Browse Source

Validate network roles for new cluster

Checks that network roles mapping from original release is a subset of
network roles mapping of new cluster's release.

Change-Id: I521e70bf3df289abf3e71c5c1558faf7126db964
Partial-Bug: #1619162
Nikita Zubkov 2 years ago
parent
commit
4150121e8a
3 changed files with 33 additions and 0 deletions
  1. 8
    0
      cluster_upgrade/handlers.py
  2. 3
    0
      cluster_upgrade/objects/adapters.py
  3. 22
    0
      cluster_upgrade/upgrade.py

+ 8
- 0
cluster_upgrade/handlers.py View File

@@ -18,6 +18,7 @@ import copy
18 18
 import six
19 19
 
20 20
 from nailgun.api.v1.handlers import base
21
+from nailgun import errors
21 22
 from nailgun import objects
22 23
 from nailgun.task import manager
23 24
 
@@ -53,6 +54,13 @@ class ClusterUpgradeCloneHandler(base.BaseHandler):
53 54
         request_data = self.checked_data(cluster=orig_cluster)
54 55
         new_cluster = upgrade.UpgradeHelper.clone_cluster(orig_cluster,
55 56
                                                           request_data)
57
+        valid = upgrade.UpgradeHelper.validate_network_roles(
58
+            orig_cluster, new_cluster,
59
+        )
60
+        if not valid:
61
+            raise errors.InvalidData("Network changes during upgrade"
62
+                                     " is not supported.")
63
+
56 64
         return new_cluster.to_dict()
57 65
 
58 66
 

+ 3
- 0
cluster_upgrade/objects/adapters.py View File

@@ -98,6 +98,9 @@ class NailgunClusterAdapter(object):
98 98
     def get_admin_network_group(self):
99 99
         return objects.NetworkGroup.get_admin_network_group()
100 100
 
101
+    def get_network_roles(self):
102
+        return objects.Cluster.get_network_roles(self.cluster)
103
+
101 104
 
102 105
 class NailgunReleaseAdapter(object):
103 106
     def __init__(self, release):

+ 22
- 0
cluster_upgrade/upgrade.py View File

@@ -319,3 +319,25 @@ class UpgradeHelper(object):
319 319
         seed_ng_dict = dict((ng.name, ng.id) for ng in seed_ng)
320 320
         mapping = dict((ng.id, seed_ng_dict[ng.name]) for ng in orig_ng)
321 321
         return mapping
322
+
323
+    @classmethod
324
+    def validate_network_roles(cls, orig_cluster, seed_cluster):
325
+        if not orig_cluster.network_template:
326
+            return cls._compare_releases_roles(orig_cluster, seed_cluster)
327
+        else:
328
+            # TODO network template case
329
+            return True
330
+
331
+    @classmethod
332
+    def _compare_releases_roles(cls, orig_cluster, seed_cluster):
333
+        orig_roles = orig_cluster.get_network_roles()
334
+        new_roles = seed_cluster.get_network_roles()
335
+
336
+        orig_mapping = cls._get_release_mapping(orig_roles)
337
+        new_mapping = cls._get_release_mapping(new_roles)
338
+
339
+        return orig_mapping.issubset(new_mapping)
340
+
341
+    @staticmethod
342
+    def _get_release_mapping(roles):
343
+        return {(role['id'], role['default_mapping']) for role in roles}

Loading…
Cancel
Save