Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-test: prefer shlex.quote #56823

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions test/runner/lib/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import time
import textwrap
import functools
import pipes
import sys
import hashlib
import difflib
Expand All @@ -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

mkrizek marked this conversation as resolved.
Show resolved Hide resolved
import lib.pytar
import lib.thread

Expand Down Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions test/runner/lib/manage_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

mkrizek marked this conversation as resolved.
Show resolved Hide resolved
import lib.pytar

from lib.util import (
Expand Down Expand Up @@ -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 +
Expand Down Expand Up @@ -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):
"""
Expand Down
10 changes: 7 additions & 3 deletions test/runner/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import inspect
import json
import os
import pipes
import pkgutil
import random
import re
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down