paramiko_ssh - mark connection as connected when successful (#74459)
* Remove unused import from test
This commit is contained in:
parent
98495ae99d
commit
74b2add460
3 changed files with 29 additions and 11 deletions
2
changelogs/fragments/74081-paramiko-mark-connected.yml
Normal file
2
changelogs/fragments/74081-paramiko-mark-connected.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- paramiko_ssh - mark connection as connected when ``_connect()`` is called (https://github.com/ansible/ansible/issues/74081)
|
|
@ -241,6 +241,8 @@ class Connection(ConnectionBase):
|
||||||
self.ssh = SSH_CONNECTION_CACHE[cache_key]
|
self.ssh = SSH_CONNECTION_CACHE[cache_key]
|
||||||
else:
|
else:
|
||||||
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
|
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
|
||||||
|
|
||||||
|
self._connected = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _set_log_channel(self, name):
|
def _set_log_channel(self, name):
|
||||||
|
|
|
@ -23,20 +23,34 @@ __metaclass__ = type
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from units.compat import unittest
|
|
||||||
from ansible.plugins.connection import paramiko_ssh
|
from ansible.plugins.connection import paramiko_ssh
|
||||||
from ansible.playbook.play_context import PlayContext
|
from ansible.playbook.play_context import PlayContext
|
||||||
|
|
||||||
|
|
||||||
class TestParamikoConnectionClass(unittest.TestCase):
|
@pytest.fixture
|
||||||
|
def play_context():
|
||||||
|
play_context = PlayContext()
|
||||||
|
play_context.prompt = (
|
||||||
|
'[sudo via ansible, key=ouzmdnewuhucvuaabtjmweasarviygqq] password: '
|
||||||
|
)
|
||||||
|
|
||||||
def test_paramiko_connection_module(self):
|
return play_context
|
||||||
play_context = PlayContext()
|
|
||||||
play_context.prompt = (
|
|
||||||
'[sudo via ansible, key=ouzmdnewuhucvuaabtjmweasarviygqq] password: '
|
|
||||||
)
|
|
||||||
in_stream = StringIO()
|
|
||||||
|
|
||||||
self.assertIsInstance(
|
|
||||||
paramiko_ssh.Connection(play_context, in_stream),
|
@pytest.fixture()
|
||||||
paramiko_ssh.Connection)
|
def in_stream():
|
||||||
|
return StringIO()
|
||||||
|
|
||||||
|
|
||||||
|
def test_paramiko_connection_module(play_context, in_stream):
|
||||||
|
assert isinstance(
|
||||||
|
paramiko_ssh.Connection(play_context, in_stream),
|
||||||
|
paramiko_ssh.Connection)
|
||||||
|
|
||||||
|
|
||||||
|
def test_paramiko_connect(play_context, in_stream, mocker):
|
||||||
|
mocker.patch.object(paramiko_ssh.Connection, '_connect_uncached')
|
||||||
|
connection = paramiko_ssh.Connection(play_context, in_stream)._connect()
|
||||||
|
|
||||||
|
assert isinstance(connection, paramiko_ssh.Connection)
|
||||||
|
assert connection._connected is True
|
||||||
|
|
Loading…
Reference in a new issue