From: John Mulligan Date: Mon, 26 Feb 2024 21:17:22 +0000 (-0500) Subject: qa/tasks: add a template filter to map a role name to a remote X-Git-Tag: v20.0.0~2300^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=361cbd46b9c5431452c742edd3ca7f0280e4161b;p=ceph.git qa/tasks: add a template filter to map a role name to a remote Add a `role_to_remote` template filter function that has the ability to map a role name to a remote. Attributes of the remote can then be used to get the actual node ip or name. Signed-off-by: John Mulligan --- diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index ca6e33d13169d..69510c645e3a1 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -75,6 +75,7 @@ def _template_transform(ctx, config, target): if jenv is None: loader = jinja2.BaseLoader() jenv = jinja2.Environment(loader=loader) + jenv.filters['role_to_remote'] = _role_to_remote setattr(ctx, '_jinja_env', jenv) rctx = dict(ctx=ctx, config=config, cluster_name=config.get('cluster', '')) _vip_vars(rctx) @@ -94,6 +95,16 @@ def _vip_vars(rctx): rctx[f'VIP{idx}'] = str(vip) +@jinja2.pass_context +def _role_to_remote(rctx, role): + """Return the first remote matching the given role.""" + ctx = rctx['ctx'] + for remote, roles in ctx.cluster.remotes.items(): + if role in roles: + return remote + return None + + def _shell(ctx, cluster_name, remote, args, extra_cephadm_args=[], **kwargs): teuthology.get_testdir(ctx) return remote.run(