From 594840c1d6004f826586c632f4d29e455a58c8c3 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Fri, 16 Mar 2018 13:28:04 -0400 Subject: [PATCH] Close & remove paramiko connection where appropriate (#37528) * Close & remove paramiko connection where appropriate * Update unit test --- lib/ansible/plugins/connection/network_cli.py | 5 ++++- test/units/plugins/connection/test_network_cli.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 1b3bccc476..b96fb1917c 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -368,8 +368,11 @@ class Connection(ConnectionBase): self._ssh_shell.close() self._ssh_shell = None display.debug("cli session is now closed") + + self.paramiko_conn.close() + self.paramiko_conn = None + display.debug("ssh connection has been closed successfully") self._connected = False - display.debug("ssh connection has been closed successfully") def receive(self, command=None, prompts=None, answer=None, newline=True, prompt_retry_check=False): ''' diff --git a/test/units/plugins/connection/test_network_cli.py b/test/units/plugins/connection/test_network_cli.py index fd8f27a0d0..aae1c3c988 100644 --- a/test/units/plugins/connection/test_network_cli.py +++ b/test/units/plugins/connection/test_network_cli.py @@ -93,11 +93,13 @@ class TestConnectionClass(unittest.TestCase): terminal = MagicMock(supports_multiplexing=False) conn._terminal = terminal conn._ssh_shell = MagicMock() + conn.paramiko_conn = MagicMock() conn._connected = True conn.close() self.assertTrue(terminal.on_close_shell.called) self.assertIsNone(conn._ssh_shell) + self.assertIsNone(conn.paramiko_conn) @patch("ansible.plugins.connection.paramiko_ssh.Connection._connect") def test_network_cli_exec_command(self, mocked_super):