From: Josh Durgin Date: Tue, 15 Mar 2016 21:08:36 +0000 (-0700) Subject: misc: allow a prefix for cluster in is_type() X-Git-Tag: 1.1.0~615^2~21 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=754d6b3049803789ba364c376acf10bee2095bcd;p=teuthology.git misc: allow a prefix for cluster in is_type() This still matches roles with no prefix first, so it stays compatible with existing suites. Signed-off-by: Josh Durgin --- diff --git a/teuthology/misc.py b/teuthology/misc.py index 68865e22a..4947b2e0a 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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 diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index bd070e31a..645cb5399 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -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()