|
|
@ -27,7 +27,7 @@ from ansible.errors import AnsibleAuthenticationFailure
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
from unittest.mock import patch, MagicMock, PropertyMock
|
|
|
|
from unittest.mock import patch, MagicMock, PropertyMock
|
|
|
|
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
|
|
|
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
|
|
|
from ansible.module_utils.six.moves import shlex_quote
|
|
|
|
import shlex
|
|
|
|
from ansible.module_utils.common.text.converters import to_bytes
|
|
|
|
from ansible.module_utils.common.text.converters import to_bytes
|
|
|
|
from ansible.playbook.play_context import PlayContext
|
|
|
|
from ansible.playbook.play_context import PlayContext
|
|
|
|
from ansible.plugins.connection import ssh
|
|
|
|
from ansible.plugins.connection import ssh
|
|
|
@ -246,7 +246,7 @@ class TestConnectionBaseClass(unittest.TestCase):
|
|
|
|
# Test with SCP_IF_SSH set to smart
|
|
|
|
# Test with SCP_IF_SSH set to smart
|
|
|
|
# Test when SFTP works
|
|
|
|
# Test when SFTP works
|
|
|
|
conn.set_option('scp_if_ssh', 'smart')
|
|
|
|
conn.set_option('scp_if_ssh', 'smart')
|
|
|
|
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'
|
|
|
|
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.put_file('/path/to/in/file', '/path/to/dest/file')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
|
|
|
|
|
|
|
@ -266,13 +266,13 @@ class TestConnectionBaseClass(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
# test with SCPP_IF_SSH disabled
|
|
|
|
# test with SCPP_IF_SSH disabled
|
|
|
|
conn.set_option('scp_if_ssh', False)
|
|
|
|
conn.set_option('scp_if_ssh', False)
|
|
|
|
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'
|
|
|
|
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.put_file('/path/to/in/file', '/path/to/dest/file')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
|
|
|
|
|
|
|
|
expected_in_data = b' '.join((b'put',
|
|
|
|
expected_in_data = b' '.join((b'put',
|
|
|
|
to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')),
|
|
|
|
to_bytes(shlex.quote('/path/to/in/file/with/unicode-fö〩')),
|
|
|
|
to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
|
|
|
|
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.put_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
|
|
|
|
|
|
|
@ -304,7 +304,7 @@ class TestConnectionBaseClass(unittest.TestCase):
|
|
|
|
# Test with SCP_IF_SSH set to smart
|
|
|
|
# Test with SCP_IF_SSH set to smart
|
|
|
|
# Test when SFTP works
|
|
|
|
# Test when SFTP works
|
|
|
|
conn.set_option('scp_if_ssh', 'smart')
|
|
|
|
conn.set_option('scp_if_ssh', 'smart')
|
|
|
|
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'
|
|
|
|
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.set_options({})
|
|
|
|
conn.set_options({})
|
|
|
|
conn.fetch_file('/path/to/in/file', '/path/to/dest/file')
|
|
|
|
conn.fetch_file('/path/to/in/file', '/path/to/dest/file')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
@ -326,13 +326,13 @@ class TestConnectionBaseClass(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
# test with SCP_IF_SSH disabled
|
|
|
|
# test with SCP_IF_SSH disabled
|
|
|
|
conn.set_option('scp_if_ssh', False)
|
|
|
|
conn.set_option('scp_if_ssh', False)
|
|
|
|
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'
|
|
|
|
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.fetch_file('/path/to/in/file', '/path/to/dest/file')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
|
|
|
|
|
|
|
|
expected_in_data = b' '.join((b'get',
|
|
|
|
expected_in_data = b' '.join((b'get',
|
|
|
|
to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')),
|
|
|
|
to_bytes(shlex.quote('/path/to/in/file/with/unicode-fö〩')),
|
|
|
|
to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n'
|
|
|
|
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.fetch_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩')
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False)
|
|
|
|
|
|
|
|
|
|
|
|