]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: a new cephadm exec task similar to vip.exec but generalized
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 26 Feb 2024 21:16:57 +0000 (16:16 -0500)
committerAdam King <adking@redhat.com>
Mon, 15 Apr 2024 15:01:30 +0000 (11:01 -0400)
Add a new cephadm.exec task that works similarly to the existing
vip.exec but instead of only considering VIP related string replacements
it uses that templating feature that was recently added to the
cephadm module for generalized string templating.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 1ed66542ef27f5382d82b7cc60e76c2fe6d30fc9)

qa/tasks/cephadm.py

index a7069c19fe7b146059a77d4f7135bd2fdcf16aef..ca6e33d13169da223d66d0b94d11dd97c3246748 100644 (file)
@@ -1463,6 +1463,41 @@ def _shell_command(obj):
     raise ValueError(f'invalid command item: {obj!r}')
 
 
+def exec(ctx, config):
+    """
+    This is similar to the standard 'exec' task, but does template substitutions.
+
+    TODO: this should probably be moved out of cephadm.py as it's pretty generic.
+    """
+    assert isinstance(config, dict), "task exec got invalid config"
+
+    testdir = teuthology.get_testdir(ctx)
+
+    if 'all-roles' in config and len(config) == 1:
+        a = config['all-roles']
+        roles = teuthology.all_roles(ctx.cluster)
+        config = dict((id_, a) for id_ in roles if not id_.startswith('host.'))
+    elif 'all-hosts' in config and len(config) == 1:
+        a = config['all-hosts']
+        roles = teuthology.all_roles(ctx.cluster)
+        config = dict((id_, a) for id_ in roles if id_.startswith('host.'))
+
+    for role, ls in config.items():
+        (remote,) = ctx.cluster.only(role).remotes.keys()
+        log.info('Running commands on role %s host %s', role, remote.name)
+        for c in ls:
+            c.replace('$TESTDIR', testdir)
+            remote.run(
+                args=[
+                    'sudo',
+                    'TESTDIR={tdir}'.format(tdir=testdir),
+                    'bash',
+                    '-ex',
+                    '-c',
+                    _template_transform(ctx, config, c)],
+                )
+
+
 def apply(ctx, config):
     """
     Apply spec