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

Option parsing: warn if both an option and its alias are specified for a module #53698

Merged
merged 5 commits into from
Jul 19, 2019

Conversation

felixfontein
Copy link
Contributor

SUMMARY

Currently, if both an option and its alias are provided in module options, the value of the alias overwrites the value of the option. (If multiple aliases of that option are specified, the last one appearing in the aliases list wins.)

I think there should be a warning if that happens. This PR implements such a warning:

Example:

 - argtest:
      l: 1,2,3
      lalias: 1,2,3,4
      x:
        y: 1
        yy: 2

with argument_spec=dict(l=dict(type='list', elements='int', aliases=['lalias']), x=dict(type='dict', options=dict(y=dict(type='str', aliases=['yy'])))) results in

 [WARNING]: Both option l and its alias lalias are set.
 [WARNING]: Both option x.y and its alias x.yy are set.
ISSUE TYPE
  • Bugfix Pull Request
  • Feature Pull Request
COMPONENT NAME

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

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 12, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 20, 2019
@felixfontein
Copy link
Contributor Author

About the question on IRC on why alias_warnings is carried around: this is because aliases are handled very early on, and calling self.warn() directly will do a call to self.log(), which is potentially bad since self.no_log hasn't been set up yet (see comment in except block):
https://github.com/ansible/ansible/blob/69df7ba6329d3cc60419dade008fcc44c7f4a6b0/lib/ansible/module_utils/basic.py#L764-L771

@bcoca
Copy link
Member

bcoca commented Mar 22, 2019

inject the warnings directly into the 'warnings' list and you don't have to deal with log

@felixfontein
Copy link
Contributor Author

If it's ok that they're not sent to log, sure, that makes it a lot easier :-)

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 22, 2019
@felixfontein felixfontein force-pushed the warn-aliases branch 2 times, most recently from 1c8756e to a42adb9 Compare March 22, 2019 06:48
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. support:community This issue/PR relates to code supported by the Ansible community. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 22, 2019
@felixfontein
Copy link
Contributor Author

The CI failures seem to be totally unrelated to this PR.

ready_for_review

@felixfontein felixfontein force-pushed the warn-aliases branch 2 times, most recently from 7b7bc38 to 5ca5b4f Compare March 26, 2019 20:00
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Mar 26, 2019
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 26, 2019
@felixfontein
Copy link
Contributor Author

ready_for_review

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 3, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 28, 2019
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jun 7, 2019
@felixfontein
Copy link
Contributor Author

Re-triggering CI.

@felixfontein felixfontein reopened this Jul 6, 2019
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 6, 2019
@felixfontein
Copy link
Contributor Author

@bcoca can you take another look? It has been a while... :)

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 14, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jul 18, 2019
@felixfontein
Copy link
Contributor Author

rebuild_merge

@ansibot ansibot added shipit This PR is ready to be merged by Core needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. shipit This PR is ready to be merged by Core labels Jul 18, 2019
@felixfontein
Copy link
Contributor Author

bot_status

@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2019

Components

changelogs/fragments/53698-alias-collision-warning.yaml
support: community
maintainers:

lib/ansible/module_utils/basic.py
support: core
maintainers:

lib/ansible/module_utils/common/parameters.py
support: core
maintainers:

test/units/module_utils/basic/test_argument_spec.py
support: core
maintainers:

Metadata

waiting_on: felixfontein
changes_requested_by: null
needs_info: False
needs_revision: True
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: unstable
shippable_status: pending
maintainer_shipits (module maintainers): False
community_shipits (namespace maintainers): False
ansible_shipits (core team members): False
shipit_actors (maintainer or core team member): None
shipit_actors_other:
automerge: automerge shipit test failed

click here for bot help

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jul 19, 2019
@ansibot ansibot merged commit 4a574c4 into ansible:devel Jul 19, 2019
@felixfontein felixfontein deleted the warn-aliases branch July 19, 2019 18:58
@felixfontein
Copy link
Contributor Author

@bcoca and everyone on IRC who helped with this: thanks for reviewing!

@ansible ansible locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants