Skip to content

Commit 361cbd4

Browse files
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 <[email protected]>
1 parent 1ed6654 commit 361cbd4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

qa/tasks/cephadm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def _template_transform(ctx, config, target):
7575
if jenv is None:
7676
loader = jinja2.BaseLoader()
7777
jenv = jinja2.Environment(loader=loader)
78+
jenv.filters['role_to_remote'] = _role_to_remote
7879
setattr(ctx, '_jinja_env', jenv)
7980
rctx = dict(ctx=ctx, config=config, cluster_name=config.get('cluster', ''))
8081
_vip_vars(rctx)
@@ -94,6 +95,16 @@ def _vip_vars(rctx):
9495
rctx[f'VIP{idx}'] = str(vip)
9596

9697

98+
@jinja2.pass_context
99+
def _role_to_remote(rctx, role):
100+
"""Return the first remote matching the given role."""
101+
ctx = rctx['ctx']
102+
for remote, roles in ctx.cluster.remotes.items():
103+
if role in roles:
104+
return remote
105+
return None
106+
107+
97108
def _shell(ctx, cluster_name, remote, args, extra_cephadm_args=[], **kwargs):
98109
teuthology.get_testdir(ctx)
99110
return remote.run(

0 commit comments

Comments
 (0)