]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: make roles_of_type() cluster-aware
authorJosh Durgin <jdurgin@redhat.com>
Tue, 15 Mar 2016 22:13:27 +0000 (15:13 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:05 +0000 (14:36 -0700)
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index f5128fd8965a006a455d1ff2a0fbb8aaf22103bc..8e09f647a67aeeeb2d93197e8fc343130662f6b6 100644 (file)
@@ -377,11 +377,11 @@ def roles_of_type(roles_for_host, type_):
     :param roles_for host: list of roles possible
     :param type_: type of role
     """
-    prefix = '{type}.'.format(type=type_)
+    is_of_type = is_type(type_)
     for name in roles_for_host:
-        if not name.startswith(prefix):
+        if not is_of_type(name):
             continue
-        id_ = name[len(prefix):]
+        _, _, id_ = split_role(name)
         yield id_
 
 
index 9476af4df07bead1133c86796d5587cd2501b1ec..3b539c1a1336fe55f63a0b12f115a4c0988554d2 100644 (file)
@@ -89,6 +89,19 @@ def test_get_clients_simple():
         next(g)
 
 
+def test_roles_of_type():
+    expected = [
+        (['client.0', 'osd.0', 'ceph.osd.1'], 'osd', ['0', '1']),
+        (['client.0', 'osd.0', 'ceph.osd.1'], 'client', ['0']),
+        (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'mon', []),
+        (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client',
+         ['1', '2.3']),
+        ]
+    for roles_for_host, type_, expected_ids in expected:
+        ids = list(misc.roles_of_type(roles_for_host, type_))
+        assert ids == expected_ids
+
+
 def test_get_http_log_path():
     # Fake configuration
     archive_server = "http://example.com/server_root"