From: John Mulligan Date: Sat, 24 Feb 2024 19:26:36 +0000 (-0500) Subject: qa/tasks: allow passing stdin string to cephadm shell commands X-Git-Tag: v19.1.0~82^2~8 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2beca806fba676ead5bdc5fb82a1d3f67a9ea4db;p=ceph.git qa/tasks: allow passing stdin string to cephadm shell commands 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 (cherry picked from commit 2a917e23ca6b3d2a4b90a40a07a1b5ae299b3924) --- diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 927cf6c4599ff..daf36fb84cc50 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -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