From b07a78b4ba1a43465f7987420c79c240c97a67ae Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 8 Apr 2021 15:11:06 -0400 Subject: [PATCH] remove deprecated connection password functions (#74155) * they were moved from connecitons to become plugins * fixed clog, removed sanity ignore * fixed tests to use become functions --- .../remove_connection_become_checks.yml | 2 ++ lib/ansible/plugins/connection/__init__.py | 33 ------------------- test/sanity/ignore.txt | 1 - .../plugins/connection/test_connection.py | 14 ++++---- test/units/plugins/connection/test_ssh.py | 19 ++++++----- 5 files changed, 19 insertions(+), 50 deletions(-) create mode 100644 changelogs/fragments/remove_connection_become_checks.yml diff --git a/changelogs/fragments/remove_connection_become_checks.yml b/changelogs/fragments/remove_connection_become_checks.yml new file mode 100644 index 00000000000..19729f11780 --- /dev/null +++ b/changelogs/fragments/remove_connection_become_checks.yml @@ -0,0 +1,2 @@ +removed_features: + - connections, removed password check stubs that had been moved to become plugins. diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index b172c4cedd2..65260ab5bd5 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -229,39 +229,6 @@ class ConnectionBase(AnsiblePlugin): def reset(self): display.warning("Reset is not implemented for this connection") - # NOTE: these password functions are all become specific, the name is - # confusing as it does not handle 'protocol passwords' - # DEPRECATED: - # These are kept for backwards compatibility - # Use the methods provided by the become plugins instead - def check_become_success(self, b_output): - display.deprecated( - "Connection.check_become_success is deprecated, calling code should be using become plugins instead", - version="2.12", collection_name='ansible.builtin' - ) - return self.become.check_success(b_output) - - def check_password_prompt(self, b_output): - display.deprecated( - "Connection.check_password_prompt is deprecated, calling code should be using become plugins instead", - version="2.12", collection_name='ansible.builtin' - ) - return self.become.check_password_prompt(b_output) - - def check_incorrect_password(self, b_output): - display.deprecated( - "Connection.check_incorrect_password is deprecated, calling code should be using become plugins instead", - version="2.12", collection_name='ansible.builtin' - ) - return self.become.check_incorrect_password(b_output) - - def check_missing_password(self, b_output): - display.deprecated( - "Connection.check_missing_password is deprecated, calling code should be using become plugins instead", - version="2.12", collection_name='ansible.builtin' - ) - return self.become.check_missing_password(b_output) - class NetworkConnectionBase(ConnectionBase): """ diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index fb3746d09c2..cb8a94b0a38 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -155,7 +155,6 @@ lib/ansible/plugins/action/async_status.py pylint:ansible-deprecated-version lib/ansible/plugins/action/normal.py action-plugin-docs # default action plugin for modules without a dedicated action plugin lib/ansible/plugins/cache/__init__.py pylint:ansible-deprecated-version lib/ansible/plugins/cache/base.py ansible-doc!skip # not a plugin, but a stub for backwards compatibility -lib/ansible/plugins/connection/__init__.py pylint:ansible-deprecated-version lib/ansible/plugins/inventory/__init__.py pylint:ansible-deprecated-version lib/ansible/plugins/inventory/script.py pylint:ansible-deprecated-version lib/ansible/plugins/lookup/sequence.py pylint:blacklisted-name diff --git a/test/units/plugins/connection/test_connection.py b/test/units/plugins/connection/test_connection.py index 17c2e0850d9..0f484e6280a 100644 --- a/test/units/plugins/connection/test_connection.py +++ b/test/units/plugins/connection/test_connection.py @@ -160,10 +160,10 @@ debug1: Sending command: /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=ouzm c.set_become_plugin(become_loader.get('sudo')) c.become.prompt = '[sudo via ansible, key=ouzmdnewuhucvuaabtjmweasarviygqq] password: ' - self.assertTrue(c.check_password_prompt(local)) - self.assertTrue(c.check_password_prompt(ssh_pipelining_vvvv)) - self.assertTrue(c.check_password_prompt(ssh_nopipelining_vvvv)) - self.assertTrue(c.check_password_prompt(ssh_novvvv)) - self.assertTrue(c.check_password_prompt(dns_issue)) - self.assertFalse(c.check_password_prompt(nothing)) - self.assertFalse(c.check_password_prompt(in_front)) + self.assertTrue(c.become.check_password_prompt(local)) + self.assertTrue(c.become.check_password_prompt(ssh_pipelining_vvvv)) + self.assertTrue(c.become.check_password_prompt(ssh_nopipelining_vvvv)) + self.assertTrue(c.become.check_password_prompt(ssh_novvvv)) + self.assertTrue(c.become.check_password_prompt(dns_issue)) + self.assertFalse(c.become.check_password_prompt(nothing)) + self.assertFalse(c.become.check_password_prompt(in_front)) diff --git a/test/units/plugins/connection/test_ssh.py b/test/units/plugins/connection/test_ssh.py index 631bf143a30..74f5157d710 100644 --- a/test/units/plugins/connection/test_ssh.py +++ b/test/units/plugins/connection/test_ssh.py @@ -104,10 +104,10 @@ class TestConnectionBaseClass(unittest.TestCase): conn = connection_loader.get('ssh', pc, new_stdin) conn.set_become_plugin(become_loader.get('sudo')) - conn.check_password_prompt = MagicMock() - conn.check_become_success = MagicMock() - conn.check_incorrect_password = MagicMock() - conn.check_missing_password = MagicMock() + conn.become.check_password_prompt = MagicMock() + conn.become.check_success = MagicMock() + conn.become.check_incorrect_password = MagicMock() + conn.become.check_missing_password = MagicMock() def _check_password_prompt(line): if b'foo' in line: @@ -129,11 +129,6 @@ class TestConnectionBaseClass(unittest.TestCase): return True return False - conn.become.check_password_prompt = MagicMock(side_effect=_check_password_prompt) - conn.become.check_become_success = MagicMock(side_effect=_check_become_success) - conn.become.check_incorrect_password = MagicMock(side_effect=_check_incorrect_password) - conn.become.check_missing_password = MagicMock(side_effect=_check_missing_password) - # test examining output for prompt conn._flags = dict( become_prompt=False, @@ -143,7 +138,13 @@ class TestConnectionBaseClass(unittest.TestCase): ) pc.prompt = True + + # override become plugin conn.become.prompt = True + conn.become.check_password_prompt = MagicMock(side_effect=_check_password_prompt) + conn.become.check_success = MagicMock(side_effect=_check_become_success) + conn.become.check_incorrect_password = MagicMock(side_effect=_check_incorrect_password) + conn.become.check_missing_password = MagicMock(side_effect=_check_missing_password) def get_option(option): if option == 'become_pass':