|
|
|
@ -6,10 +6,12 @@
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.executor.interpreter_discovery import discover_interpreter
|
|
|
|
from ansible.executor.interpreter_discovery import discover_interpreter
|
|
|
|
from ansible.module_utils.common.text.converters import to_text
|
|
|
|
from ansible.module_utils.common.text.converters import to_text
|
|
|
|
|
|
|
|
from ansible.errors import AnsibleConnectionFailure
|
|
|
|
|
|
|
|
|
|
|
|
mock_ubuntu_platform_res = to_text(
|
|
|
|
mock_ubuntu_platform_res = to_text(
|
|
|
|
r'{"osrelease_content": "NAME=\"Ubuntu\"\nVERSION=\"16.04.5 LTS (Xenial Xerus)\"\nID=ubuntu\nID_LIKE=debian\n'
|
|
|
|
r'{"osrelease_content": "NAME=\"Ubuntu\"\nVERSION=\"16.04.5 LTS (Xenial Xerus)\"\nID=ubuntu\nID_LIKE=debian\n'
|
|
|
|
@ -84,3 +86,13 @@ def test_no_interpreters_found():
|
|
|
|
assert mock_action.method_calls[1][0] == '_discovery_warnings.append'
|
|
|
|
assert mock_action.method_calls[1][0] == '_discovery_warnings.append'
|
|
|
|
assert u'No python interpreters found for host host-fóöbär (tried' \
|
|
|
|
assert u'No python interpreters found for host host-fóöbär (tried' \
|
|
|
|
in mock_action.method_calls[1][1][0]
|
|
|
|
in mock_action.method_calls[1][1][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ansible_error_exception():
|
|
|
|
|
|
|
|
mock_action = MagicMock()
|
|
|
|
|
|
|
|
mock_action._low_level_execute_command.side_effect = AnsibleConnectionFailure("host key mismatch")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(AnsibleConnectionFailure) as context:
|
|
|
|
|
|
|
|
discover_interpreter(mock_action, 'python', 'auto_legacy', {'inventory_hostname': u'host'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert 'host key mismatch' == str(context.value)
|
|
|
|
|