:param roles_for host: list of roles possible
:param type_: type of role
"""
- prefix = '{type}.'.format(type=type_)
+ is_of_type = is_type(type_)
for name in roles_for_host:
- if not name.startswith(prefix):
+ if not is_of_type(name):
continue
- id_ = name[len(prefix):]
+ _, _, id_ = split_role(name)
yield id_
next(g)
+def test_roles_of_type():
+ expected = [
+ (['client.0', 'osd.0', 'ceph.osd.1'], 'osd', ['0', '1']),
+ (['client.0', 'osd.0', 'ceph.osd.1'], 'client', ['0']),
+ (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'mon', []),
+ (['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client',
+ ['1', '2.3']),
+ ]
+ for roles_for_host, type_, expected_ids in expected:
+ ids = list(misc.roles_of_type(roles_for_host, type_))
+ assert ids == expected_ids
+
+
def test_get_http_log_path():
# Fake configuration
archive_server = "http://example.com/server_root"