summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnastasiya <atolochkova@mirantis.com>2016-09-01 12:16:06 +0300
committerAnastasia Balobashina <atolochkova@mirantis.com>2016-09-19 10:33:44 +0000
commit821f8373abdce04974e02ef8b20d1d8fffa2094a (patch)
treef0762779875d25588d86abd3f4f784834ac193aa
parente2b9dbf1ca61b92c457722108eaf6dba95ac4f4b (diff)
Sync network groups during cloning environment
for creating of network groups in the seed cluster such as in the original cluster Change-Id: I17f95756fa26ef0f7df0e969f9f1ba4331047c8d Closes-Bug: #1616817
Notes
Notes (review): Code-Review+1: Nikita Zubkov <nzubkov@mirantis.com> Code-Review+1: Fedor Zhadaev <fzhadaev@mirantis.com> Code-Review+1: Sergey Novikov <snovikov@mirantis.com> Code-Review+1: Alexey Stepanov <astepanov@mirantis.com> Code-Review+2: Ilya Kharin <akscram@gmail.com> Workflow+1: Ilya Kharin <akscram@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 20 Sep 2016 09:58:32 +0000 Reviewed-on: https://review.openstack.org/365038 Project: openstack/fuel-nailgun-extension-cluster-upgrade Branch: refs/heads/master
-rw-r--r--cluster_upgrade/objects/adapters.py8
-rw-r--r--cluster_upgrade/tests/test_upgrade.py66
-rw-r--r--cluster_upgrade/upgrade.py60
3 files changed, 134 insertions, 0 deletions
diff --git a/cluster_upgrade/objects/adapters.py b/cluster_upgrade/objects/adapters.py
index 1adb27a..be5a00d 100644
--- a/cluster_upgrade/objects/adapters.py
+++ b/cluster_upgrade/objects/adapters.py
@@ -122,6 +122,10 @@ class NailgunReleaseAdapter(object):
122 return self.release.environment_version 122 return self.release.environment_version
123 123
124 @property 124 @property
125 def id(self):
126 return self.release.id
127
128 @property
125 def roles_metadata(self): 129 def roles_metadata(self):
126 return self.release.roles_metadata 130 return self.release.roles_metadata
127 131
@@ -136,6 +140,10 @@ class NailgunNetworkManager(object):
136 self.cluster = cluster 140 self.cluster = cluster
137 self.net_manager = net_manager 141 self.net_manager = net_manager
138 142
143 def create(self, network_configuration, group_id=None):
144 self.net_manager.create_network_group(self.cluster,
145 network_configuration, group_id)
146
139 def update(self, network_configuration): 147 def update(self, network_configuration):
140 self.net_manager.update(self.cluster, network_configuration) 148 self.net_manager.update(self.cluster, network_configuration)
141 149
diff --git a/cluster_upgrade/tests/test_upgrade.py b/cluster_upgrade/tests/test_upgrade.py
index 3d03ec4..2b847f5 100644
--- a/cluster_upgrade/tests/test_upgrade.py
+++ b/cluster_upgrade/tests/test_upgrade.py
@@ -229,6 +229,72 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
229 self.assertEqual('image', 229 self.assertEqual('image',
230 attrs['editable']['provision']['method']['value']) 230 attrs['editable']['provision']['method']['value'])
231 231
232 def check_different_attributes(self, orig_cluster, new_cluster):
233 release = new_cluster.release.id
234 nodegroups_id_maping = self.helper.get_nodegroups_id_mapping(
235 orig_cluster, new_cluster
236 )
237 orig_ngs = self.serialize_nets(orig_cluster.cluster)['networks']
238 seed_ngs = self.serialize_nets(new_cluster.cluster)['networks']
239 for seed_ng in seed_ngs:
240 for orig_ng in orig_ngs:
241 if orig_ng['name'] == seed_ng['name'] \
242 and orig_ng['name'] != "fuelweb_admin":
243
244 self.assertEqual(seed_ng['group_id'],
245 nodegroups_id_maping[orig_ng['group_id']])
246
247 if seed_ng.get('release'):
248 self.assertEqual(seed_ng['release'], release)
249
250 def skip_different_attributes(self, orig_cluster, new_cluster):
251 orig_ngs = self.serialize_nets(orig_cluster.cluster)['networks']
252 seed_ngs = self.serialize_nets(new_cluster.cluster)['networks']
253 keys = ['release', 'id', 'group_id']
254 orig_ngs_names = {ng['name']: ng for ng in orig_ngs}
255 for seed_ng in seed_ngs:
256 if seed_ng['name'] == 'fuelweb_admin':
257 continue
258 orig_ng = orig_ngs_names.get(seed_ng['name'])
259 if not orig_ng:
260 continue
261 for key in keys:
262 orig_ng.pop(key, None)
263 seed_ng.pop(key, None)
264 return orig_ngs, seed_ngs
265
266 def test_sync_network_groups(self):
267 new_cluster = self.helper.create_cluster_clone(self.src_cluster,
268 self.data)
269 self.helper.sync_network_groups(self.src_cluster, new_cluster)
270 self.check_different_attributes(self.src_cluster, new_cluster)
271 orig_ngs, seed_ngs = self.skip_different_attributes(self.src_cluster,
272 new_cluster)
273 self.assertEqual(orig_ngs, seed_ngs)
274
275 def test_remove_network_groups(self):
276 new_cluster = self.helper.create_cluster_clone(self.src_cluster,
277 self.data)
278 self.helper.remove_network_groups(new_cluster)
279 seed_ngs = self.serialize_nets(new_cluster.cluster)['networks']
280 self.assertEqual(len(seed_ngs), 1)
281 self.assertEqual(seed_ngs[0]['name'], 'fuelweb_admin')
282
283 def test_copy_network_groups(self):
284 new_cluster = self.helper.create_cluster_clone(self.src_cluster,
285 self.data)
286 nodegroups_id_maping = self.helper.get_nodegroups_id_mapping(
287 self.src_cluster, new_cluster
288 )
289 release = new_cluster.release.id
290 self.helper.remove_network_groups(new_cluster)
291 self.helper.copy_network_groups(self.src_cluster, nodegroups_id_maping,
292 release)
293 self.check_different_attributes(self.src_cluster, new_cluster)
294 orig_ngs, seed_ngs = self.skip_different_attributes(self.src_cluster,
295 new_cluster)
296 self.assertEqual(orig_ngs, seed_ngs)
297
232 def test_change_env_settings_no_editable_provision(self): 298 def test_change_env_settings_no_editable_provision(self):
233 new_cluster = self.helper.create_cluster_clone(self.src_cluster, 299 new_cluster = self.helper.create_cluster_clone(self.src_cluster,
234 self.data) 300 self.data)
diff --git a/cluster_upgrade/upgrade.py b/cluster_upgrade/upgrade.py
index 2ade745..0b5bede 100644
--- a/cluster_upgrade/upgrade.py
+++ b/cluster_upgrade/upgrade.py
@@ -20,6 +20,7 @@ import collections
20import six 20import six
21 21
22from nailgun import consts 22from nailgun import consts
23from nailgun.db import db
23from nailgun.extensions.network_manager.objects.serializers import \ 24from nailgun.extensions.network_manager.objects.serializers import \
24 network_configuration 25 network_configuration
25from nailgun import objects 26from nailgun import objects
@@ -100,6 +101,7 @@ class UpgradeHelper(object):
100 relations.UpgradeRelationObject.create_relation(orig_cluster.id, 101 relations.UpgradeRelationObject.create_relation(orig_cluster.id,
101 new_cluster.id) 102 new_cluster.id)
102 cls.change_env_settings(orig_cluster, new_cluster) 103 cls.change_env_settings(orig_cluster, new_cluster)
104 cls.sync_network_groups(orig_cluster, new_cluster)
103 return new_cluster 105 return new_cluster
104 106
105 @classmethod 107 @classmethod
@@ -137,6 +139,55 @@ class UpgradeHelper(object):
137 attrs['editable']['provision']['method']['value'] = 'image' 139 attrs['editable']['provision']['method']['value'] = 'image'
138 140
139 @classmethod 141 @classmethod
142 def sync_network_groups(cls, orig_cluster, new_cluster):
143 cls.remove_network_groups(new_cluster)
144 nodegroups_id_maping = cls.get_nodegroups_id_mapping(orig_cluster,
145 new_cluster)
146 release = new_cluster.release.id
147 cls.copy_network_groups(orig_cluster, nodegroups_id_maping, release)
148
149 @classmethod
150 def remove_network_groups(cls, cluster):
151 seed_ng = cluster.get_network_groups()
152 for ng in seed_ng:
153 if ng.name == 'fuelweb_admin':
154 continue
155 objects.NetworkGroup.delete(ng.network_group)
156
157 @classmethod
158 def copy_network_groups(cls, orig_cluster, nodegroups_id_maping, release):
159 nets_serializer = cls.network_serializers[orig_cluster.net_provider]
160 orig_net = nets_serializer.serialize_for_cluster(orig_cluster.cluster)
161 for ng in orig_net['networks']:
162 if ng['name'] == 'fuelweb_admin':
163 continue
164 meta = ng['meta']
165 metadata = {
166 'notation': 'cidr',
167 'render_type': None,
168 'map_priority': 2,
169 'configurable': True,
170 'use_gateway': False,
171 'name': ng['name'],
172 'vlan_start': ng['vlan_start']
173 }
174 metadata.update(meta)
175 if metadata['notation'] == 'ip_ranges':
176 metadata['ip_range'] = ng['ip_ranges'][0]
177 metadata['cidr'] = ng['cidr']
178 data = {
179 'name': ng['name'],
180 'release': release,
181 'vlan_start': ng['vlan_start'],
182 'cidr': ng['cidr'],
183 'gateway': ng['gateway'],
184 'group_id': nodegroups_id_maping[ng['group_id']],
185 'meta': metadata
186 }
187 objects.NetworkGroup.create(data)
188 db().commit()
189
190 @classmethod
140 def copy_node_groups(cls, orig_cluster, new_cluster): 191 def copy_node_groups(cls, orig_cluster, new_cluster):
141 for ng in orig_cluster.node_groups: 192 for ng in orig_cluster.node_groups:
142 if getattr(ng, 'is_default', False) or ng.name == 'default': 193 if getattr(ng, 'is_default', False) or ng.name == 'default':
@@ -259,3 +310,12 @@ class UpgradeHelper(object):
259 mapping[orig_cluster.get_admin_network_group().id] = \ 310 mapping[orig_cluster.get_admin_network_group().id] = \
260 seed_cluster.get_admin_network_group().id 311 seed_cluster.get_admin_network_group().id
261 return mapping 312 return mapping
313
314 @classmethod
315 def get_nodegroups_id_mapping(cls, orig_cluster, seed_cluster):
316 orig_ng = orig_cluster.node_groups
317 seed_ng = seed_cluster.node_groups
318
319 seed_ng_dict = dict((ng.name, ng.id) for ng in seed_ng)
320 mapping = dict((ng.id, seed_ng_dict[ng.name]) for ng in orig_ng)
321 return mapping