Skip to content

Commit

Permalink
misc: add helpers to get components of a role
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Durgin <[email protected]>
  • Loading branch information
jdurgin committed Apr 11, 2016
1 parent 2b95cab commit 3276150
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions teuthology/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions teuthology/test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3276150

Please sign in to comment.