From: Dan Mick Date: Sat, 1 Feb 2014 00:07:52 +0000 (-0800) Subject: misc.py: helper roles_to_remotes for generic use X-Git-Tag: 1.1.0~1666^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9b2b2c28f11fbc75509b1dbf42fe2b2c7056017f;p=teuthology.git misc.py: helper roles_to_remotes for generic use roles_to_remotes will take a config key, 'roles' by default, and search cluster.remotes for those roles, returning a list of remotes that hold it. The list is uniquified by default, but that can be overridden. So you can have a task that should run on specific roles, configure it with "roles: [mon.0 server.0 osd.2]", and call this to get a list of remotes that contain those roles. Signed-off-by: Dan Mick --- diff --git a/teuthology/misc.py b/teuthology/misc.py index 1bc2fa65b..2f7495332 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -872,6 +872,21 @@ def replace_all_with_clients(cluster, config): norm_config['client.{id}'.format(id=client)] = config['all'] return norm_config +def roles_to_remotes(cluster, config, attrname='roles', unique=True): + """ + Get a list of roles from attrname, and return a list of + remotes corresponding to those roles. If 'unique' is False, + allow duplicates in the returned remote list (if a remote serves + multiple roles). attrname may not exist, in which case the + returned list is empty. + """ + roles = config.get(attrname, list()) + remotes = [] + for role in roles: + rem = cluster.only(role).remotes.keys()[0] + if (not unique) or (rem not in remotes): + remotes.append(rem) + return remotes def deep_merge(a, b): if a is None: