From 3550f342e0b755832cf8d616e4700a92c40b85cd Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Thu, 30 Aug 2018 17:14:39 -0400 Subject: [PATCH] Gcp auth deprecation (#44866) --- lib/ansible/module_utils/gcp.py | 13 ++++--------- test/units/module_utils/gcp/test_auth.py | 12 ++++++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/ansible/module_utils/gcp.py b/lib/ansible/module_utils/gcp.py index 26176db2d6..8629a17494 100644 --- a/lib/ansible/module_utils/gcp.py +++ b/lib/ansible/module_utils/gcp.py @@ -237,7 +237,7 @@ def _validate_credentials_file(module, credentials_file, require_valid_json=True :param credentials_file: path to file on disk :type credentials_file: ``str``. Complete path to file on disk. - :param require_valid_json: If true, require credentials to be valid JSON. Default is True. + :param require_valid_json: This argument is ignored as of Ansible 2.7. :type require_valid_json: ``bool`` :params check_libcloud: If true, check the libcloud version available to see if @@ -263,14 +263,9 @@ def _validate_credentials_file(module, credentials_file, require_valid_json=True credentials_file, changed=False) return False except ValueError as e: - if require_valid_json: - module.fail_json( - msg='GCP Credentials File %s invalid. Must be valid JSON.' % credentials_file, changed=False) - else: - module.deprecate(msg=("Non-JSON credentials file provided. This format is deprecated. " - " Please generate a new JSON key from the Google Cloud console"), - version=2.5) - return True + module.fail_json( + msg='Non-JSON credentials file provided. Please generate a new JSON key from the Google Cloud console', + changed=False) def gcp_connect(module, provider, get_driver, user_agent_product, user_agent_version): diff --git a/test/units/module_utils/gcp/test_auth.py b/test/units/module_utils/gcp/test_auth.py index 8cd63d84d7..0148be734a 100644 --- a/test/units/module_utils/gcp/test_auth.py +++ b/test/units/module_utils/gcp/test_auth.py @@ -151,16 +151,16 @@ class GCPAuthTestCase(unittest.TestCase): def test_validate_credentials_file(self): # TODO(supertom): Only dealing with p12 here, check the other states # of this function - module = mock.MagicMock() + module = FakeModule() with mock.patch("ansible.module_utils.gcp.open", mock.mock_open(read_data='foobar'), create=True) as m: # pem condition, warning is suppressed with the return_value credentials_file = '/foopath/pem.pem' - is_valid = _validate_credentials_file(module, - credentials_file=credentials_file, - require_valid_json=False, - check_libcloud=False) - self.assertTrue(is_valid) + with self.assertRaises(ValueError): + _validate_credentials_file(module, + credentials_file=credentials_file, + require_valid_json=False, + check_libcloud=False) @mock.patch('ansible.module_utils.gcp._get_gcp_environ_var', side_effect=fake_get_gcp_environ_var)