From 361cbd46b9c5431452c742edd3ca7f0280e4161b Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 26 Feb 2024 16:17:22 -0500 Subject: [PATCH] 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 --- qa/tasks/cephadm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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( -- 2.39.5