ansible-test - Use shlex.join where appropriate.

pull/78091/head
Matt Clay 2 years ago
parent 24d91f552c
commit cf9fd2d7da

@ -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

@ -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."""

@ -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]

@ -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'

Loading…
Cancel
Save