summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Zubkov <nzubkov@mirantis.com>2016-09-12 19:03:43 +0300
committerNikita Zubkov <nzubkov@mirantis.com>2016-09-21 17:00:02 +0300
commit4150121e8a97ff76fc116596e8cd19e69c3ea279 (patch)
tree1fbfd4065149d67ea7cd89ea8f2f71c2aacb92c6
parent821f8373abdce04974e02ef8b20d1d8fffa2094a (diff)
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
Notes
Notes (review): Code-Review+2: Ilya Kharin <akscram@gmail.com> Workflow+1: Ilya Kharin <akscram@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 21 Sep 2016 15:05:05 +0000 Reviewed-on: https://review.openstack.org/368944 Project: openstack/fuel-nailgun-extension-cluster-upgrade Branch: refs/heads/master
-rw-r--r--cluster_upgrade/handlers.py8
-rw-r--r--cluster_upgrade/objects/adapters.py3
-rw-r--r--cluster_upgrade/upgrade.py22
3 files changed, 33 insertions, 0 deletions
diff --git a/cluster_upgrade/handlers.py b/cluster_upgrade/handlers.py
index 21faab6..22dd948 100644
--- a/cluster_upgrade/handlers.py
+++ b/cluster_upgrade/handlers.py
@@ -18,6 +18,7 @@ import copy
18import six 18import six
19 19
20from nailgun.api.v1.handlers import base 20from nailgun.api.v1.handlers import base
21from nailgun import errors
21from nailgun import objects 22from nailgun import objects
22from nailgun.task import manager 23from nailgun.task import manager
23 24
@@ -53,6 +54,13 @@ class ClusterUpgradeCloneHandler(base.BaseHandler):
53 request_data = self.checked_data(cluster=orig_cluster) 54 request_data = self.checked_data(cluster=orig_cluster)
54 new_cluster = upgrade.UpgradeHelper.clone_cluster(orig_cluster, 55 new_cluster = upgrade.UpgradeHelper.clone_cluster(orig_cluster,
55 request_data) 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 return new_cluster.to_dict() 64 return new_cluster.to_dict()
57 65
58 66
diff --git a/cluster_upgrade/objects/adapters.py b/cluster_upgrade/objects/adapters.py
index be5a00d..0edf3ee 100644
--- a/cluster_upgrade/objects/adapters.py
+++ b/cluster_upgrade/objects/adapters.py
@@ -98,6 +98,9 @@ class NailgunClusterAdapter(object):
98 def get_admin_network_group(self): 98 def get_admin_network_group(self):
99 return objects.NetworkGroup.get_admin_network_group() 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
102class NailgunReleaseAdapter(object): 105class NailgunReleaseAdapter(object):
103 def __init__(self, release): 106 def __init__(self, release):
diff --git a/cluster_upgrade/upgrade.py b/cluster_upgrade/upgrade.py
index 0b5bede..812a0a1 100644
--- a/cluster_upgrade/upgrade.py
+++ b/cluster_upgrade/upgrade.py
@@ -319,3 +319,25 @@ class UpgradeHelper(object):
319 seed_ng_dict = dict((ng.name, ng.id) for ng in seed_ng) 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) 320 mapping = dict((ng.id, seed_ng_dict[ng.name]) for ng in orig_ng)
321 return mapping 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}