summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-11-17 13:18:29 -0800
committerGitHub <noreply@github.com>2016-11-17 13:18:29 -0800
commited00741a01ed4eb935797afc74cabf6ce0a0e7fa (patch)
treeb06cf468f51f3b11fdbfd46fedc0dd1981341155 /test
parent5d043b65d355b8d7ef2696d457a916e607756ee6 (diff)
downloadansible-ed00741a01ed4eb935797afc74cabf6ce0a0e7fa.tar.gz
Mcsalgado's change to use shlex.quote instead of pipes.quote (#18534)
* Replace pipes.quote for shlex_quote * More migration of pipes.quote to shlex_quote Note that we cannot yet move module code over. Modules have six-1.4 bundled which does not have shlex_quote. This shouldn't be a problem as the function is still importable from pipes.quote. It's just that this has become an implementation detail that makes us want to import from shlex instead. Once we get rid of the python2.4 dependency we can update to a newer version of bundled six module-side and then we're free to use shlex_quote everywhere.
Diffstat (limited to 'test')
-rw-r--r--test/units/playbook/test_play_context.py4
-rw-r--r--test/units/plugins/action/test_action.py4
-rw-r--r--test/units/plugins/connection/test_ssh.py18
3 files changed, 13 insertions, 13 deletions
diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py
index a6b2094ed0..adbd54f2bb 100644
--- a/test/units/playbook/test_play_context.py
+++ b/test/units/playbook/test_play_context.py
@@ -20,12 +20,12 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
-import pipes
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, MagicMock
from ansible import constants as C
+from ansible.compat.six.moves import shlex_quote
from ansible.cli import CLI
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.playbook.play_context import PlayContext
@@ -181,7 +181,7 @@ class TestPlayContext(unittest.TestCase):
play_context.become_pass = 'testpass'
play_context.become_method = 'dzdo'
cmd = play_context.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
- self.assertEqual(cmd, """%s -p %s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, pipes.quote(play_context.prompt), play_context.become_user, default_exe, play_context.success_key, default_cmd))
+ self.assertEqual(cmd, """%s -p %s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, shlex_quote(play_context.prompt), play_context.become_user, default_exe, play_context.success_key, default_cmd))
class TestTaskAndVariableOverrride(unittest.TestCase):
diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py
index 52083257a7..1542a2d0fc 100644
--- a/test/units/plugins/action/test_action.py
+++ b/test/units/plugins/action/test_action.py
@@ -20,7 +20,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import pipes
import os
try:
@@ -32,6 +31,7 @@ from nose.tools import eq_, raises
from ansible import constants as C
from ansible.compat.six import text_type
+from ansible.compat.six.moves import shlex_quote
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, MagicMock, mock_open
@@ -164,7 +164,7 @@ class TestActionBase(unittest.TestCase):
# create a mock connection, so we don't actually try and connect to things
def env_prefix(**args):
- return ' '.join(['%s=%s' % (k, pipes.quote(text_type(v))) for k,v in args.items()])
+ return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k,v in args.items()])
mock_connection = MagicMock()
mock_connection._shell.env_prefix.side_effect = env_prefix
diff --git a/test/units/plugins/connection/test_ssh.py b/test/units/plugins/connection/test_ssh.py
index 04d456f325..73dc0685ef 100644
--- a/test/units/plugins/connection/test_ssh.py
+++ b/test/units/plugins/connection/test_ssh.py
@@ -21,13 +21,13 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import pipes
from io import StringIO
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, MagicMock
from ansible import constants as C
+from ansible.compat.six.moves import shlex_quote
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
from ansible.playbook.play_context import PlayContext
from ansible.plugins.connection import ssh
@@ -311,7 +311,7 @@ class TestConnectionBaseClass(unittest.TestCase):
# Test with C.DEFAULT_SCP_IF_SSH set to smart
# Test when SFTP works
C.DEFAULT_SCP_IF_SSH = 'smart'
- expected_in_data = b' '.join((b'put', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n'
+ expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n'
conn.put_file('/path/to/in/file', '/path/to/dest/file')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)
@@ -331,13 +331,13 @@ class TestConnectionBaseClass(unittest.TestCase):
# test with C.DEFAULT_SCP_IF_SSH disabled
C.DEFAULT_SCP_IF_SSH = False
- expected_in_data = b' '.join((b'put', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n'
+ expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n'
conn.put_file('/path/to/in/file', '/path/to/dest/file')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)
expected_in_data = b' '.join((b'put',
- to_bytes(pipes.quote('/path/to/in/file/with/unicode-fö〩')),
- to_bytes(pipes.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
+ to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')),
+ to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
conn.put_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)
@@ -365,7 +365,7 @@ class TestConnectionBaseClass(unittest.TestCase):
# Test with C.DEFAULT_SCP_IF_SSH set to smart
# Test when SFTP works
C.DEFAULT_SCP_IF_SSH = 'smart'
- expected_in_data = b' '.join((b'get', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n'
+ expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n'
conn.fetch_file('/path/to/in/file', '/path/to/dest/file')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)
@@ -385,13 +385,13 @@ class TestConnectionBaseClass(unittest.TestCase):
# test with C.DEFAULT_SCP_IF_SSH disabled
C.DEFAULT_SCP_IF_SSH = False
- expected_in_data = b' '.join((b'get', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n'
+ expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n'
conn.fetch_file('/path/to/in/file', '/path/to/dest/file')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)
expected_in_data = b' '.join((b'get',
- to_bytes(pipes.quote('/path/to/in/file/with/unicode-fö〩')),
- to_bytes(pipes.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
+ to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')),
+ to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
conn.fetch_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩')
conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False)