-
Notifications
You must be signed in to change notification settings - Fork 44
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
Resolve meraki webhook fail when none defined #436
Resolve meraki webhook fail when none defined #436
Conversation
… with however many items are in the list
Hello! The all tests passed in my dev env. Please add the Example file of -- |
@y0rune - added, i think, so please review.
|
plugins/modules/meraki_webhook.py
Outdated
"shared_secret" | ||
] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" | ||
i = 0 | ||
while i < len(meraki.result["data"]): |
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.
Why a while loop instead of a for loop here?
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.
Ah. Your comment has made me re-look at this. There is still an issue here so it's not ready for merge.
So that is where i started - I've just tried this again to check - and I think i've been miss-interpreted an error i saw..
with ...
for i in meraki.result['data']:
i[
"shared_secret"
] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
... I get the "Query one webhook" test failing with TypeError: 'str' object does not support item assignment
. I took that to be an issue with the indirect assignment afforded by the for loop variable and so used a while loop instead with direct assignment.
I've miss-understood the meraki.result behaviour - assuming data is always a list - be it empty or with multiple entries. With a query naming a web hook, I'm guessing now data is a dict, not a single entry list pointing to a dict.
I'll look at this again.
I've re-pushed this - ready for re-review. |
@@ -17,6 +17,22 @@ | |||
net_name: '{{test_net_name}}' | |||
type: appliance | |||
|
|||
- name: Query for any webhooks expecting None |
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.
Overall this looks good but should there be a new test looking for the shared_secret
value?
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.
We can certainly use the opportunity to call out the expected behaviour via the test cases yes. that's probably just the de-commenting of the idempotency tests and tightening the assert statements.
(.venv) vagrant@terra01:~/ansible_collections/cisco/meraki$ grep "\- name" tests/integration/targets/meraki_webhook/tasks/tests.yml
- name: Test an API key is provided
- name: Create test network
- name: Query for any webhooks expecting None
- name: Create webhook with check mode
- name: Create webhook
- name: Query all webhooks expecting 1
- name: Query one webhook
- name: Query one webhook with id
- name: Update webhook with check mode
# - name: Update webhook
# - name: Update webhook with idempotency
# - name: Update webhook with id
- name: Create webhook payload template for a webhook
- name: Debug payload_template
- name: Create webhook with a payload template
- name: Delete webhook with payload template
- name: Create test webhook
- name: Get webhook status
- name: Query all webhooks
- name: Delete webhook invalid webhook
- name: Delete webhook in check mode
- name: Delete webhook
- name: Delete webhook payload template for a webhook
- name: Delete test network
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 added a test to my local branch testing that a seemingly idempotent change is always going to return "changed" and no shared_secret. passed.
-
I then added a test that did a change without shared_secret set - expecting changed='false' - and that's picked up another issue.
API behaviour - if the shared secret is not set in the request, then the API will still return 200 OK - it does not touch the secret - only updating any changed params. (verified through GUI/Postman)
module behaviour - if the shared secret param is not set, the module will set shared secret to null, and send that - API will return 400 Error. To my mind, it should not be setting the param at all.
I can see how to resolve that - any issues with me adding that to the PR?
Lets merge this one and add the other fixes in a new PR. |
Resolves issue #433
Original Issue report concerned meraki_webhook failing when a query returns a list with no entries.
PR adds test coverage for the observed issue, and makes
sanitize_no_log_values
work with lists of any length.sanity and integration tests passed.