paramiko_ssh - mark connection as connected when successful (#74459)

* Remove unused import from test
This commit is contained in:
Sam Doran 2021-04-29 15:11:02 -04:00 committed by GitHub
parent 98495ae99d
commit 74b2add460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 11 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- paramiko_ssh - mark connection as connected when ``_connect()`` is called (https://github.com/ansible/ansible/issues/74081)

View file

@ -241,6 +241,8 @@ class Connection(ConnectionBase):
self.ssh = SSH_CONNECTION_CACHE[cache_key]
else:
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
self._connected = True
return self
def _set_log_channel(self, name):

View file

@ -23,20 +23,34 @@ __metaclass__ = type
from io import StringIO
import pytest
from units.compat import unittest
from ansible.plugins.connection import paramiko_ssh
from ansible.playbook.play_context import PlayContext
class TestParamikoConnectionClass(unittest.TestCase):
def test_paramiko_connection_module(self):
@pytest.fixture
def play_context():
play_context = PlayContext()
play_context.prompt = (
'[sudo via ansible, key=ouzmdnewuhucvuaabtjmweasarviygqq] password: '
)
in_stream = StringIO()
self.assertIsInstance(
return play_context
@pytest.fixture()
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