]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: add a template filter to map a role name to a remote
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 26 Feb 2024 21:17:22 +0000 (16:17 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 21 Mar 2024 22:31:16 +0000 (18:31 -0400)
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 <jmulligan@redhat.com>
qa/tasks/cephadm.py

index ca6e33d13169da223d66d0b94d11dd97c3246748..69510c645e3a183a484d62ee6f106682a0debc27 100644 (file)
@@ -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(