]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: allow passing stdin string to cephadm shell commands
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 24 Feb 2024 19:26:36 +0000 (14:26 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 21 Mar 2024 22:30:58 +0000 (18:30 -0400)
There are cases where I want to pass some large-ish strings to ceph
commands executed via cephadm shell. Allow items within the commands
list to be dicts containing a command (as before) and an optional
stdin variable. This change also supports possible future extensions as
well.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
qa/tasks/cephadm.py

index 927cf6c4599fff7e78db80e4bbd6cfe4ad024b90..daf36fb84cc5055d4a5b2c593536f45322778098 100644 (file)
@@ -1421,10 +1421,17 @@ def shell(ctx, config):
         (remote,) = ctx.cluster.only(role).remotes.keys()
         log.info('Running commands on role %s host %s', role, remote.name)
         if isinstance(cmd, list):
-            for c in cmd:
-                _shell(ctx, cluster_name, remote,
-                       ['bash', '-c', c],
-                       extra_cephadm_args=args)
+            for cobj in cmd:
+                sh_cmd, stdin = _shell_command(cobj)
+                _shell(
+                    ctx,
+                    cluster_name,
+                    remote,
+                    ['bash', '-c', sh_cmd],
+                    extra_cephadm_args=args,
+                    stdin=stdin,
+                )
+
         else:
             assert isinstance(cmd, str)
             _shell(ctx, cluster_name, remote,
@@ -1432,6 +1439,16 @@ def shell(ctx, config):
                    extra_cephadm_args=args)
 
 
+def _shell_command(obj):
+    if isinstance(obj, str):
+        return obj, None
+    if isinstance(obj, dict):
+        cmd = obj['cmd']
+        stdin = obj.get('stdin', None)
+        return cmd, stdin
+    raise ValueError(f'invalid command item: {obj!r}')
+
+
 def apply(ctx, config):
     """
     Apply spec