]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: allow a prefix for cluster in is_type()
authorJosh Durgin <jdurgin@redhat.com>
Tue, 15 Mar 2016 21:08:36 +0000 (14:08 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:04 +0000 (14:36 -0700)
This still matches roles with no prefix first, so it stays compatible
with existing suites.

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

index 68865e22a59f359c523a515a4b4077e80af63f34..4947b2e0ac426121f6d16f1cf289330ebdf42db8 100644 (file)
@@ -397,10 +397,15 @@ def is_type(type_):
 
     def _is_type(role):
         """
-        Return type based on the starting role name.  This should
-        probably be improved in the future.
+        Return type based on the starting role name.
+
+        If there is more than one period, strip the first part
+        (ostensibly a cluster name) and check the remainder for the prefix.
         """
-        return role.startswith(prefix)
+        if role.startswith(prefix):
+            return True
+        return (role.count('.') > 1 and
+                role[role.find('.') + 1:].startswith(prefix))
     return _is_type
 
 
index bd070e31acd3a5d1346f0da9bae2ddf8d832354f..645cb53990839c5138c148cb14f8a5efcaa9a84a 100644 (file)
@@ -114,6 +114,20 @@ def test_get_http_log_path():
     assert path == "http://qa-proxy.ceph.com/teuthology/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps/"
 
 
+def test_is_type():
+    is_client = misc.is_type('client')
+    assert is_client('client.0')
+    assert is_client('ceph.client.0')
+    assert is_client('foo.client.0')
+    assert is_client('foo.client.bar.baz')
+
+    assert not is_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')
+
+
 class TestHostnames(object):
     def setup(self):
         config._conf = dict()