Skip to content

Commit

Permalink
misc: add cluster-aware roles filter
Browse files Browse the repository at this point in the history
Unlike roles_of_type, this actually returns roles. We can't change the
semantics of the existing one due to backwards compatibility
requirements for old ceph-qa-suite branches, so make a new function
and implement the old one in terms of the new more general interface.

Signed-off-by: Josh Durgin <[email protected]>
  • Loading branch information
jdurgin committed Apr 11, 2016
1 parent 79fb944 commit 0c54b16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
23 changes: 18 additions & 5 deletions teuthology/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,32 @@ def split_role(role):


def roles_of_type(roles_for_host, type_):
"""
Generator of ids.
Each call returns the next possible role of the type specified.
:param roles_for host: list of roles possible
:param type_: type of role
"""
for role in cluster_roles_of_type(roles_for_host, type_, None):
_, _, id_ = split_role(role)
yield id_


def cluster_roles_of_type(roles_for_host, type_, cluster):
"""
Generator of roles.
Each call returns the next possible role of the type specified.
:param roles_for host: list of roles possible
:param type_: type of role
:param cluster: cluster name
"""
is_of_type = is_type(type_)
for name in roles_for_host:
if not is_of_type(name):
is_type_in_cluster = is_type(type_, cluster)
for role in roles_for_host:
if not is_type_in_cluster(role):
continue
_, _, id_ = split_role(name)
yield id_
yield role


def all_roles(cluster):
Expand Down
17 changes: 17 additions & 0 deletions teuthology/test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ def test_roles_of_type():
assert ids == expected_ids


def test_cluster_roles_of_type():
expected = [
(['client.0', 'osd.0', 'ceph.osd.1'], 'osd', 'ceph',
['osd.0', 'ceph.osd.1']),
(['client.0', 'osd.0', 'ceph.osd.1'], 'client', 'ceph',
['client.0']),
(['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'mon', None, []),
(['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client', None,
['foo.client.1', 'bar.client.2.3']),
(['foo.client.1', 'bar.client.2.3', 'baz.osd.1'], 'client', 'bar',
['bar.client.2.3']),
]
for roles_for_host, type_, cluster, expected_roles in expected:
roles = list(misc.cluster_roles_of_type(roles_for_host, type_, cluster))
assert roles == expected_roles


def test_all_roles_of_type():
expected = [
([['client.0', 'osd.0', 'ceph.osd.1'], ['bar.osd.2']],
Expand Down

0 comments on commit 0c54b16

Please sign in to comment.