mirror of
https://github.com/ansible/awx.git
synced 2026-05-18 06:47:41 -02:30
Merge pull request #11062 from john-westcott-iv/collection_version_change
Collection version change
This commit is contained in:
@@ -261,22 +261,29 @@ class ControllerAPIModule(ControllerModule):
|
|||||||
controller_version = response.info().getheader('X-API-Product-Version', None)
|
controller_version = response.info().getheader('X-API-Product-Version', None)
|
||||||
|
|
||||||
parsed_collection_version = Version(self._COLLECTION_VERSION).version
|
parsed_collection_version = Version(self._COLLECTION_VERSION).version
|
||||||
parsed_controller_version = Version(controller_version).version
|
if not controller_version:
|
||||||
if controller_type == 'AWX':
|
|
||||||
collection_compare_ver = parsed_collection_version[0]
|
|
||||||
controller_compare_ver = parsed_controller_version[0]
|
|
||||||
else:
|
|
||||||
collection_compare_ver = "{0}.{1}".format(parsed_collection_version[0], parsed_collection_version[1])
|
|
||||||
controller_compare_ver = '{0}.{1}'.format(parsed_controller_version[0], parsed_controller_version[1])
|
|
||||||
|
|
||||||
if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != controller_type:
|
|
||||||
self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, controller_type))
|
|
||||||
elif collection_compare_ver != controller_compare_ver:
|
|
||||||
self.warn(
|
self.warn(
|
||||||
"You are running collection version {0} but connecting to {2} version {1}".format(
|
"You are using the {0} version of this collection but connecting to a controller that did not return a version".format(
|
||||||
self._COLLECTION_VERSION, controller_version, controller_type
|
self._COLLECTION_VERSION
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
parsed_controller_version = Version(controller_version).version
|
||||||
|
if controller_type == 'AWX':
|
||||||
|
collection_compare_ver = parsed_collection_version[0]
|
||||||
|
controller_compare_ver = parsed_controller_version[0]
|
||||||
|
else:
|
||||||
|
collection_compare_ver = "{0}.{1}".format(parsed_collection_version[0], parsed_collection_version[1])
|
||||||
|
controller_compare_ver = '{0}.{1}'.format(parsed_controller_version[0], parsed_controller_version[1])
|
||||||
|
|
||||||
|
if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != controller_type:
|
||||||
|
self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, controller_type))
|
||||||
|
elif collection_compare_ver != controller_compare_ver:
|
||||||
|
self.warn(
|
||||||
|
"You are running collection version {0} but connecting to {2} version {1}".format(
|
||||||
|
self._COLLECTION_VERSION, controller_version, controller_type
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.version_checked = True
|
self.version_checked = True
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ def getAWXheader(self, header_name, default):
|
|||||||
return mock_headers.get(header_name, default)
|
return mock_headers.get(header_name, default)
|
||||||
|
|
||||||
|
|
||||||
|
def getNoheader(self, header_name, default):
|
||||||
|
mock_headers = {}
|
||||||
|
return mock_headers.get(header_name, default)
|
||||||
|
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
return json.dumps({})
|
return json.dumps({})
|
||||||
|
|
||||||
@@ -48,6 +53,14 @@ def mock_awx_ping_response(self, method, url, **kwargs):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def mock_no_ping_response(self, method, url, **kwargs):
|
||||||
|
r = Response()
|
||||||
|
r.getheader = getNoheader.__get__(r)
|
||||||
|
r.read = read.__get__(r)
|
||||||
|
r.status = status.__get__(r)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def test_version_warning(collection_import, silence_warning):
|
def test_version_warning(collection_import, silence_warning):
|
||||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||||
@@ -63,6 +76,21 @@ def test_version_warning(collection_import, silence_warning):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_version_warning(collection_import, silence_warning):
|
||||||
|
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||||
|
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_no_ping_response):
|
||||||
|
my_module = ControllerAPIModule(argument_spec=dict())
|
||||||
|
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 using the {0} version of this collection but connecting to a controller that did not return a version'.format(my_module._COLLECTION_VERSION)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_version_warning_strictness_awx(collection_import, silence_warning):
|
def test_version_warning_strictness_awx(collection_import, silence_warning):
|
||||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||||
|
|||||||
Reference in New Issue
Block a user