diff --git a/test/lib/ansible_test/_internal/become.py b/test/lib/ansible_test/_internal/become.py index 25df71089f5..a9a98bd8142 100644 --- a/test/lib/ansible_test/_internal/become.py +++ b/test/lib/ansible_test/_internal/become.py @@ -34,7 +34,7 @@ class Doas(Become): become = ['doas', '-n'] if command: - become.extend(['sh', '-c', ' '.join(shlex.quote(c) for c in command)]) + become.extend(['sh', '-c', shlex.join(command)]) else: become.extend(['-s']) @@ -53,7 +53,7 @@ class Su(Become): become = ['su', '-l', 'root'] if command: - become.extend(['-c', ' '.join(shlex.quote(c) for c in command)]) + become.extend(['-c', shlex.join(command)]) return become @@ -70,7 +70,7 @@ class Sudo(Become): become = ['sudo', '-in'] if command: - become.extend(['sh', '-c', ' '.join(shlex.quote(c) for c in command)]) + become.extend(['sh', '-c', shlex.join(command)]) return become diff --git a/test/lib/ansible_test/_internal/connections.py b/test/lib/ansible_test/_internal/connections.py index 026058abb4f..05b53ac3040 100644 --- a/test/lib/ansible_test/_internal/connections.py +++ b/test/lib/ansible_test/_internal/connections.py @@ -81,7 +81,7 @@ class Connection(metaclass=abc.ABCMeta): # Using gzip to compress the archive allows this to work on all POSIX systems we support. commands = [tar_cmd, gzip_cmd] - sh_cmd = ['sh', '-c', ' | '.join(' '.join(shlex.quote(cmd) for cmd in command) for command in commands)] + sh_cmd = ['sh', '-c', ' | '.join(shlex.join(command) for command in commands)] retry(lambda: self.run(sh_cmd, stdout=dst, capture=True)) @@ -160,7 +160,7 @@ class SshConnection(Connection): options.extend(['-p', str(self.settings.port)]) options.append(f'{self.settings.user}@{self.settings.host}') - options.append(' '.join(shlex.quote(cmd) for cmd in command)) + options.append(shlex.join(command)) def error_callback(ex): # type: (SubprocessError) -> None """Error handler.""" diff --git a/test/lib/ansible_test/_internal/ssh.py b/test/lib/ansible_test/_internal/ssh.py index 184e89406f2..c2dfb277c34 100644 --- a/test/lib/ansible_test/_internal/ssh.py +++ b/test/lib/ansible_test/_internal/ssh.py @@ -176,7 +176,7 @@ def run_ssh_command( cmd = create_ssh_command(ssh, options, cli_args, command) env = common_environment() - cmd_show = ' '.join([shlex.quote(c) for c in cmd]) + cmd_show = shlex.join(cmd) display.info('Run background command: %s' % cmd_show, verbosity=1, truncate=True) cmd_bytes = [to_bytes(c) for c in cmd] diff --git a/test/lib/ansible_test/_internal/util.py b/test/lib/ansible_test/_internal/util.py index 9409b1e5933..5bc4cb5b60f 100644 --- a/test/lib/ansible_test/_internal/util.py +++ b/test/lib/ansible_test/_internal/util.py @@ -368,7 +368,7 @@ def raw_command( cmd = list(cmd) - escaped_cmd = ' '.join(shlex.quote(c) for c in cmd) + escaped_cmd = shlex.join(cmd) if capture: description = 'Run' @@ -867,7 +867,7 @@ class SubprocessError(ApplicationError): runtime=None, # type: t.Optional[float] error_callback=None, # type: t.Optional[t.Callable[[SubprocessError], None]] ): # type: (...) -> None - message = 'Command "%s" returned exit status %s.\n' % (' '.join(shlex.quote(c) for c in cmd), status) + message = 'Command "%s" returned exit status %s.\n' % (shlex.join(cmd), status) if stderr: message += '>>> Standard Error\n'