-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Conversation
The test
|
268da46
to
c77abe7
Compare
ready_for_review |
c77abe7
to
6328c43
Compare
6328c43
to
0455e2b
Compare
@sean797 The tests are failing with a message about merging... Could you rebase this? |
There was a problem hiding this 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: |
There was a problem hiding this comment.
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
ansible/lib/ansible/executor/task_queue_manager.py
Lines 151 to 159 in 17c89d1
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)?
3e5efae
to
f76729d
Compare
6fe770d
to
4522a5e
Compare
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? |
There was a problem hiding this 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.
test/integration/targets/handlers/roles/test_handlers_meta/handlers/main.yml
Show resolved
Hide resolved
test/integration/targets/handlers/roles/test_handlers_meta/tasks/main.yml
Show resolved
Hide resolved
4522a5e
to
59e1ea6
Compare
59e1ea6
to
c9d5c79
Compare
Added some more tests, thanks again @cognifloyd 👍 |
There was a problem hiding this 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
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This was discussed in the IRC meeting on 2018-11-15 and the vote was to not include this feature. It adds complexity to |
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
COMPONENT NAME
meta
ANSIBLE VERSION