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

ec2_vol: Add check_mode support to ec2_vol #509

Merged

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Sep 21, 2021

SUMMARY

Add check_mode support to ec2_vol.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_vol

@ansibullbot
Copy link

@mandar242 this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request merge_commit This PR contains at least one merge commit. Please resolve! module module needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_triage labels Sep 21, 2021
@ansibullbot
Copy link

@ansibullbot ansibullbot added community_review integration tests/integration plugins plugin (any type) tests tests and removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Sep 21, 2021
@goneri
Copy link
Member

goneri commented Sep 21, 2021

recheck

1 similar comment
@alinabuzachis
Copy link
Contributor

recheck

@alinabuzachis
Copy link
Contributor

recheck

plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
@alinabuzachis
Copy link
Contributor

recheck

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 @mandar242. What you have here looks good but could you please add some tests for different update actions? As the code flows now it should be fine, but for example module_utils.ec2.ensure_ec2_tags doesn't handle check_mode so if the logic ever got changed around we could miss that if there wasn't a test for tag changes under check_mode.

@tremble
Copy link
Contributor

tremble commented Oct 1, 2021

module_utils.ec2.ensure_ec2_tags doesn't handle check_mode so if the logic ever got changed around we could miss that if there wasn't a test for tag changes under check_mode.

Not entirely true, it's handled down in remove_ec2_tags and add_ec2_tags which will return "changed" but not make the change in check mode.

Copy link
Contributor

@alinabuzachis alinabuzachis left a comment

Choose a reason for hiding this comment

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

@mandar242 Thank you very much for working on this. I have only one last suggestion. Could you please use as example the tests run without the check mode and add more tests for the check mode in an analogous way (where it makes sense)? We want to be sure the check mode covers all the functionalities.

@tremble
Copy link
Contributor

tremble commented Oct 1, 2021

To follow up on what @alinabuzachis said: where possible, the best way to write the tests is for each 'change' that you make within the tests you run the change 4 times:

  1. With check_mode - testing is changed
  2. Without check_mode - testing is changed and the other return values
  3. With check_mode again, testing is not changed
  4. Without check_mode again, testing is not changed and the other return values.

This can get rather long and repetitive for the more complex modules, but catches a lot of annoying little bugs and when someone's reviewing the code it's much easier to see that things like idempotency and check mode are behaving consistently within the module. I'll often label each test as

  1. Update SomeThing - check_mode
  2. Update SomeThing
  3. Update SomeThing - idempotency - check_mode
  4. Update SomeThing - idempotency

@tremble
Copy link
Contributor

tremble commented Oct 1, 2021

recheck

@jillr
Copy link
Collaborator

jillr commented Oct 1, 2021

recheck

@tremble saw your ping in irc after you'd gone. That's a really interesting CI failure that I don't know about! Let's see if it happens again?

@jillr
Copy link
Collaborator

jillr commented Oct 1, 2021

recheck

Copy link
Contributor

@alinabuzachis alinabuzachis left a comment

Choose a reason for hiding this comment

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

@mandar242 Thank you. LGTM!

Comment on lines +462 to 465
if module.check_mode:
module.exit_json(changed=True, msg='Would have created a volume if not in check mode.')

if volume is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

One minor niggle for the future (not worth blocking this over). I find it's less likely to lead to weird edge cases if you make your check_mode tests as late as possible. Here for example, if someone re-wrote the flow of main() and you'd sometimes be passed a volume, performing the check_mode test before you test volume would result in broken idempotency.

@tremble tremble added the gate label Oct 6, 2021
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review feature This issue/PR relates to a feature request integration tests/integration module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants