mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
partial revert of changes introduced in d5f7a0181b
(#21688)
This commit is contained in:
parent
0d060a185f
commit
e4a2c804be
2 changed files with 7 additions and 3 deletions
|
@ -23,6 +23,7 @@ import socket
|
||||||
import json
|
import json
|
||||||
import signal
|
import signal
|
||||||
import datetime
|
import datetime
|
||||||
|
import traceback
|
||||||
|
|
||||||
from ansible.errors import AnsibleConnectionFailure
|
from ansible.errors import AnsibleConnectionFailure
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
|
@ -69,6 +70,7 @@ class Connection(_Connection):
|
||||||
super(Connection, self)._connect()
|
super(Connection, self)._connect()
|
||||||
|
|
||||||
display.debug('starting network_cli._connect()')
|
display.debug('starting network_cli._connect()')
|
||||||
|
display.vvvv('starting network_cli._connect()')
|
||||||
|
|
||||||
network_os = self._play_context.network_os
|
network_os = self._play_context.network_os
|
||||||
if not network_os:
|
if not network_os:
|
||||||
|
@ -149,7 +151,9 @@ class Connection(_Connection):
|
||||||
if obj.get('sendonly'):
|
if obj.get('sendonly'):
|
||||||
return
|
return
|
||||||
return self.receive(obj)
|
return self.receive(obj)
|
||||||
except (socket.timeout, AttributeError):
|
except (socket.timeout, AttributeError) as exc:
|
||||||
|
#display.debug(traceback.format_exc())
|
||||||
|
display.vvv(traceback.format_exc())
|
||||||
raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip())
|
raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip())
|
||||||
|
|
||||||
def _strip(self, data):
|
def _strip(self, data):
|
||||||
|
@ -219,6 +223,7 @@ class Connection(_Connection):
|
||||||
:returns: a tuple of (return code, stdout, stderr). The return
|
:returns: a tuple of (return code, stdout, stderr). The return
|
||||||
code is an integer and stdout and stderr are strings
|
code is an integer and stdout and stderr are strings
|
||||||
"""
|
"""
|
||||||
|
display.vvv('cmd: %s' % cmd)
|
||||||
try:
|
try:
|
||||||
obj = json.loads(cmd)
|
obj = json.loads(cmd)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
@ -234,7 +239,7 @@ class Connection(_Connection):
|
||||||
return (0, self._history, '')
|
return (0, self._history, '')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self._connected:
|
if self._shell is None:
|
||||||
self.open_shell()
|
self.open_shell()
|
||||||
except AnsibleConnectionFailure as exc:
|
except AnsibleConnectionFailure as exc:
|
||||||
return (1, '', str(exc))
|
return (1, '', str(exc))
|
||||||
|
|
|
@ -138,7 +138,6 @@ class TestConnectionClass(unittest.TestCase):
|
||||||
conn._shell = MagicMock()
|
conn._shell = MagicMock()
|
||||||
|
|
||||||
# test _shell already open
|
# test _shell already open
|
||||||
conn._connected = MagicMock(return_value=True)
|
|
||||||
rc, out, err = conn.exec_command('command')
|
rc, out, err = conn.exec_command('command')
|
||||||
self.assertEqual(out, 'command response')
|
self.assertEqual(out, 'command response')
|
||||||
self.assertFalse(mock_open_shell.called)
|
self.assertFalse(mock_open_shell.called)
|
||||||
|
|
Loading…
Reference in a new issue