]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: add optional cluster filter to is_type
authorJosh Durgin <jdurgin@redhat.com>
Thu, 17 Mar 2016 00:09:21 +0000 (17:09 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:41 +0000 (14:36 -0700)
reimplement in terms of split_role while we're at it

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 53e73669240acc06a8723dd634e655c2ea855f76..318b0598b0098ee7ea3cecde74a7d68f8c9be050 100644 (file)
@@ -409,12 +409,12 @@ def all_roles_of_type(cluster, type_):
             yield id_
 
 
-def is_type(type_):
+def is_type(type_, cluster=None):
     """
     Returns a matcher function for whether role is of type given.
-    """
-    prefix = '{type}.'.format(type=type_)
 
+    :param cluster: cluster name to check in matcher (default to no check for cluster)
+    """
     def _is_type(role):
         """
         Return type based on the starting role name.
@@ -422,10 +422,10 @@ def is_type(type_):
         If there is more than one period, strip the first part
         (ostensibly a cluster name) and check the remainder for the prefix.
         """
-        if role.startswith(prefix):
-            return True
-        return (role.count('.') > 1 and
-                role[role.find('.') + 1:].startswith(prefix))
+        role_cluster, role_type, _ = split_role(role)
+        if cluster is not None and role_cluster != cluster:
+            return False
+        return role_type == type_
     return _is_type
 
 
index 80f18915d4e0991c0e3208607c853e41d06beeeb..4a9376d2e064682fc488265477adae27b5d26937 100644 (file)
@@ -183,13 +183,26 @@ def test_is_type():
     assert is_client('foo.client.0')
     assert is_client('foo.client.bar.baz')
 
-    assert not is_client('')
+    with pytest.raises(ValueError):
+        is_client('')
+        is_client('client')
     assert not is_client('foo.bar.baz')
     assert not is_client('ceph.client')
-    assert not is_client('client')
     assert not is_client('hadoop.master.0')
 
 
+def test_is_type_in_cluster():
+    is_c1_osd = misc.is_type('osd', 'c1')
+    with pytest.raises(ValueError):
+        is_c1_osd('')
+    assert not is_c1_osd('osd.0')
+    assert not is_c1_osd('ceph.osd.0')
+    assert not is_c1_osd('ceph.osd.0')
+    assert not is_c1_osd('c11.osd.0')
+    assert is_c1_osd('c1.osd.0')
+    assert is_c1_osd('c1.osd.999')
+
+
 def test_get_mons():
     ips = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
     addrs = ['1.1.1.1:6789', '1.1.1.1:6790', '1.1.1.1:6791']