summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-03-24 11:48:45 +0000
committerGerrit Code Review <review@openstack.org>2017-03-24 11:48:45 +0000
commit36b90eacdc4e54b938d6ff2d7b20ed904050393e (patch)
tree88009de7fb051fc272abd94943b9497da0c18b71
parent531e275d348a602fdee6797d0adbddd9ed4f1cd2 (diff)
parentfba3bc344523da0d43f94e130b4944efe0d32529 (diff)
Merge "Use tags instead of roles"
-rw-r--r--nailgun/nailgun/objects/cluster.py7
-rw-r--r--nailgun/nailgun/test/unit/test_objects.py5
2 files changed, 10 insertions, 2 deletions
diff --git a/nailgun/nailgun/objects/cluster.py b/nailgun/nailgun/objects/cluster.py
index 669b963..298b33b 100644
--- a/nailgun/nailgun/objects/cluster.py
+++ b/nailgun/nailgun/objects/cluster.py
@@ -868,7 +868,7 @@ class Cluster(NailgunObject):
868 @classmethod 868 @classmethod
869 def get_roles_by_tag(cls, tag_name, instance): 869 def get_roles_by_tag(cls, tag_name, instance):
870 roles = set() 870 roles = set()
871 for role, meta in six.iteritems(cls.get_own_roles(instance)): 871 for role, meta in six.iteritems(cls.get_roles(instance)):
872 if tag_name in meta.get('tags', {}): 872 if tag_name in meta.get('tags', {}):
873 roles.add(role) 873 roles.add(role)
874 return roles 874 return roles
@@ -1036,13 +1036,16 @@ class Cluster(NailgunObject):
1036 return nodegroups[0] 1036 return nodegroups[0]
1037 1037
1038 @classmethod 1038 @classmethod
1039 def get_node_groups(cls, instance, noderoles): 1039 def get_node_groups(cls, instance, nodetags):
1040 """Returns node groups for given node roles. 1040 """Returns node groups for given node roles.
1041 1041
1042 :param instance: a Cluster instance 1042 :param instance: a Cluster instance
1043 :param noderoles: a list of node roles 1043 :param noderoles: a list of node roles
1044 :returns: a query for list of NodeGroup instances 1044 :returns: a query for list of NodeGroup instances
1045 """ 1045 """
1046 noderoles = set()
1047 for tag in nodetags:
1048 noderoles.update(cls.get_roles_by_tag(tag, instance) or [tag])
1046 psql_noderoles = sa.cast( 1049 psql_noderoles = sa.cast(
1047 psql.array(noderoles), 1050 psql.array(noderoles),
1048 psql.ARRAY(sa.String(consts.ROLE_NAME_MAX_SIZE))) 1051 psql.ARRAY(sa.String(consts.ROLE_NAME_MAX_SIZE)))
diff --git a/nailgun/nailgun/test/unit/test_objects.py b/nailgun/nailgun/test/unit/test_objects.py
index a7cddd1..ede85db 100644
--- a/nailgun/nailgun/test/unit/test_objects.py
+++ b/nailgun/nailgun/test/unit/test_objects.py
@@ -1098,6 +1098,7 @@ class TestClusterObject(BaseTestCase):
1098 super(TestClusterObject, self).setUp() 1098 super(TestClusterObject, self).setUp()
1099 self.cluster = self.env.create( 1099 self.cluster = self.env.create(
1100 cluster_kwargs={'net_provider': 'neutron'}, 1100 cluster_kwargs={'net_provider': 'neutron'},
1101 release_kwargs={'version': 'newton-10.0', 'api': False},
1101 nodes_kwargs=[ 1102 nodes_kwargs=[
1102 {'roles': ['controller']}, 1103 {'roles': ['controller']},
1103 {'roles': ['controller']}, 1104 {'roles': ['controller']},
@@ -1240,6 +1241,10 @@ class TestClusterObject(BaseTestCase):
1240 controller.group_id, 1241 controller.group_id,
1241 objects.Cluster.get_common_node_group(self.cluster, 1242 objects.Cluster.get_common_node_group(self.cluster,
1242 ['controller']).id) 1243 ['controller']).id)
1244 self.assertEqual(
1245 controller.group_id,
1246 objects.Cluster.get_common_node_group(self.cluster,
1247 ['neutron']).id)
1243 1248
1244 def test_get_node_group_multiple_return_same_group(self): 1249 def test_get_node_group_multiple_return_same_group(self):
1245 group_id = self.env.create_node_group().json_body['id'] 1250 group_id = self.env.create_node_group().json_body['id']