-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Add AWS module_utils function to be able to check exceptions for a spec… #41202
Conversation
The test
|
The test
The test
|
thanks @ryansb, looks good |
The test
|
The duplicate-exception test doesn't seem to like this change :( |
3434a01
to
f9228a1
Compare
@s-hertel I rebased your branch on latest devel and applied the same change to aws_eks_cluster so that if you work out how to appease the tests, aws_eks_cluster will get the fix too |
The test
|
This |
test/sanity/pylint/ignore.txt
Outdated
lib/ansible/modules/cloud/amazon/ecs_ecr.py ansible-format-automatic-specification | ||
lib/ansible/modules/cloud/amazon/rds_instance_facts.py duplicate-except | ||
lib/ansible/modules/cloud/amazon/rds_snapshot_facts.py duplicate-except |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these ignores needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the exception being caught is being dynamically generated and may or may not be the same class caught below. Pylint doesn't differentiate between this and static duplicates yet. I've opened a ticket in hopes that we can ignore only dynamically generate exception possible-duplicates in the future pylint-dev/pylint#2174 (so we don't accidentally mask static duplicates for which there is no reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add the error code check to the existing ClientError exception handlers instead of using dynamic types?
It looks like ClientError is already handled in most cases, so you'd end up with something like:
except botocore.exceptions.ClientError as e:
if is_boto3_error_code('NoSuchConfigRuleException'):
# do stuff here
else:
# do other stuff here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it just simplifies things and gives us the equivalent to what we thought from_code was (interestingly, from_code is also catching duplicate exceptions, pylint isn't catching it somehow).
Allows:
except is_boto3_error_code('ExceptionCodeWithSpecialHandling'):
pass
except (BotoCoreError, ClientError) as e:
module.fail_json_aws(e, msg="error message")
rather than
except ClientError as e:
if is_boto3_error_code('NoSuchConfigRuleException'):
pass
else:
module.fail_json_aws(e, msg="error message")
except BotoCoreError as e:
module.fail_json_aws(e, msg="error message")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use inline pylint ignore comments for these instead of ignore.txt, since these are not issues that need fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the correct ignore the # noqa
comment on the line? Or is there an ignore where you can specify the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's # pylint: disable=duplicate-except
…arisons in Python 3+
bc5facd
to
014f10b
Compare
…ble#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
…ific error code
WIP need to add this to the guidelines doc.
SUMMARY
Implementation for how we are using client.exceptions.from_code. from_code() is masking ClientErrors or ClientError subclasses.
ISSUE TYPE
COMPONENT NAME
lib/ansible/module_utils/aws/core.py
ANSIBLE VERSION