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

Adds optional filter arg to meta for flush_handlers (#25491) #25573

Closed
wants to merge 1 commit into from

Conversation

sean797
Copy link

@sean797 sean797 commented Jun 10, 2017

SUMMARY

Adds optional filter arg to meta. Currently only used for the flush_handlers action but in the future I envision it being used by other actions.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

meta

ANSIBLE VERSION
ansible 2.3.0.0

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 c:plugins/strategy core_review In order to be merged, this PR must follow the core review workflow. feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Jun 10, 2017
@ansibot
Copy link
Contributor

ansibot commented Jun 10, 2017

The test ansible-test sanity --test pep8 failed with the following errors:

lib/ansible/plugins/strategy/__init__.py:718:59: E251 unexpected spaces around keyword / parameter equals
lib/ansible/plugins/strategy/__init__.py:718:61: E251 unexpected spaces around keyword / parameter equals
lib/ansible/plugins/strategy/__init__.py:730:28: E711 comparison to None should be 'if cond is not None:'

click here for bot help

@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 Jun 10, 2017
@sean797 sean797 force-pushed the flush_handlers-filter branch from 268da46 to c77abe7 Compare June 11, 2017 12:36
@sean797
Copy link
Author

sean797 commented Jun 11, 2017

ready_for_review

@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 Jun 12, 2017
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jun 12, 2017
@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. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jun 23, 2017
@sean797 sean797 force-pushed the flush_handlers-filter branch from c77abe7 to 6328c43 Compare August 8, 2017 13:27
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 8, 2017
@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 Aug 17, 2017
@ansibot ansibot added plugins/strategy test This PR relates to tests. labels Sep 2, 2017
@sean797 sean797 force-pushed the flush_handlers-filter branch from 6328c43 to 0455e2b Compare October 4, 2017 11:50
@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 Oct 4, 2017
@cognifloyd
Copy link
Contributor

@sean797 The tests are failing with a message about merging... Could you rebase this?
I would love to see this merged. I'll try to carve out some time next week to test this.

Copy link
Contributor

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to deal with handlers that have an array of listeners. Multiple listeners is something I use quite a bit.

@@ -835,6 +835,12 @@ def run_handlers(self, iterator, play_context):
# but this may take some work in the iterator and gets tricky when
# we consider the ability of meta tasks to flush handlers
for handler in handler_block.block:
if filters is not None:
if handler.listen in self._listening_handlers:
if handler.listen not in filters:
Copy link
Contributor

@cognifloyd cognifloyd Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this covers a handler that is listening to a list of handlers. right?

- name: handler_name
  listen:
    - listen_to_this
    - and_this
  command: echo

if handler.listen:
listeners = handler.listen
if not isinstance(listeners, list):
listeners = [listeners]
for listener in listeners:
if listener not in self._listening_handlers:
self._listening_handlers[listener] = []
display.debug("Adding handler %s to listening list" % handler.name)
self._listening_handlers[listener].append(handler._uuid)

From reading the code, maybe something like:

            for handler in handler_block.block:
                if filters is not None:
                    handler_names = [handler.name]
                    if handler.listen:
                        if isinstance(handler.listen, list):
                            handler_names.extend(handler.listen)
                        else:
                            handler_names.append(handler.listen)
                    if all([name not in filters for name in handler_names]):
                        continue

What was the point of checking if listen is in _listening_handlers before checking if it was in filters (I dropped that)?

@sean797 sean797 force-pushed the flush_handlers-filter branch 2 times, most recently from 3e5efae to f76729d Compare October 23, 2018 09:15
@ansibot ansibot removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Oct 23, 2018
@sean797 sean797 force-pushed the flush_handlers-filter branch 2 times, most recently from 6fe770d to 4522a5e Compare October 23, 2018 17:30
@sean797
Copy link
Author

sean797 commented Oct 24, 2018

Thanks @cognifloyd Sorry for the delay, I've updated and rebased now. To me, it looks like the tests failures and unrelated to this change?

Copy link
Contributor

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test to make sure this covers listening to a list of handlers.

@sean797 sean797 force-pushed the flush_handlers-filter branch from 4522a5e to 59e1ea6 Compare October 25, 2018 09:12
@sean797 sean797 force-pushed the flush_handlers-filter branch from 59e1ea6 to c9d5c79 Compare October 25, 2018 09:14
@sean797
Copy link
Author

sean797 commented Oct 25, 2018

Added some more tests, thanks again @cognifloyd 👍

Copy link
Contributor

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically, this looks great. I look forward to using it in my playbooks! Thanks @sean797

@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 Nov 3, 2018
# since they do not use k=v pairs, so get that
meta_action = task.args.get('_raw_params')
# old style meta tasks store their args in the _raw_params field of args,
# since they never use to use k=v pairs, now its recomended to use name k=v pair
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k=v pairs is never recommended but the comment here isn't (and wasn't) really about k=v so it's probably more clear to drop the k=v mention:

old style meta tasks only had one value, the name of the meta action. This would be stored, unparsed in _raw_params. Meta tasks can now take separate fields for the action and options. If so, the meta_action will be stored in the 'name' dictionary field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rephrase of 'never used options, now it is recommended to always use options' .. which is 'format neutral', covering both k=v and k: v

meta_action = task.args.get('_raw_params')
# old style meta tasks store their args in the _raw_params field of args,
# since they never use to use k=v pairs, now its recomended to use name k=v pair
meta_action = task.args.get('_raw_params') or task.args.get('name')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to deprecate, then we should have additional logic to detect that the action came in via _raw_params rather than name and issue a deprecation warning.

However, we may want to do this via a "long deprecation cycle" which we've talked about the need for but haven't nailed down any rules for yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I would want to deprecate the raw_params method, I think it makes sense to support both, especially considering there are other meta actions that do no use any additional params.

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html 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 Nov 14, 2018
@samdoran
Copy link
Contributor

This was discussed in the IRC meeting on 2018-11-15 and the vote was to not include this feature. It adds complexity to meta in order to allow granular control of which handlers get executed. It is possible to get this same behavior using conditionals, block, include_tasks, or other existing mechanisms without the need to add complexity to meta.

@samdoran samdoran closed this Nov 15, 2018
@sean797 sean797 mentioned this pull request Jun 14, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 c:plugins/strategy feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. plugins/strategy stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. 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. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants