From 33bd7f9742b480f70ffe05e49e3631bf4e5cf1e9 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Thu, 23 May 2019 08:11:32 +0200 Subject: [PATCH 1/2] ansible-test: prefer shlex.quote --- test/runner/lib/executor.py | 8 ++++++-- test/runner/lib/manage_ci.py | 12 ++++++++---- test/runner/lib/util.py | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 054b964c3b4619..1c73b1921b6696 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -10,7 +10,6 @@ import time import textwrap import functools -import pipes import sys import hashlib import difflib @@ -19,6 +18,11 @@ import string import shutil +try: + from shlex import quote as cmd_quote +except ImportError: + from pipes import quote as cmd_quote + import lib.pytar import lib.thread @@ -219,7 +223,7 @@ def install_command_requirements(args, python_version=None): if changes: 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 try: diff --git a/test/runner/lib/manage_ci.py b/test/runner/lib/manage_ci.py index 8376d06a1b6274..070a4b53a570cb 100644 --- a/test/runner/lib/manage_ci.py +++ b/test/runner/lib/manage_ci.py @@ -3,10 +3,14 @@ from __future__ import absolute_import, print_function import os -import pipes import tempfile import time +try: + from shlex import quote as cmd_quote +except ImportError: + from pipes import quote as cmd_quote + import lib.pytar from lib.util import ( @@ -107,7 +111,7 @@ def ssh(self, command, options=None, force_pty=True): 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 + @@ -273,14 +277,14 @@ def ssh(self, command, options=None): 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 359e1250006b3f..203aa71467434b 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -9,7 +9,6 @@ import inspect import json import os -import pipes import pkgutil import random import re @@ -38,6 +37,11 @@ # noinspection PyCompatibility 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]] REMOTE_COMPLETION = {} # type: dict[str, 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) - 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) @@ -763,7 +767,7 @@ def __init__(self, cmd, status=0, stdout=None, stderr=None, runtime=None): :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' From be38aee4c29b7fb355eb780495ee5151b1092461 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Thu, 23 May 2019 10:09:21 +0200 Subject: [PATCH 2/2] Use cmd_quote from lib.util --- test/runner/lib/executor.py | 6 +----- test/runner/lib/manage_ci.py | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 1c73b1921b6696..c3944301134b03 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -18,11 +18,6 @@ import string import shutil -try: - from shlex import quote as cmd_quote -except ImportError: - from pipes import quote as cmd_quote - import lib.pytar import lib.thread @@ -65,6 +60,7 @@ get_remote_completion, named_temporary_file, COVERAGE_OUTPUT_PATH, + cmd_quote, ) from lib.docker_util import ( diff --git a/test/runner/lib/manage_ci.py b/test/runner/lib/manage_ci.py index 070a4b53a570cb..0e1df84a89956b 100644 --- a/test/runner/lib/manage_ci.py +++ b/test/runner/lib/manage_ci.py @@ -6,11 +6,6 @@ import tempfile import time -try: - from shlex import quote as cmd_quote -except ImportError: - from pipes import quote as cmd_quote - import lib.pytar from lib.util import ( @@ -18,6 +13,7 @@ ApplicationError, run_command, intercept_command, + cmd_quote, ) from lib.core_ci import (