diff --git a/awx_collection/plugins/module_utils/tower_api.py b/awx_collection/plugins/module_utils/tower_api.py index de81b6a662..02122b6c25 100644 --- a/awx_collection/plugins/module_utils/tower_api.py +++ b/awx_collection/plugins/module_utils/tower_api.py @@ -7,7 +7,7 @@ from ansible.module_utils.urls import Request, SSLValidationError, ConnectionErr from ansible.module_utils.six import PY2 from ansible.module_utils.six.moves.urllib.error import HTTPError from ansible.module_utils.six.moves.http_cookiejar import CookieJar -import semver +from distutils.version import LooseVersion as Version import time from json import loads, dumps @@ -260,17 +260,13 @@ class TowerAPIModule(TowerModule): tower_type = response.info().getheader('X-API-Product-Name', None) tower_version = response.info().getheader('X-API-Product-Version', None) - semver_collection_version = semver.VersionInfo.parse(self._COLLECTION_VERSION) - semver_tower_version = semver.VersionInfo.parse(tower_version) + collection_major = Version(self._COLLECTION_VERSION).version[0] + tower_major = Version(tower_version).version[0] 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 semver_collection_version.major != semver_tower_version.major: - self.warn("You are running collection version {0} but connecting to tower version {1}".format( - self._COLLECTION_VERSION, tower_version - )) + self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, tower_type)) + elif collection_major != tower_major: + self.warn("You are running collection version {0} but connecting to tower version {1}".format(self._COLLECTION_VERSION, tower_version)) self.version_checked = True response_body = '' diff --git a/awx_collection/test/awx/test_module_utils.py b/awx_collection/test/awx/test_module_utils.py index 473bfe9457..61a3b6d4bd 100644 --- a/awx_collection/test/awx/test_module_utils.py +++ b/awx_collection/test/awx/test_module_utils.py @@ -32,6 +32,20 @@ def mock_ping_response(self, method, url, **kwargs): def test_version_warning(collection_import, silence_warning): + TowerAPIModule = collection_import('plugins.module_utils.tower_api').TowerAPIModule + cli_data = {'ANSIBLE_MODULE_ARGS': {}} + testargs = ['module_file2.py', json.dumps(cli_data)] + with mock.patch.object(sys, 'argv', testargs): + with mock.patch('ansible.module_utils.urls.Request.open', new=mock_ping_response): + my_module = TowerAPIModule(argument_spec=dict()) + my_module._COLLECTION_VERSION = "2.0.0" + my_module._COLLECTION_TYPE = "not-junk" + my_module.collection_to_version['not-junk'] = 'not-junk' + my_module.get_endpoint('ping') + silence_warning.assert_called_once_with('You are running collection version 2.0.0 but connecting to tower version 1.2.3') + + +def test_version_warning_strictness(collection_import, silence_warning): TowerAPIModule = collection_import('plugins.module_utils.tower_api').TowerAPIModule cli_data = {'ANSIBLE_MODULE_ARGS': {}} testargs = ['module_file2.py', json.dumps(cli_data)] @@ -42,7 +56,7 @@ def test_version_warning(collection_import, silence_warning): my_module._COLLECTION_TYPE = "not-junk" my_module.collection_to_version['not-junk'] = 'not-junk' my_module.get_endpoint('ping') - silence_warning.assert_called_once_with('You are running collection version 1.0.0 but connecting to tower version 1.2.3') + silence_warning.assert_not_called() def test_type_warning(collection_import, silence_warning): diff --git a/requirements/requirements.in b/requirements/requirements.in index 4f22262c86..1970b215fb 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -43,7 +43,6 @@ python3-saml python-ldap>=3.3.1 # https://github.com/python-ldap/python-ldap/issues/270 pyyaml>=5.4.1 # minimum to fix https://github.com/yaml/pyyaml/issues/478 schedule==0.6.0 -semver==2.13.0 social-auth-core==3.3.1 # see UPGRADE BLOCKERs social-auth-app-django==3.1.0 # see UPGRADE BLOCKERs redis