From: Josh Durgin Date: Thu, 17 Mar 2016 00:09:21 +0000 (-0700) Subject: misc: add optional cluster filter to is_type X-Git-Tag: 1.1.0~615^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=79fb9442ebed21e0eff97a78f77b92aebe21c052;p=teuthology.git misc: add optional cluster filter to is_type reimplement in terms of split_role while we're at it Signed-off-by: Josh Durgin --- diff --git a/teuthology/misc.py b/teuthology/misc.py index 53e73669..318b0598 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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 diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index 80f18915..4a9376d2 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -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']