mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Add AWS boto3 error code exception function is_boto3_error_code (#41202)
* Add aws/core.py function to check for specific AWS error codes * Use sys.exc_info to get exception object if it isn't passed in * Allow catching exceptions with is_boto3_error_code * Replace from_code with is_boto3_error_code * Return a type that will never be raised to support stricter type comparisons in Python 3+ * Use is_boto3_error_code in aws_eks_cluster * Add duplicate-except to ignores when using is_boto3_error_code * Add is_boto3_error_code to module development guideline docs
This commit is contained in:
parent
269f404121
commit
40d2df0ef3
12 changed files with 84 additions and 41 deletions
|
@ -129,7 +129,7 @@ version:
|
|||
'''
|
||||
|
||||
|
||||
from ansible.module_utils.aws.core import AnsibleAWSModule
|
||||
from ansible.module_utils.aws.core import AnsibleAWSModule, is_boto3_error_code
|
||||
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, get_ec2_security_group_ids_from_names
|
||||
|
||||
try:
|
||||
|
@ -197,11 +197,11 @@ def get_cluster(client, module):
|
|||
name = module.params.get('name')
|
||||
try:
|
||||
return client.describe_cluster(name=name)['cluster']
|
||||
except client.exceptions.from_code('ResourceNotFoundException'):
|
||||
except is_boto3_error_code('ResourceNotFoundException'):
|
||||
return None
|
||||
except botocore.exceptions.EndpointConnectionError as e:
|
||||
except botocore.exceptions.EndpointConnectionError as e: # pylint: disable=duplicate-except
|
||||
module.fail_json(msg="Region %s is not supported by EKS" % client.meta.region_name)
|
||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
|
||||
module.fail_json(e, msg="Couldn't get cluster %s" % name)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue