]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: add cluster-aware roles filter
authorJosh Durgin <jdurgin@redhat.com>
Thu, 17 Mar 2016 00:46:30 +0000 (17:46 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:42 +0000 (14:36 -0700)
Unlike roles_of_type, this actually returns roles. We can't change the
semantics of the existing one due to backwards compatibility
requirements for old ceph-qa-suite branches, so make a new function
and implement the old one in terms of the new more general interface.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 318b0598b0098ee7ea3cecde74a7d68f8c9be050..ccf78009ea4d2218f21911df050db393695214df 100644 (file)
@@ -370,19 +370,32 @@ def split_role(role):
 
 
 def roles_of_type(roles_for_host, type_):
+    """
+    Generator of ids.
+
+    Each call returns the next possible role of the type specified.
+    :param roles_for host: list of roles possible
+    :param type_: type of role
+    """
+    for role in cluster_roles_of_type(roles_for_host, type_, None):
+        _, _, id_ = split_role(role)
+        yield id_
+
+
+def cluster_roles_of_type(roles_for_host, type_, cluster):
     """
     Generator of roles.
 
     Each call returns the next possible role of the type specified.
     :param roles_for host: list of roles possible
     :param type_: type of role
+    :param cluster: cluster name
     """
-    is_of_type = is_type(type_)
-    for name in roles_for_host:
-        if not is_of_type(name):
+    is_type_in_cluster = is_type(type_, cluster)
+    for role in roles_for_host:
+        if not is_type_in_cluster(role):
             continue
-        _, _, id_ = split_role(name)
-        yield id_
+        yield role
 
 
 def all_roles(cluster):
index 4a9376d2e064682fc488265477adae27b5d26937..be0cc87585fba2827f050560ab5bc9e00b1df354 100644 (file)
@@ -134,6 +134,23 @@ def test_roles_of_type():
         assert ids == expected_ids
 
 
+def test_cluster_roles_of_type():
+    expected = [
+        (['client.0', 'osd.0', 'ceph.osd.1'], 'osd', 'ceph',
+         ['osd.0', 'ceph.osd.1']),
+        (['client.0', 'osd.0', 'ceph.osd.1'], 'client', 'ceph',
+         ['client.0']),
+        (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'mon', None, []),
+        (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client', None,
+         ['foo.client.1', 'bar.client.2.3']),
+        (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client', 'bar',
+         ['bar.client.2.3']),
+        ]
+    for roles_for_host, type_, cluster, expected_roles in expected:
+        roles = list(misc.cluster_roles_of_type(roles_for_host, type_, cluster))
+        assert roles == expected_roles
+
+
 def test_all_roles_of_type():
     expected = [
         ([['client.0', 'osd.0', 'ceph.osd.1'], ['bar.osd.2']],