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

Handle expected boolean values for waiter error matcher #8804

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-wait-22691.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "wait",
"description": "Update waiters to handle expected boolean values when matching errors (`aws/aws-cli#3220 <https://github.com/aws/aws-cli/issues/3220>`__)"
}
11 changes: 10 additions & 1 deletion awscli/botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,16 @@ def acceptor_matches(response):
# response. So response is still a dictionary, and in the case
# of an error response will contain the "Error" and
# "ResponseMetadata" key.
return response.get("Error", {}).get("Code", "") == expected
# When expected is True, accept any error code.
# When expected is False, check if any errors were encountered.
# Otherwise, check for a specific AWS error code.
if expected is True:
return "Error" in response and "Code" in response["Error"]
elif expected is False:
return "Error" not in response
else:
return response.get("Error", {}).get("Code", "") == expected

return acceptor_matches


Expand Down
32 changes: 32 additions & 0 deletions tests/unit/botocore/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,38 @@ def test_single_waiter_supports_error(self):
self.assertFalse(
success_acceptor({'Error': {'Code': 'DoesNotExistErorr'}}))

def test_single_waiter_supports_no_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': False,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({}))
self.assertFalse(success_acceptor({'Error': {'Code': 'ExampleError'}}))

def test_single_waiter_supports_any_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': True,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError1'}}))
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError2'}}))

def test_unknown_matcher(self):
unknown_type = 'arbitrary_type'
single_waiter = {
Expand Down
Loading