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

aws_kms - stabilize and add integration tests #1052

Conversation

jatorcasso
Copy link
Contributor

SUMMARY
  • update/add integration tests for various actions
  • return list of policies as a list of jsons for clarity
  • sleep on updates (no kms waiter, attempted manual waiters but still had test failures)
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

aws_kms

ADDITIONAL INFORMATION

I tried adding manual waiters for different actions like waiting for tags to be correct, policy to be updated, etc, but would still fail ~half of the time on idempotency tests. seems like after updating the key's status is a bit buggy.

@ansibullbot
Copy link

@ansibullbot ansibullbot added community_review feature This issue/PR relates to a feature request integration tests/integration module module needs_triage plugins plugin (any type) tests tests labels Apr 6, 2022
Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

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

LGTM, there's a lot of formatting changes in the tests though (which are good changes!) so I'd like to see a second review before a merge in case I missed anything.

@jatorcasso
Copy link
Contributor Author

Considering the last CI run failed, it looks like the wait will still cause CI problems. Seems like I should just remove the wait and keep the tests marked as unstable @jillr @alinabuzachis

Copy link
Contributor

@mandar242 mandar242 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jatorcasso
Copy link
Contributor Author

recheck

@jatorcasso jatorcasso marked this pull request as draft April 14, 2022 19:43
@jatorcasso jatorcasso marked this pull request as ready for review April 14, 2022 20:36
@markuman markuman added the backport-3 PR should be backported to the stable-3 branch label Apr 19, 2022
@@ -863,6 +904,10 @@ def update_key(connection, module, key):
changed |= update_grants(connection, module, key, module.params.get('grants'), module.params.get('purge_grants'))
changed |= update_key_rotation(connection, module, key, module.params.get('enable_key_rotation'))

# Pause to wait for updates
if changed and not module.check_mode:
sleep(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of using sleep here because it isn't probably solving the issue. If sometimes the update operation will take more than 5 seconds we will be in the same situation. Maybe @tremble can suggest a better approach instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think what we'd need to do here is a build a comparison function that constructs what we expect to returned by get_key_details(), and checks to see if result matches (or at least the relevant keys). If it doesn't, retry (some limited number of times).

Or else change every update/ensure function to do something similar - "connection.update_key_description, then connection.describe_key and check the description". I don't like this option much though.

Copy link
Member

Choose a reason for hiding this comment

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

I think what we'd need to do here is a build a comparison function that constructs what we expect to returned by get_key_details(), and checks to see if result matches (or at least the relevant keys). If it doesn't, retry (some limited number of times).

sleep is used like this in s3_lifecycle

Copy link
Contributor Author

@jatorcasso jatorcasso Apr 21, 2022

Choose a reason for hiding this comment

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

another option is retrying on KMSInvalidStateException, like what I proposed for iam_user and rds_instance does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tremble - tagging you here because this is simliar to the igw issue where on one call of getting the key, description is new-description, then on following call, description is old-description. same with tags, policies, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jillr tried both of those options and still errors in integration tests. It'll return the updated fields, then on subsequent calls, return old fields.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jatorcasso Gotcha. In that case the sleep sounds justified, can you please update the code comment to briefly explain that the API stays inconsistent too long to do a simple check and we need to wait to be confident the change has propagated? Otherwise we might try to change it later and run into this problem again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To summarize the OT (Slack) conversation around this - it seems that all of the proposed workarounds regarding the wait period after updates and inconsistencies in whats being reflected when fetching key metadata don't fix the problem (integration tests still failing on idempotency tests). Documenting this in the module as well as adding waits in integration tests was decided to be the best solution (albeit not a great one).

plugins/modules/aws_kms.py Outdated Show resolved Hide resolved
plugins/modules/aws_kms.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

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

thanks for all your work on this @jatorcasso!

@jillr jillr added the mergeit Merge the PR (SoftwareFactory) label Apr 26, 2022
@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 558a025 into ansible-collections:main Apr 26, 2022
@patchback
Copy link

patchback bot commented Apr 26, 2022

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/558a0252a3d57657b8c6be50e65b3663d37958fa/pr-1052

Backported as #1099

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Apr 26, 2022
aws_kms - stabilize and add integration tests

SUMMARY

update/add integration tests for various actions
return list of policies as a list of jsons for clarity
sleep on updates (no kms waiter, attempted manual waiters but still had test failures)

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_kms
ADDITIONAL INFORMATION
I tried adding manual waiters for different actions like waiting for tags to be correct, policy to be updated, etc, but would still fail ~half of the time on idempotency tests. seems like after updating the key's status is a bit buggy.

Reviewed-by: Jill R <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Joseph Torcasso <None>
Reviewed-by: Mandar Kulkarni <mandar242@gmail.com>
Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Alina Buzachis <None>
(cherry picked from commit 558a025)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request May 6, 2022
[PR #1052/558a0252 backport][stable-3] aws_kms - stabilize and add integration tests

This is a backport of PR #1052 as merged into main (558a025).
SUMMARY

update/add integration tests for various actions
return list of policies as a list of jsons for clarity
sleep on updates (no kms waiter, attempted manual waiters but still had test failures)

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_kms
ADDITIONAL INFORMATION
I tried adding manual waiters for different actions like waiting for tags to be correct, policy to be updated, etc, but would still fail ~half of the time on idempotency tests. seems like after updating the key's status is a bit buggy.

Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/community.aws that referenced this pull request Oct 24, 2023
…e_cloudwatchevent

Migrate cloudwatchevent* modules and tests

Depends-On: ansible/zuul-config#443
Migrate cloudwatchevent* modules and tests

Reviewed-by: Mike Graves <mgraves@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3 PR should be backported to the stable-3 branch community_review feature This issue/PR relates to a feature request has_issue integration tests/integration mergeit Merge the PR (SoftwareFactory) module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants