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

Resolve meraki webhook fail when none defined #436

Conversation

mystery-rabbit
Copy link
Contributor

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.

@y0rune
Copy link
Contributor

y0rune commented Jan 27, 2023

Hello!

The all tests passed in my dev env.
The ansible-lint was not passed due to some kind of warnings. I will fix it in the #361.

Please add the changelogs/fragments/xyz.yml as bugfix .

Example file of changelogs/fragments: https://github.com/CiscoDevNet/ansible-meraki/pull/432/files#diff-7c42c7e2a287182c3da289d14dddb44f293da1bf306b0112cd93cebba21835fb

--
Marcin

@mystery-rabbit
Copy link
Contributor Author

@y0rune - added, i think, so please review.

  • for future use - is there any docs/guide to the fragments files? - it's not mentioned in contributing.md.

@kbreit
Copy link
Collaborator

kbreit commented Jan 30, 2023

https://github.com/ansible-community/antsibull-changelog/blob/main/docs/changelogs.rst

"shared_secret"
] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
i = 0
while i < len(meraki.result["data"]):
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@mystery-rabbit
Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kbreit

  • 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?

@kbreit
Copy link
Collaborator

kbreit commented Feb 1, 2023

Lets merge this one and add the other fixes in a new PR.

@kbreit kbreit merged commit 36ad145 into CiscoDevNet:master Feb 1, 2023
@mystery-rabbit mystery-rabbit deleted the Resolve_meraki_webhook_fail_when_none_defined branch February 2, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants