From 90898132e456ee1993db99a1531379f1b98ee915 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 13 Feb 2020 22:59:00 +0100 Subject: [PATCH] CloudRetry/AWSRetry : Disable catching of NotFound exceptions (#67281) * CloudRetry/AWSRetry : Remove default catching of NotFound exceptions * Add docs * Changelog updates from review * Update unit tests after removing 'NotFound' from default retries --- changelogs/fragments/67281-AWSRetry-disable-NotFound.yaml | 2 ++ docs/docsite/rst/porting_guides/porting_guide_2.10.rst | 1 + lib/ansible/module_utils/ec2.py | 3 +-- test/units/module_utils/ec2/test_aws.py | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/67281-AWSRetry-disable-NotFound.yaml diff --git a/changelogs/fragments/67281-AWSRetry-disable-NotFound.yaml b/changelogs/fragments/67281-AWSRetry-disable-NotFound.yaml new file mode 100644 index 00000000000..43680118d27 --- /dev/null +++ b/changelogs/fragments/67281-AWSRetry-disable-NotFound.yaml @@ -0,0 +1,2 @@ +minor_changes: +- "The ``AWSRetry`` decorator no longer catches ``NotFound`` exceptions unless they're explicitly added via ``catch_extra_error_codes``." diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.10.rst b/docs/docsite/rst/porting_guides/porting_guide_2.10.rst index 3ab2e1ec86d..452c3abfd3b 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_2.10.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_2.10.rst @@ -102,6 +102,7 @@ Noteworthy module changes * The ``datacenter`` option has been removed from :ref:`vmware_guest_find ` * The options ``ip_address`` and ``subnet_mask`` have been removed from :ref:`vmware_vmkernel `; use the suboptions ``ip_address`` and ``subnet_mask`` of the ``network`` option instead. * Ansible modules created with ``add_file_common_args=True`` added a number of undocumented arguments which were mostly there to ease implementing certain action plugins. The undocumented arguments ``src``, ``follow``, ``force``, ``content``, ``backup``, ``remote_src``, ``regexp``, ``delimiter``, and ``directory_mode`` are now no longer added. Modules relying on these options to be added need to specify them by themselves. +* The ``AWSRetry`` decorator no longer catches ``NotFound`` exceptions by default. ``NotFound`` exceptions need to be explicitly added using ``catch_extra_error_codes``. Some AWS modules may see an increase in transient failures due to AWS's eventual consistency model. * :ref:`vmware_datastore_maintenancemode ` now returns ``datastore_status`` instead of Ansible internal key ``results``. * :ref:`vmware_host_kernel_manager ` now returns ``host_kernel_status`` instead of Ansible internal key ``results``. * :ref:`vmware_host_ntp ` now returns ``host_ntp_status`` instead of Ansible internal key ``results``. diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 2953592705c..59d088191b6 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -111,8 +111,7 @@ class AWSRetry(CloudRetry): if catch_extra_error_codes: retry_on.extend(catch_extra_error_codes) - not_found = re.compile(r'^\w+.NotFound') - return response_code in retry_on or not_found.search(response_code) + return response_code in retry_on def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params): diff --git a/test/units/module_utils/ec2/test_aws.py b/test/units/module_utils/ec2/test_aws.py index 9ef6e9e04e1..7c664422642 100644 --- a/test/units/module_utils/ec2/test_aws.py +++ b/test/units/module_utils/ec2/test_aws.py @@ -43,7 +43,7 @@ class RetryTestCase(unittest.TestCase): def extend_failures(): self.counter += 1 if self.counter < 2: - raise botocore.exceptions.ClientError(err_msg, 'Could not find you') + raise botocore.exceptions.ClientError(err_msg, 'You did something wrong.') else: return 'success' @@ -53,13 +53,13 @@ class RetryTestCase(unittest.TestCase): def test_retry_once(self): self.counter = 0 - err_msg = {'Error': {'Code': 'InstanceId.NotFound'}} + err_msg = {'Error': {'Code': 'InternalFailure'}} @AWSRetry.backoff(tries=2, delay=0.1) def retry_once(): self.counter += 1 if self.counter < 2: - raise botocore.exceptions.ClientError(err_msg, 'Could not find you') + raise botocore.exceptions.ClientError(err_msg, 'Something went wrong!') else: return 'success'