From 754d6b3049803789ba364c376acf10bee2095bcd Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Tue, 15 Mar 2016 14:08:36 -0700 Subject: [PATCH] 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 --- teuthology/misc.py | 11 ++++++++--- teuthology/test/test_misc.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 68865e22a5..4947b2e0ac 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 bd070e31ac..645cb53990 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() -- 2.39.5