From: Josh Durgin Date: Tue, 15 Mar 2016 21:40:05 +0000 (-0700) Subject: misc: add helpers to get components of a role X-Git-Tag: 1.1.0~615^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=327615028d17dba8b168d0e96d274d8581c0f1f8;p=teuthology.git misc: add helpers to get components of a role Signed-off-by: Josh Durgin --- diff --git a/teuthology/misc.py b/teuthology/misc.py index 2df4b1fd3..59077f00f 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -346,6 +346,26 @@ def skeleton_config(ctx, roles, ips): return conf +def ceph_role(role): + """ + Return the ceph name for the role, without any cluster prefix, e.g. osd.0. + """ + _, type_, id_ = split_role(role) + return type_ + '.' + id_ + + +def split_role(role): + """ + Return a tuple of cluster, type, and id + If no cluster is included in the role, the default cluster, 'ceph', is used + """ + cluster = 'ceph' + if role.count('.') > 1: + cluster, role = role.split('.', 1) + type_, id_ = role.split('.', 1) + return cluster, type_, id_ + + def roles_of_type(roles_for_host, type_): """ Generator of roles. diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index 6b392bfbe..9476af4df 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -149,6 +149,18 @@ def test_get_mons(): 'ceph.mon.c': ips[2] + ':6789'} +def test_split_role(): + expected = { + 'client.0': ('ceph', 'client', '0'), + 'foo.client.0': ('foo', 'client', '0'), + 'bar.baz.x.y.z': ('bar', 'baz', 'x.y.z'), + 'mds.a-s-b': ('ceph', 'mds', 'a-s-b'), + } + + for role, expected_split in expected.items(): + actual_split = misc.split_role(role) + assert actual_split == expected_split + class TestHostnames(object): def setup(self): config._conf = dict()