]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: reduce duplicated code
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 27 Feb 2024 14:44:51 +0000 (09:44 -0500)
committerAdam King <adking@redhat.com>
Mon, 15 Apr 2024 15:01:30 +0000 (11:01 -0400)
All `exec`-style function in teuthology appear to have a transformation
block that expands names like `all-roles` and `all-hosts`. With the new
cephadm.exec task that block appeared twice in cephadm.py. This change
removes the duplication by creating an _expand_roles function that
can be called from the command executing functions.

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

qa/tasks/cephadm.py

index 69510c645e3a183a484d62ee6f106682a0debc27..fdc9fdcd7392f8e66c903bc40df1fdaf7a2fada9 100644 (file)
@@ -1420,6 +1420,18 @@ def stop(ctx, config):
     yield
 
 
+def _expand_roles(ctx, config):
+    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.'))
+    return config
+
+
 def shell(ctx, config):
     """
     Execute (shell) commands
@@ -1432,15 +1444,7 @@ def shell(ctx, config):
     for k in config.pop('volumes', []):
         args.extend(['-v', k])
 
-    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.'))
-
+    config = _expand_roles(ctx, config)
     config = _template_transform(ctx, config, config)
     for role, cmd in config.items():
         (remote,) = ctx.cluster.only(role).remotes.keys()
@@ -1481,18 +1485,8 @@ def exec(ctx, config):
     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.'))
-
+    config = _expand_roles(ctx, config)
     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)