summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-08-24 16:11:27 +0000
committerGerrit Code Review <review@openstack.org>2016-08-24 16:11:27 +0000
commit1b63629862beae83fe421a395412fe0f31cfe0fd (patch)
tree144425ea114060cae94ff18cc24b1ef6692a0d7f
parent96ca0fdf0db24a84c510029e035cc60460d61a5c (diff)
parent95ff3a3598397bb6e3c68793051298aaa006d163 (diff)
Merge "Add cluster transformations"
-rw-r--r--cluster_upgrade/tests/test_transformations.py42
-rw-r--r--cluster_upgrade/tests/test_upgrade.py5
-rw-r--r--cluster_upgrade/transformations/cluster.py52
-rw-r--r--cluster_upgrade/upgrade.py47
-rw-r--r--setup.cfg4
5 files changed, 118 insertions, 32 deletions
diff --git a/cluster_upgrade/tests/test_transformations.py b/cluster_upgrade/tests/test_transformations.py
index 46e0c77..880ee2d 100644
--- a/cluster_upgrade/tests/test_transformations.py
+++ b/cluster_upgrade/tests/test_transformations.py
@@ -17,6 +17,7 @@ from nailgun.test import base as nailgun_test_base
17import six 17import six
18 18
19from .. import transformations 19from .. import transformations
20from ..transformations import cluster
20 21
21 22
22class TestTransformations(nailgun_test_base.BaseUnitTest): 23class TestTransformations(nailgun_test_base.BaseUnitTest):
@@ -177,3 +178,44 @@ class TestLazy(nailgun_test_base.BaseUnitTest):
177 lazy_obj = transformations.Lazy(mgr_cls_mock) 178 lazy_obj = transformations.Lazy(mgr_cls_mock)
178 lazy_obj.apply() 179 lazy_obj.apply()
179 self.assertEqual(lazy_obj.apply, mgr_cls_mock.return_value.apply) 180 self.assertEqual(lazy_obj.apply, mgr_cls_mock.return_value.apply)
181
182
183class TestClusterTransformers(nailgun_test_base.BaseUnitTest):
184 def setUp(self):
185 self.data = {
186 'editable': {
187 'external_dns': {
188 'dns_list': {'type': 'text', 'value': 'a,b,\nc, d'}},
189 'external_ntp': {
190 'ntp_list': {'type': 'text', 'value': 'a,b,\nc, d'}},
191 },
192 'generated': {
193 'provision': {},
194 },
195 }
196
197 def test_dns_list(self):
198 res = cluster.transform_dns_list(self.data)
199 self.assertEqual(
200 res['editable']['external_dns']['dns_list'],
201 {'type': 'text_list', 'value': ['a', 'b', 'c', 'd']},
202 )
203
204 def test_ntp_list(self):
205 res = cluster.transform_ntp_list(self.data)
206 self.assertEqual(
207 res['editable']['external_ntp']['ntp_list'],
208 {'type': 'text_list', 'value': ['a', 'b', 'c', 'd']},
209 )
210
211 def test_provision(self):
212 res = cluster.drop_generated_provision(self.data)
213 self.assertNotIn('provision', res['generated'])
214
215 def test_manager(self):
216 man = cluster.Manager() # verify default config and entry points
217 self.assertEqual(man.transformers, [(version.StrictVersion('9.0'), [
218 cluster.transform_dns_list,
219 cluster.transform_ntp_list,
220 cluster.drop_generated_provision,
221 ])])
diff --git a/cluster_upgrade/tests/test_upgrade.py b/cluster_upgrade/tests/test_upgrade.py
index 8b6c7b2..2f9ff98 100644
--- a/cluster_upgrade/tests/test_upgrade.py
+++ b/cluster_upgrade/tests/test_upgrade.py
@@ -50,7 +50,7 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
50 {"metadata": "src_fake", 50 {"metadata": "src_fake",
51 "key": 51 "key":
52 {"type": "text", 52 {"type": "text",
53 "value": "fake1, fake2,fake3 , fake4"}, 53 "value": "fake"},
54 "src_key": "src_data" 54 "src_key": "src_data"
55 }, 55 },
56 "repo_setup": "src_data" 56 "repo_setup": "src_data"
@@ -69,9 +69,6 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
69 result = upgrade.merge_attributes( 69 result = upgrade.merge_attributes(
70 src_editable_attrs, new_editable_attrs 70 src_editable_attrs, new_editable_attrs
71 ) 71 )
72 new_editable_attrs["test"]["key"]["value"] = [
73 "fake1", "fake2", "fake3", "fake4"
74 ]
75 self.assertEqual(result, new_editable_attrs) 72 self.assertEqual(result, new_editable_attrs)
76 73
77 def test_create_cluster_clone(self): 74 def test_create_cluster_clone(self):
diff --git a/cluster_upgrade/transformations/cluster.py b/cluster_upgrade/transformations/cluster.py
new file mode 100644
index 0000000..61368e0
--- /dev/null
+++ b/cluster_upgrade/transformations/cluster.py
@@ -0,0 +1,52 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from cluster_upgrade import transformations
14
15# NOTE: In the mitaka-9.0 release types of values dns_list and
16# ntp_list were changed from 'text'
17# (a string of comma-separated IP-addresses)
18# to 'text_list' (a list of strings of IP-addresses).
19
20
21def transform_to_text_list(data):
22 if data['type'] == 'text':
23 data['type'] = 'text_list'
24 data['value'] = [
25 part.strip() for part in data['value'].split(',')
26 ]
27
28 return data
29
30
31def transform_dns_list(data):
32 dns_list = data['editable']['external_dns']['dns_list']
33 transform_to_text_list(dns_list)
34 return data
35
36
37def transform_ntp_list(data):
38 ntp_list = data['editable']['external_ntp']['ntp_list']
39 transform_to_text_list(ntp_list)
40 return data
41
42
43def drop_generated_provision(data):
44 data['generated'].pop('provision', None)
45 return data
46
47
48class Manager(transformations.Manager):
49 default_config = {
50 '9.0': ['dns_list', 'ntp_list', 'drop_provision'],
51 }
52 name = 'cluster'
diff --git a/cluster_upgrade/upgrade.py b/cluster_upgrade/upgrade.py
index e0a3aa7..e1b9ec8 100644
--- a/cluster_upgrade/upgrade.py
+++ b/cluster_upgrade/upgrade.py
@@ -25,7 +25,9 @@ from nailgun.extensions.network_manager.objects.serializers import \
25from nailgun import objects 25from nailgun import objects
26from nailgun import utils 26from nailgun import utils
27 27
28from . import transformations # That's weird, but that's how hacking likes
28from .objects import adapters 29from .objects import adapters
30from .transformations import cluster as cluster_trs
29 31
30 32
31def merge_attributes(a, b): 33def merge_attributes(a, b):
@@ -42,25 +44,9 @@ def merge_attributes(a, b):
42 for key, values in six.iteritems(pairs): 44 for key, values in six.iteritems(pairs):
43 if key != "metadata" and key in a_values: 45 if key != "metadata" and key in a_values:
44 values["value"] = a_values[key]["value"] 46 values["value"] = a_values[key]["value"]
45 # NOTE: In the mitaka-9.0 release types of values dns_list and
46 # ntp_list were changed from 'text'
47 # (a string of comma-separated IP-addresses)
48 # to 'text_list' (a list of strings of IP-addresses).
49 if a_values[key]['type'] == 'text' and \
50 values['type'] == 'text_list':
51 values["value"] = [
52 value.strip() for value in values['value'].split(',')
53 ]
54 return attrs 47 return attrs
55 48
56 49
57def merge_generated_attrs(new_attrs, orig_attrs):
58 # skip attributes that should be generated for new cluster
59 attrs = copy.deepcopy(orig_attrs)
60 attrs.pop('provision', None)
61 return utils.dict_merge(new_attrs, attrs)
62
63
64def merge_nets(a, b): 50def merge_nets(a, b):
65 new_settings = copy.deepcopy(b) 51 new_settings = copy.deepcopy(b)
66 source_networks = dict((n["name"], n) for n in a["networks"]) 52 source_networks = dict((n["name"], n) for n in a["networks"])
@@ -88,6 +74,7 @@ class UpgradeHelper(object):
88 consts.CLUSTER_NET_PROVIDERS.nova_network: 74 consts.CLUSTER_NET_PROVIDERS.nova_network:
89 network_configuration.NovaNetworkConfigurationSerializer, 75 network_configuration.NovaNetworkConfigurationSerializer,
90 } 76 }
77 cluster_transformations = transformations.Lazy(cluster_trs.Manager)
91 78
92 @classmethod 79 @classmethod
93 def clone_cluster(cls, orig_cluster, data): 80 def clone_cluster(cls, orig_cluster, data):
@@ -111,20 +98,24 @@ class UpgradeHelper(object):
111 98
112 @classmethod 99 @classmethod
113 def copy_attributes(cls, orig_cluster, new_cluster): 100 def copy_attributes(cls, orig_cluster, new_cluster):
114 # TODO(akscram): Attributes should be copied including 101 attrs = cls.cluster_transformations.apply(
115 # borderline cases when some parameters are 102 orig_cluster.release.environment_version,
116 # renamed or moved into plugins. Also, we should 103 new_cluster.release.environment_version,
117 # to keep special steps in copying of parameters 104 {
118 # that know how to translate parameters from one 105 'editable': orig_cluster.editable_attrs,
119 # version to another. A set of this kind of steps 106 'generated': orig_cluster.generated_attrs,
120 # should define an upgrade path of a particular 107 },
121 # cluster. 108 )
122 new_cluster.generated_attrs = merge_generated_attrs( 109
110 new_cluster.generated_attrs = utils.dict_merge(
123 new_cluster.generated_attrs, 111 new_cluster.generated_attrs,
124 orig_cluster.generated_attrs) 112 attrs['generated'],
113 )
114
125 new_cluster.editable_attrs = merge_attributes( 115 new_cluster.editable_attrs = merge_attributes(
126 orig_cluster.editable_attrs, 116 attrs['editable'],
127 new_cluster.editable_attrs) 117 new_cluster.editable_attrs,
118 )
128 119
129 @classmethod 120 @classmethod
130 def change_env_settings(cls, orig_cluster, new_cluster): 121 def change_env_settings(cls, orig_cluster, new_cluster):
diff --git a/setup.cfg b/setup.cfg
index b5b9a81..aa902e4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -25,3 +25,7 @@ packages =
25[entry_points] 25[entry_points]
26nailgun.extensions = 26nailgun.extensions =
27 cluster_upgrade = cluster_upgrade.extension:ClusterUpgradeExtension 27 cluster_upgrade = cluster_upgrade.extension:ClusterUpgradeExtension
28nailgun.cluster_upgrade.transformations.cluster.9.0 =
29 dns_list = cluster_upgrade.transformations.cluster:transform_dns_list
30 ntp_list = cluster_upgrade.transformations.cluster:transform_ntp_list
31 drop_provision = cluster_upgrade.transformations.cluster:drop_generated_provision