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_vpc_nat_gateway cleanup #445

Merged

Conversation

alinabuzachis
Copy link
Contributor

SUMMARY

Cleanup ec2_vpc_nat_gateway

ISSUE TYPE
COMPONENT NAME

ec2_vpc_nat_gateway

@ansibullbot
Copy link

@ansibullbot ansibullbot added WIP Work in progress module module needs_triage plugins plugin (any type) small_patch Hopefully easy to review labels Feb 25, 2021
@tremble
Copy link
Contributor

tremble commented Feb 25, 2021

Test failures look to be due to a lack of retry decorators on ec2_vpc_nat_gateway_info

@alinabuzachis
Copy link
Contributor Author

@tremble yes, thank you. Should I add the decorator in this PR or open a new one? This PR is for the overall cleanup of the ec2_vpc_nat_gateway module and I think it would be better to merge #436 before. I can add the decorator in #436 if you prefer.

@tremble
Copy link
Contributor

tremble commented Feb 25, 2021

In the strictest sense it can be its own PR, which I'd happily review and merge pretty quickly.

In the past I've bundled the and _info cleanup together in a couple of cases, because the tests tend to be linked (and getting reviews was difficult before yourself and the other new cloud team members started).

@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch from 8126d8b to 3741139 Compare February 25, 2021 16:18
@alinabuzachis
Copy link
Contributor Author

@tremble Ok, I will do it in a while and I will ping you then. Thank you.

@ansibullbot ansibullbot added integration tests/integration tests tests and removed small_patch Hopefully easy to review labels Feb 25, 2021
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.

Good progress here

return True, ''

ip_released = False
try:
client.describe_addresses(aws_retry=True, AllocationIds=[allocation_id])
except botocore.exceptions.ClientError as e:
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

There might be a more specific failure that we could catch here with is_boto3_error_code (probably InvalidAllocationID.NotFound, not sure about any others) to do the return True, str(e), and handle general exceptions separately.

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 Thank you for reviewing. I tried to add the catch on this error. Let me know if it makes sense to you.

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 I noticed adding the explicit catch of the InvalidAllocationID.NotFound error implies removing the botocore.exceptions.ClientError because InvalidAllocationID.NotFound is already catched by ClientError. Otherwise, I can catch only InvalidAllocationID.NotFound and then consider the except botocore.exceptions.BotoCoreError (this is what I've actually done right now). Let me know if this works for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be possible to catch both BotoCoreError and ClientError.

While pylint thinks that except is_boto3_error_code('InvalidAllocationID.NotFound') catches all ClientError, this is actually incorrect and due to a bug in pylint. pylint-dev/pylint#2174

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 Ok, my Shippable check was failing due to this duplicate catch. I added again the the botocore.exceptions.ClientError. Thanks.

@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch 2 times, most recently from ebf852c to 2c00a76 Compare March 4, 2021 18:02
@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch 6 times, most recently from 0eba859 to 79ce47f Compare March 9, 2021 14:43
# IP address likely already released
# Happens with gateway in 'deleted' state that
# still lists associations
return True, str(e)
return True, e
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I forget to commit it. Could you kindly have a look as well at this #436 (when you will have some time)?

@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch 2 times, most recently from 6dc30db to f98c541 Compare March 9, 2021 22:02
@ansibullbot
Copy link

@alinabuzachis this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibullbot ansibullbot added the merge_commit This PR contains at least one merge commit. Please resolve! label Mar 10, 2021
@ansibullbot ansibullbot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Mar 10, 2021
@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch 2 times, most recently from edec340 to 923f544 Compare March 10, 2021 17:02
@ansibullbot ansibullbot 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 Mar 10, 2021
@alinabuzachis alinabuzachis changed the title [WIP] ec2_vpc_nat_gateway cleanup ec2_vpc_nat_gateway cleanup Mar 11, 2021
@ansibullbot ansibullbot added community_review and removed WIP Work in progress labels Mar 11, 2021
@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch 3 times, most recently from 2e1a7e6 to 38f3b66 Compare March 11, 2021 18:55
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>
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.

Couple small things here, thanks @alinabuzachis for all your work on this

"EIP {0} does not exist".format(eip_address)
)
except is_boto3_error_code('InvalidAddress.Malformed') as e:
allocation_id = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the EIP the user provides is malformed we should probably return that information to the user so that they can troubleshoot their playbook, we're returning an empty msg now. For a malformed EIP we should probably fail here rather than returning back to pre_create since we can't proceed with the information provided in the playbook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added fail_json for this case. Let me know if this works for you. Thank you @jillr.

except is_boto3_error_code('InvalidAddress.Malformed') as e:
allocation_id = None
except is_boto3_error_code('InvalidAddress.NotFound') as e: # pylint: disable=duplicate-except
allocation_id = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably also want to exit here as well and return the error to the user.

Copy link
Contributor Author

@alinabuzachis alinabuzachis Mar 16, 2021

Choose a reason for hiding this comment

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

Thank you for reviewing @jillr. I added the specific msg for this case. As allocation_id will be None, it will exit propagating the message. https://github.com/ansible-collections/community.aws/pull/445/files#diff-847118175f7fbd015daf612a3319157ca22874f706c01f26348f4f86f67384d9R742-R749 Is this working for you?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, this makes sense to me. Thanks!

Signed-off-by: Alina Buzachis <[email protected]>
@alinabuzachis alinabuzachis force-pushed the cleanup_ec2_vpc_nat_gateway branch from 38f3b66 to c555d66 Compare March 16, 2021 13:46
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

@jillr jillr merged commit 9b60a2d into ansible-collections:main Mar 16, 2021
danquixote pushed a commit to danquixote/community.aws that referenced this pull request May 16, 2021
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>
alinabuzachis added a commit to alinabuzachis/community.aws that referenced this pull request Jul 16, 2021
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@9b60a2d
alinabuzachis added a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>
alinabuzachis added a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>
danielcotton pushed a commit to danielcotton/community.aws that referenced this pull request Nov 23, 2021
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>
alinabuzachis added a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
* Add waiter for ec2_vpc_nat_gateway (ansible-collections#445)
* Added NatGatewayAvailable waiter

Signed-off-by: Alina Buzachis <[email protected]>
alinabuzachis added a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
* ec2_vpc_nat_gateway overall cleanup
   * use custm waiters to manage NAT gateway states (deleted and available)
   * imporve error handling
   * improve documentation examples
   * code cleaning

Signed-off-by: Alina Buzachis <[email protected]>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@9b60a2d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review integration tests/integration module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants