-
Notifications
You must be signed in to change notification settings - Fork 235
Adding retry logic for #655 and add tests for delete_default_vpc.py #708
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0393102
Adding retry logic for #655 and add tests for delete_default_vpc.py
39e6375
Proper logging
5ab608e
Adopt tenacity in favor of retrying
0eb2eab
Max retry logic and exponential backoff intervals
da320f4
Change logging msg to DEBUG and add meaningfull msg
f09b1bf
Mock nap.time.sleep for faster tests
e247f6d
Merge branch 'master' into fix-655
StewartW 44a8609
Update src/lambda_codebase/account_processing/tests/test_delete_defau…
StewartW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| aws-xray-sdk==2.13.0 | ||
| pyyaml~=6.0.1 | ||
| tenacity==8.2.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/lambda_codebase/account_processing/tests/test_delete_default_vpc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright Amazon.com Inc. or its affiliates. | ||
| # SPDX-License-Identifier: MIT-0 | ||
|
|
||
| """ | ||
StewartW marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Tests the delete_default_vpc lambda | ||
| """ | ||
|
|
||
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
| from delete_default_vpc import find_default_vpc | ||
| from botocore.exceptions import ClientError | ||
|
|
||
|
|
||
| class TestFindDefaultVPC(unittest.TestCase): | ||
|
|
||
| @patch("tenacity.nap.time.sleep", MagicMock()) | ||
| @patch('delete_default_vpc.patch_all') | ||
sbkok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # pylint: disable=unused-argument | ||
| def test_find_default_vpc(self, mock_patch_all): | ||
| # Create a mock ec2_client | ||
| mock_ec2_client = MagicMock() | ||
|
|
||
| # Define the side effects for describe_vpcs method | ||
| side_effects = [ | ||
| ClientError({'Error': {'Code': 'MockTestError'}}, 'describe_vpcs'), | ||
| ClientError({'Error': {'Code': 'MockTestError'}}, 'describe_vpcs'), | ||
| {"Vpcs": [ | ||
| {"VpcId": "vpc-123", "IsDefault": False}, | ||
| {"VpcId": "vpc-456", "IsDefault": True}, | ||
| {"VpcId": "vpc-789", "IsDefault": False} | ||
| ]} | ||
| ] | ||
|
|
||
| # Set side_effect for the mock ec2_client.describe_vpcs | ||
| mock_ec2_client.describe_vpcs.side_effect = side_effects | ||
|
|
||
| # Call the function with the mock ec2_client | ||
| default_vpc_id = find_default_vpc(mock_ec2_client) | ||
|
|
||
| # Check if the correct default VPC ID is returned | ||
| self.assertEqual(default_vpc_id, "vpc-456") | ||
|
|
||
| # Check if describe_vpcs method is called 3 times | ||
| self.assertEqual(mock_ec2_client.describe_vpcs.call_count, 3) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.