From: Josh Durgin Date: Tue, 15 Mar 2016 22:13:27 +0000 (-0700) Subject: misc: make roles_of_type() cluster-aware X-Git-Tag: 1.1.0~615^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e77f185797e3fb7d0f3edfad540ff66840972c09;p=teuthology.git misc: make roles_of_type() cluster-aware Signed-off-by: Josh Durgin --- diff --git a/teuthology/misc.py b/teuthology/misc.py index f5128fd89..8e09f647a 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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_ diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index 9476af4df..3b539c1a1 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -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"