From 75a99bb1d50d30e39e107883822d7a4996b623c1 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Thu, 25 Mar 2021 09:33:46 -0400 Subject: [PATCH] Fixing version check --- awx_collection/plugins/module_utils/tower_api.py | 3 +-- awx_collection/test/awx/test_module_utils.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/awx_collection/plugins/module_utils/tower_api.py b/awx_collection/plugins/module_utils/tower_api.py index 4fcdecfde1..2edba2b502 100644 --- a/awx_collection/plugins/module_utils/tower_api.py +++ b/awx_collection/plugins/module_utils/tower_api.py @@ -262,14 +262,13 @@ class TowerAPIModule(TowerModule): parsed_collection_version = Version(self._COLLECTION_VERSION).version parsed_tower_version = Version(tower_version).version - if tower_type != 'AWX': + if tower_type == 'AWX': collection_compare_ver = parsed_collection_version[0] tower_compare_ver = parsed_tower_version[0] else: collection_compare_ver = "{}.{}".format(parsed_collection_version[0], parsed_collection_version[1]) tower_compare_ver = '{}.{}'.format(parsed_tower_version[0], parsed_tower_version[1]) - if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != tower_type: self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, tower_type)) elif collection_compare_ver != tower_compare_ver: diff --git a/awx_collection/test/awx/test_module_utils.py b/awx_collection/test/awx/test_module_utils.py index 2c88e64826..8f2a8e52d5 100644 --- a/awx_collection/test/awx/test_module_utils.py +++ b/awx_collection/test/awx/test_module_utils.py @@ -13,10 +13,12 @@ awx_name = 'AWX' tower_name = 'Red Hat Ansible Tower' ping_version = '1.2.3' + def getTowerheader(self, header_name, default): mock_headers = {'X-API-Product-Name': tower_name, 'X-API-Product-Version': ping_version} return mock_headers.get(header_name, default) + def getAWXheader(self, header_name, default): mock_headers = {'X-API-Product-Name': awx_name, 'X-API-Product-Version': ping_version} return mock_headers.get(header_name, default) @@ -37,6 +39,7 @@ def mock_tower_ping_response(self, method, url, **kwargs): r.status = status.__get__(r) return r + def mock_awx_ping_response(self, method, url, **kwargs): r = Response() r.getheader = getAWXheader.__get__(r) @@ -55,7 +58,9 @@ def test_version_warning(collection_import, silence_warning): my_module._COLLECTION_VERSION = "2.0.0" my_module._COLLECTION_TYPE = "awx" my_module.get_endpoint('ping') - silence_warning.assert_called_once_with('You are running collection version {} but connecting to tower version {}'.format(my_module._COLLECTION_VERSION, ping_version)) + silence_warning.assert_called_once_with( + 'You are running collection version {} but connecting to tower version {}'.format(my_module._COLLECTION_VERSION, ping_version) + ) def test_version_warning_strictness_awx(collection_import, silence_warning): @@ -80,6 +85,7 @@ def test_version_warning_strictness_awx(collection_import, silence_warning): my_module.get_endpoint('ping') silence_warning.assert_not_called() + def test_version_warning_strictness_tower(collection_import, silence_warning): TowerAPIModule = collection_import('plugins.module_utils.tower_api').TowerAPIModule cli_data = {'ANSIBLE_MODULE_ARGS': {}} @@ -100,8 +106,9 @@ def test_version_warning_strictness_tower(collection_import, silence_warning): my_module._COLLECTION_VERSION = "1.0.0" my_module._COLLECTION_TYPE = "tower" my_module.get_endpoint('ping') - silence_warning.assert_called_once_with('You are running collection version {} but connecting to tower version {}'.format(my_module._COLLECTION_VERSION, ping_version)) - + silence_warning.assert_called_once_with( + 'You are running collection version {} but connecting to tower version {}'.format(my_module._COLLECTION_VERSION, ping_version) + ) def test_type_warning(collection_import, silence_warning):