]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: add helpers to get components of a role
authorJosh Durgin <jdurgin@redhat.com>
Tue, 15 Mar 2016 21:40:05 +0000 (14:40 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:04 +0000 (14:36 -0700)
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 2df4b1fd3ff560f59c8be0074f1a3fad811a41eb..59077f00ff68ab5cb3a20e5451bb8601f18263cf 100644 (file)
@@ -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.
index 6b392bfbe2bca276595fcc3616ebd1ad50f0d1f4..9476af4df07bead1133c86796d5587cd2501b1ec 100644 (file)
@@ -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()