summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Krizek <martin.krizek@gmail.com>2019-05-24 22:10:33 +0200
committerToshio Kuratomi <a.badger@gmail.com>2019-05-28 12:41:51 -0700
commitb6c6046987dc2cbc29e03104afe5ef6d9a1a2568 (patch)
tree054b4edaa433faeea994f500dd5a1f1aacdda518
parent03bab95231ef2f12e273f91ce3538e382cf3e69b (diff)
downloadansible-b6c6046987dc2cbc29e03104afe5ef6d9a1a2568.tar.gz
ansible-test: prefer shlex.quote (#56823)
(cherry picked from commit 484c0233169a6e037a3ce57830114e51d00898af)
-rw-r--r--test/runner/lib/executor.py4
-rw-r--r--test/runner/lib/manage_ci.py8
-rw-r--r--test/runner/lib/util.py10
3 files changed, 13 insertions, 9 deletions
diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py
index 8d212572c2..f3f5cef591 100644
--- a/test/runner/lib/executor.py
+++ b/test/runner/lib/executor.py
@@ -11,7 +11,6 @@ import tempfile
import time
import textwrap
import functools
-import pipes
import sys
import hashlib
import difflib
@@ -55,6 +54,7 @@ from lib.util import (
generate_pip_command,
find_python,
get_docker_completion,
+ cmd_quote,
)
from lib.docker_util import (
@@ -210,7 +210,7 @@ def install_command_requirements(args, python_version=None):
return # no changes means no conflicts
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)))
def run_pip_commands(args, pip, commands, detect_pip_changes=False):
diff --git a/test/runner/lib/manage_ci.py b/test/runner/lib/manage_ci.py
index ed6aa25f60..5c0e9c889b 100644
--- a/test/runner/lib/manage_ci.py
+++ b/test/runner/lib/manage_ci.py
@@ -3,7 +3,6 @@
from __future__ import absolute_import, print_function
import os
-import pipes
import tempfile
import time
@@ -14,6 +13,7 @@ from lib.util import (
ApplicationError,
run_command,
intercept_command,
+ cmd_quote,
)
from lib.core_ci import (
@@ -105,7 +105,7 @@ class ManageWindowsCI(object):
options.append('-tt')
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,
['ssh', '-q'] + self.ssh_args +
@@ -267,14 +267,14 @@ class ManagePosixCI(object):
options = []
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,
['ssh', '-tt', '-q'] + self.ssh_args +
options +
['-p', str(self.core_ci.connection.port),
'%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):
"""
diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py
index a8f88a8e76..97a991b2cb 100644
--- a/test/runner/lib/util.py
+++ b/test/runner/lib/util.py
@@ -9,7 +9,6 @@ import fcntl
import inspect
import json
import os
-import pipes
import pkgutil
import random
import re
@@ -41,6 +40,11 @@ except ImportError:
DOCKER_COMPLETION = {}
COVERAGE_PATHS = {} # type: dict[str, str]
+try:
+ from shlex import quote as cmd_quote
+except ImportError:
+ from pipes import quote as cmd_quote
+
def get_docker_completion():
"""
@@ -335,7 +339,7 @@ def raw_command(cmd, capture=False, env=None, data=None, cwd=None, explain=False
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('Working directory: %s' % cwd, verbosity=2)
@@ -701,7 +705,7 @@ class SubprocessError(ApplicationError):
:type stderr: str | 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:
message += '>>> Standard Error\n'