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.
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
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']