ansible-test: prefer shlex.quote (#56823)

pull/56950/head
Martin Krizek 5 years ago committed by GitHub
parent 3b9478ade0
commit 484c023316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,6 @@ import re
import time import time
import textwrap import textwrap
import functools import functools
import pipes
import sys import sys
import hashlib import hashlib
import difflib import difflib
@ -61,6 +60,7 @@ from lib.util import (
get_remote_completion, get_remote_completion,
named_temporary_file, named_temporary_file,
COVERAGE_OUTPUT_PATH, COVERAGE_OUTPUT_PATH,
cmd_quote,
) )
from lib.docker_util import ( from lib.docker_util import (
@ -219,7 +219,7 @@ def install_command_requirements(args, python_version=None):
if changes: if changes:
raise ApplicationError('Conflicts detected in requirements. The following commands reported changes during verification:\n%s' % raise ApplicationError('Conflicts detected in requirements. The following commands reported changes during verification:\n%s' %
'\n'.join((' '.join(pipes.quote(c) for c in cmd) for cmd in changes))) '\n'.join((' '.join(cmd_quote(c) for c in cmd) for cmd in changes)))
# ask pip to check for conflicts between installed packages # ask pip to check for conflicts between installed packages
try: try:

@ -3,7 +3,6 @@
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import os import os
import pipes
import tempfile import tempfile
import time import time
@ -14,6 +13,7 @@ from lib.util import (
ApplicationError, ApplicationError,
run_command, run_command,
intercept_command, intercept_command,
cmd_quote,
) )
from lib.core_ci import ( from lib.core_ci import (
@ -107,7 +107,7 @@ class ManageWindowsCI(object):
options.append('-tt') options.append('-tt')
if isinstance(command, list): if isinstance(command, list):
command = ' '.join(pipes.quote(c) for c in command) command = ' '.join(cmd_quote(c) for c in command)
run_command(self.core_ci.args, run_command(self.core_ci.args,
['ssh', '-q'] + self.ssh_args + ['ssh', '-q'] + self.ssh_args +
@ -273,14 +273,14 @@ class ManagePosixCI(object):
options = [] options = []
if isinstance(command, list): if isinstance(command, list):
command = ' '.join(pipes.quote(c) for c in command) command = ' '.join(cmd_quote(c) for c in command)
run_command(self.core_ci.args, run_command(self.core_ci.args,
['ssh', '-tt', '-q'] + self.ssh_args + ['ssh', '-tt', '-q'] + self.ssh_args +
options + options +
['-p', str(self.core_ci.connection.port), ['-p', str(self.core_ci.connection.port),
'%s@%s' % (self.core_ci.connection.username, self.core_ci.connection.hostname)] + '%s@%s' % (self.core_ci.connection.username, self.core_ci.connection.hostname)] +
self.become + [pipes.quote(command)]) self.become + [cmd_quote(command)])
def scp(self, src, dst): def scp(self, src, dst):
""" """

@ -9,7 +9,6 @@ import fcntl
import inspect import inspect
import json import json
import os import os
import pipes
import pkgutil import pkgutil
import random import random
import re import re
@ -38,6 +37,11 @@ except ImportError:
# noinspection PyCompatibility # noinspection PyCompatibility
from configparser import ConfigParser from configparser import ConfigParser
try:
from shlex import quote as cmd_quote
except ImportError:
from pipes import quote as cmd_quote
DOCKER_COMPLETION = {} # type: dict[str, dict[str, str]] DOCKER_COMPLETION = {} # type: dict[str, dict[str, str]]
REMOTE_COMPLETION = {} # type: dict[str, dict[str, str]] REMOTE_COMPLETION = {} # type: dict[str, dict[str, str]]
PYTHON_PATHS = {} # type: dict[str, str] PYTHON_PATHS = {} # type: dict[str, str]
@ -389,7 +393,7 @@ def raw_command(cmd, capture=False, env=None, data=None, cwd=None, explain=False
cmd = list(cmd) cmd = list(cmd)
escaped_cmd = ' '.join(pipes.quote(c) for c in cmd) escaped_cmd = ' '.join(cmd_quote(c) for c in cmd)
display.info('Run command: %s' % escaped_cmd, verbosity=cmd_verbosity, truncate=True) display.info('Run command: %s' % escaped_cmd, verbosity=cmd_verbosity, truncate=True)
display.info('Working directory: %s' % cwd, verbosity=2) display.info('Working directory: %s' % cwd, verbosity=2)
@ -763,7 +767,7 @@ class SubprocessError(ApplicationError):
:type stderr: str | None :type stderr: str | None
:type runtime: float | None :type runtime: float | None
""" """
message = 'Command "%s" returned exit status %s.\n' % (' '.join(pipes.quote(c) for c in cmd), status) message = 'Command "%s" returned exit status %s.\n' % (' '.join(cmd_quote(c) for c in cmd), status)
if stderr: if stderr:
message += '>>> Standard Error\n' message += '>>> Standard Error\n'

Loading…
Cancel
Save