Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mechanism for warnings outside of AnsibleModule #58993

Open
wants to merge 9 commits into
base: devel
from

Conversation

Projects
None yet
4 participants
@samdoran
Copy link
Member

commented Jul 11, 2019

SUMMARY

Create a mechanism for storing warnings in a global place, outside of an AnsibleModule object.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

lib/ansible/module_utils/basic.py
lib/ansible/module_utils/common/warnings.py

global_warnings = []


class AnsibleWarning(Warning):

This comment has been minimized.

Copy link
@bcoca

bcoca Jul 12, 2019

Member

we also have a 'debug' facility that works the same, should we just add it to this PR?

This comment has been minimized.

Copy link
@samdoran

samdoran Jul 12, 2019

Author Member

Might not be a bad idea. I'm not familiar with that mechanism.

This comment has been minimized.

Copy link
@samdoran

samdoran Jul 15, 2019

Author Member

After working through this more, I don't think moving debug out would make sense with this change. That is more a flag rather than a container for holding values. We could handle that in other PR maybe, but it seems out of context for this change.

This comment has been minimized.

Copy link
@bcoca

bcoca Jul 15, 2019

Member

current debug just pushes to local syslog, but with this functioning the same as 'warnings' and return accumulated messages back to controller

@ansibot

This comment was marked as resolved.

Copy link
Contributor

commented Jul 12, 2019

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/module_utils/common/warnings.py:24:42: bad-whitespace Exactly one space required after comma         global_warnings.append({'msg': msg,'version':version})                                           ^

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

lib/ansible/module_utils/common/warnings.py:24:43: E231 missing whitespace after ','
lib/ansible/module_utils/common/warnings.py:24:53: E231 missing whitespace after ':'

click here for bot help

samdoran added some commits Jul 12, 2019

@samdoran samdoran changed the title [WIP] Add mechanism for warnings outside of AnsibleModule Add mechanism for warnings outside of AnsibleModule Jul 15, 2019

@samdoran samdoran changed the title Add mechanism for warnings outside of AnsibleModule [WIP] Add mechanism for warnings outside of AnsibleModule Jul 15, 2019

@samdoran samdoran changed the title [WIP] Add mechanism for warnings outside of AnsibleModule Add mechanism for warnings outside of AnsibleModule Jul 15, 2019

@ansibot ansibot added core_review and removed WIP labels Jul 15, 2019

@@ -2018,8 +2013,8 @@ def _return_formatted(self, kwargs):
else:
self.warn(kwargs['warnings'])

if self._warnings:
kwargs['warnings'] = self._warnings
if warnings._global_warnings:

This comment has been minimized.

Copy link
@bcoca

bcoca Jul 16, 2019

Member

if you are externally accessing it, it should not be a private var, or you might want to consider a read only method instead

This comment has been minimized.

Copy link
@samdoran

samdoran Jul 16, 2019

Author Member

That may not be a bad idea. Ideally updating these values could only be done via warn() and deprecate().

@ansibot ansibot added needs_revision and removed core_review labels Jul 16, 2019

@bcoca bcoca removed the needs_triage label Jul 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.