Browse Source

Add initial support of multi-rack for upgrades

* netgroups mapping was changed (additional argument
  for the mapping was added - name of node group)
* copying of node group during cluster cloning was added

Depends-On: I2638279371e91f15090c782fc5fdbb434a2e85f8
Partial-bug: #1612297

Change-Id: Ib1689d7b6d673c0d78434dd047a7ebc520c232e7
Co-Authored-By: Ryan Moe <rmoe@mirantis.com>
Co-Authored-By: Andrew Woodward <awoodward@mirantis.com>
Co-Authored-By: Ilya Kharin <akscram@gmail.com>
Anastasiya 2 years ago
parent
commit
e2b9dbf1ca

+ 2
- 5
cluster_upgrade/handlers.py View File

@@ -140,11 +140,8 @@ class CopyVIPsHandler(base.BaseHandler):
140 140
         self.checked_data(cluster=cluster, relation=relation)
141 141
 
142 142
         # get original cluster object and create adapter with it
143
-        orig_cluster_adapter = \
144
-            adapters.NailgunClusterAdapter(
145
-                adapters.NailgunClusterAdapter.get_by_uid(
146
-                    relation.orig_cluster_id)
147
-            )
143
+        orig_cluster_adapter = adapters.NailgunClusterAdapter.get_by_uid(
144
+            relation.orig_cluster_id)
148 145
 
149 146
         seed_cluster_adapter = adapters.NailgunClusterAdapter(cluster)
150 147
 

+ 15
- 2
cluster_upgrade/objects/adapters.py View File

@@ -35,6 +35,10 @@ class NailgunClusterAdapter(object):
35 35
     def name(self):
36 36
         return self.cluster.name
37 37
 
38
+    @property
39
+    def node_groups(self):
40
+        return self.cluster.node_groups
41
+
38 42
     @property
39 43
     def net_provider(self):
40 44
         return self.cluster.net_provider
@@ -135,8 +139,9 @@ class NailgunNetworkManager(object):
135 139
     def update(self, network_configuration):
136 140
         self.net_manager.update(self.cluster, network_configuration)
137 141
 
138
-    def get_assigned_vips(self):
139
-        return self.net_manager.get_assigned_vips(self.cluster)
142
+    def get_assigned_vips(self, network_names=None):
143
+        return self.net_manager.get_assigned_vips(
144
+            self.cluster, network_names=network_names)
140 145
 
141 146
     def assign_vips_for_net_groups(self):
142 147
         return self.net_manager.assign_vips_for_net_groups(self.cluster)
@@ -230,3 +235,11 @@ class NailgunNetworkGroupAdapter(object):
230 235
     @property
231 236
     def name(self):
232 237
         return self.network_group.name
238
+
239
+    @property
240
+    def nodegroup(self):
241
+        return self.network_group.nodegroup
242
+
243
+    @classmethod
244
+    def get_by_uid(cls, ng_id):
245
+        return objects.NetworkGroup.get_by_uid(ng_id)

+ 1
- 2
cluster_upgrade/tests/test_handlers.py View File

@@ -13,7 +13,6 @@
13 13
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16
-import unittest
17 16
 
18 17
 import mock
19 18
 
@@ -227,7 +226,7 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
227 226
 
228 227
 
229 228
 class TestCopyVipsHandler(tests_base.BaseCloneClusterTest):
230
-    @unittest.skip("Skip test regarding vips")
229
+
231 230
     def test_copy_vips(self):
232 231
         node_db = self.env.create_node(cluster_id=self.src_cluster.id,
233 232
                                        roles=["controller"])

+ 8
- 10
cluster_upgrade/tests/test_transformations.py View File

@@ -10,7 +10,6 @@
10 10
 # License for the specific language governing permissions and limitations
11 11
 # under the License.
12 12
 from distutils import version
13
-import unittest
14 13
 
15 14
 import mock
16 15
 from nailgun.test import base as nailgun_test_base
@@ -249,33 +248,32 @@ class TestClusterTransformers(nailgun_test_base.BaseUnitTest):
249 248
 class TestVipTransformers(nailgun_test_base.BaseUnitTest):
250 249
     def setUp(self):
251 250
         ip = '0.0.0.0'
252
-
253 251
         self.data = {
254
-            'management': {
252
+            1: {
255 253
                 'haproxy': ip,
256 254
                 'vrouter': ip,
257 255
                 'test': ip,
258 256
             },
259
-            'public': {
257
+            2: {
260 258
                 'haproxy': ip,
261 259
                 'vrouter': ip,
262 260
                 'test': ip,
263 261
             }
264 262
         }
263
+        self.mapping = {1: 'management', 2: 'public'}
265 264
 
266
-    @unittest.skip("Skip test regarding vips")
267 265
     def test_vip_transform(self):
268 266
         ip = '0.0.0.0'
269 267
 
270
-        data = vip.transform_vips(self.data)
268
+        data = vip.transform_vips((self.data, self.mapping))
271 269
         self.assertEqual(
272
-            data, {
273
-                'management': {
270
+            data, ({
271
+                1: {
274 272
                     'management': ip,
275 273
                     'vrouter': ip,
276 274
                 },
277
-                'public': {
275
+                2: {
278 276
                     'public': ip,
279 277
                     'vrouter_pub': ip,
280
-                }}
278
+                }}, {1: 'management', 2: 'public'})
281 279
         )

+ 0
- 2
cluster_upgrade/tests/test_upgrade.py View File

@@ -15,7 +15,6 @@
15 15
 #    under the License.
16 16
 
17 17
 import copy
18
-import unittest
19 18
 
20 19
 import six
21 20
 
@@ -146,7 +145,6 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
146 145
         self.assertEqual(public_net['ip_ranges'],
147 146
                          self.public_net_data['ip_ranges'])
148 147
 
149
-    @unittest.skip("Skip test regarding vips")
150 148
     def test_copy_vips(self):
151 149
         # save network information before node reassignment to seed cluster
152 150
         # as after that no VIP will be allocated/serialized due to

+ 5
- 5
cluster_upgrade/transformations/vip.py View File

@@ -42,17 +42,17 @@ def transform_vips(data):
42 42
         },
43 43
     }
44 44
     renamed_vips = collections.defaultdict(dict)
45
-    for ng_name, vips_obj in data.items():
46
-
47
-        ng_vip_rules = rename_vip_rules[ng_name]
45
+    vips, id_name_mapping = data
46
+    for ng_id, vips_obj in vips.items():
47
+        ng_vip_rules = rename_vip_rules[id_name_mapping[ng_id]]
48 48
         for vip_name, vip_addr in vips_obj.items():
49 49
             if vip_name not in ng_vip_rules:
50 50
                 continue
51 51
 
52 52
             new_vip_name = ng_vip_rules[vip_name]
53
-            renamed_vips[ng_name][new_vip_name] = vip_addr
53
+            renamed_vips[ng_id][new_vip_name] = vip_addr
54 54
 
55
-    return renamed_vips
55
+    return renamed_vips, id_name_mapping
56 56
 
57 57
 
58 58
 class Manager(transformations.Manager):

+ 56
- 12
cluster_upgrade/upgrade.py View File

@@ -15,6 +15,8 @@
15 15
 #    under the License.
16 16
 
17 17
 import copy
18
+
19
+import collections
18 20
 import six
19 21
 
20 22
 from nailgun import consts
@@ -47,13 +49,22 @@ def merge_attributes(a, b):
47 49
     return attrs
48 50
 
49 51
 
52
+def get_net_key(net):
53
+    group_name = None
54
+    if net["group_id"]:
55
+        group_name = objects.NodeGroup.get_by_uid(net["group_id"]).name
56
+    return (net["name"], group_name)
57
+
58
+
50 59
 def merge_nets(a, b):
51 60
     new_settings = copy.deepcopy(b)
52
-    source_networks = dict((n["name"], n) for n in a["networks"])
61
+    source_networks = dict((get_net_key(net), net) for net in a["networks"])
62
+
53 63
     for net in new_settings["networks"]:
54
-        if net["name"] not in source_networks:
64
+        net_key = get_net_key(net)
65
+        if net_key not in source_networks:
55 66
             continue
56
-        source_net = source_networks[net["name"]]
67
+        source_net = source_networks[net_key]
57 68
         for key, value in six.iteritems(net):
58 69
             if (key not in ("cluster_id", "id", "meta", "group_id") and
59 70
                     key in source_net):
@@ -84,6 +95,7 @@ class UpgradeHelper(object):
84 95
 
85 96
         new_cluster = cls.create_cluster_clone(orig_cluster, data)
86 97
         cls.copy_attributes(orig_cluster, new_cluster)
98
+        cls.copy_node_groups(orig_cluster, new_cluster)
87 99
         cls.copy_network_config(orig_cluster, new_cluster)
88 100
         relations.UpgradeRelationObject.create_relation(orig_cluster.id,
89 101
                                                         new_cluster.id)
@@ -124,6 +136,18 @@ class UpgradeHelper(object):
124 136
         attrs = new_cluster.attributes
125 137
         attrs['editable']['provision']['method']['value'] = 'image'
126 138
 
139
+    @classmethod
140
+    def copy_node_groups(cls, orig_cluster, new_cluster):
141
+        for ng in orig_cluster.node_groups:
142
+            if getattr(ng, 'is_default', False) or ng.name == 'default':
143
+                continue
144
+
145
+            data = {
146
+                'name': ng.name,
147
+                'cluster_id': new_cluster.id
148
+            }
149
+            objects.NodeGroup.create(data)
150
+
127 151
     @classmethod
128 152
     def copy_network_config(cls, orig_cluster, new_cluster):
129 153
         nets_serializer = cls.network_serializers[orig_cluster.net_provider]
@@ -140,19 +164,37 @@ class UpgradeHelper(object):
140 164
         orig_net_manager = orig_cluster.get_network_manager()
141 165
         new_net_manager = new_cluster.get_network_manager()
142 166
 
143
-        vips = {}
144
-        assigned_vips = orig_net_manager.get_assigned_vips()
145
-        for ng_name in (consts.NETWORKS.public, consts.NETWORKS.management):
146
-            vips[ng_name] = assigned_vips[ng_name]
167
+        vips = orig_net_manager.get_assigned_vips(
168
+            network_names=(consts.NETWORKS.public, consts.NETWORKS.management))
147 169
 
148
-        vips = cls.vip_transformations.apply(
170
+        netgroups_id_mapping = cls.get_netgroups_id_mapping(orig_cluster,
171
+                                                            new_cluster)
172
+        new_vips = cls.reassociate_vips(vips, netgroups_id_mapping)
173
+        id_name_vips_mapping = cls.get_id_name_vips_mapping(new_vips)
174
+        new_vips, id_name_vips_mapping = cls.vip_transformations.apply(
149 175
             orig_cluster.release.environment_version,
150 176
             new_cluster.release.environment_version,
151
-            vips
177
+            (new_vips, id_name_vips_mapping),
152 178
         )
153
-        new_net_manager.assign_given_vips_for_net_groups(vips)
179
+        new_net_manager.assign_given_vips_for_net_groups(new_vips)
154 180
         new_net_manager.assign_vips_for_net_groups()
155 181
 
182
+    @classmethod
183
+    def reassociate_vips(cls, vips, netgroups_id_mapping):
184
+        new_vips = collections.defaultdict(dict)
185
+        for orig_net_id, net_vips in vips.items():
186
+            new_net_id = netgroups_id_mapping[orig_net_id]
187
+            new_vips[new_net_id] = net_vips
188
+        return new_vips
189
+
190
+    @classmethod
191
+    def get_id_name_vips_mapping(self, vips):
192
+        mapping = {}
193
+        for vip_id in vips:
194
+            mapping[vip_id] = \
195
+                adapters.NailgunNetworkGroupAdapter.get_by_uid(vip_id).name
196
+        return mapping
197
+
156 198
     @classmethod
157 199
     def get_node_roles(cls, reprovision, current_roles, given_roles):
158 200
         """Return roles depending on the reprovisioning status.
@@ -210,8 +252,10 @@ class UpgradeHelper(object):
210 252
         orig_ng = orig_cluster.get_network_groups()
211 253
         seed_ng = seed_cluster.get_network_groups()
212 254
 
213
-        seed_ng_dict = dict((ng.name, ng.id) for ng in seed_ng)
214
-        mapping = dict((ng.id, seed_ng_dict[ng.name]) for ng in orig_ng)
255
+        seed_ng_dict = dict(((ng.name, ng.nodegroup.name), ng.id)
256
+                            for ng in seed_ng)
257
+        mapping = dict((ng.id, seed_ng_dict[(ng.name, ng.nodegroup.name)])
258
+                       for ng in orig_ng)
215 259
         mapping[orig_cluster.get_admin_network_group().id] = \
216 260
             seed_cluster.get_admin_network_group().id
217 261
         return mapping

Loading…
Cancel
Save