Skip to content

Commit

Permalink
Allow to declare some versions as unsupported, and to provide an expl…
Browse files Browse the repository at this point in the history
…icit message.
  • Loading branch information
felixfontein committed Dec 5, 2023
1 parent eda8f64 commit 7cd6f42
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
22 changes: 15 additions & 7 deletions plugins/module_utils/_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,31 @@ def __init__(self,
break
self._current = None if self.needs_version else self.unversioned

def _select(self, data, api_version):
if data is None:
self._current = None
return False, None

Check warning on line 55 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L54-L55

Added lines #L54 - L55 were not covered by tests
if isinstance(data, str):
self._current = None
return False, data
self._current = data.specialize_for_version(api_version)
return self._current.fully_understood, None

Check warning on line 60 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L57-L60

Added lines #L57 - L60 were not covered by tests

def provide_version(self, version):
if not self.needs_version:
return self.unversioned.fully_understood
return self.unversioned.fully_understood, None
api_version = LooseVersion(version)
if self.unversioned is not None:
self._current = self.unversioned.specialize_for_version(api_version)
return self._current.fully_understood
return self._current.fully_understood, None
for other_version, comparator, data in self.versioned:
if other_version == '*' and comparator == '*':
self._current = data.specialize_for_version(api_version)
return self._current.fully_understood
return self._select(data, api_version)

Check warning on line 71 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L71

Added line #L71 was not covered by tests
other_api_version = LooseVersion(other_version)
if _compare(api_version, other_api_version, comparator):
self._current = data.specialize_for_version(api_version)
return self._current.fully_understood
return self._select(data, api_version)

Check warning on line 74 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L74

Added line #L74 was not covered by tests
self._current = None
return False
return False, None

Check warning on line 76 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L76

Added line #L76 was not covered by tests

def get_data(self):
if self._current is None:
Expand Down
8 changes: 6 additions & 2 deletions plugins/modules/api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,12 @@ def main():
module.fail_json(msg='Path /{path} is not yet supported'.format(path='/'.join(path)))
if versioned_path_info.needs_version:
api_version = get_api_version(api)
if not versioned_path_info.provide_version(api_version):
module.fail_json(msg='Path /{path} is not supported for API version {api_version}'.format(path='/'.join(path), api_version=api_version))
supported, not_supported_msg = versioned_path_info.provide_version(api_version)
if not supported:
msg = 'Path /{path} is not supported for API version {api_version}'.format(path='/'.join(path), api_version=api_version)

Check warning on line 355 in plugins/modules/api_info.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/api_info.py#L355

Added line #L355 was not covered by tests
if not_supported_msg:
msg = '{0}: {1}'.format(msg, not_supported_msg)
module.fail_json(msg=msg)

Check warning on line 358 in plugins/modules/api_info.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/api_info.py#L357-L358

Added lines #L357 - L358 were not covered by tests
path_info = versioned_path_info.get_data()

handle_disabled = module.params['handle_disabled']
Expand Down
8 changes: 6 additions & 2 deletions plugins/modules/api_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,8 +1133,12 @@ def main():
versioned_path_info = PATHS.get(tuple(path))
if versioned_path_info.needs_version:
api_version = get_api_version(api)
if not versioned_path_info.provide_version(api_version):
module.fail_json(msg='Path /{path} is not supported for API version {api_version}'.format(path='/'.join(path), api_version=api_version))
supported, not_supported_msg = versioned_path_info.provide_version(api_version)
if not supported:
msg = 'Path /{path} is not supported for API version {api_version}'.format(path='/'.join(path), api_version=api_version)

Check warning on line 1138 in plugins/modules/api_modify.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/api_modify.py#L1138

Added line #L1138 was not covered by tests
if not_supported_msg:
msg = '{0}: {1}'.format(msg, not_supported_msg)
module.fail_json(msg=msg)

Check warning on line 1141 in plugins/modules/api_modify.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/api_modify.py#L1140-L1141

Added lines #L1140 - L1141 were not covered by tests
path_info = versioned_path_info.get_data()

backend = get_backend(path_info)
Expand Down

0 comments on commit 7cd6f42

Please sign in to comment.