From e1461659de166cb063aeaaf2d31729e9d7285b00 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 28 Apr 2022 14:09:13 +1000 Subject: [PATCH] AWS tests: cleanup image deletion checking This is a follow-on to I3279c3b5cb8cf26d390835fd0a7049bc43ec40b5 As discussed in the referenced issue, the blank return and AttributeError here is the correct way to determine a recently deleted image. We don't need to catch the ClientError as that won't be raised any more. Getting a value for the state would indicate it wasn't deleted. This bumps the moto base requirement to ensure we have this behaviour. Change-Id: I2d5b0ccb9802aa0d4c81555a17f40fe8b8595ebd --- nodepool/tests/unit/test_driver_aws.py | 19 ++++++------------- test-requirements.txt | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/nodepool/tests/unit/test_driver_aws.py b/nodepool/tests/unit/test_driver_aws.py index 1861a991d..1bea35401 100644 --- a/nodepool/tests/unit/test_driver_aws.py +++ b/nodepool/tests/unit/test_driver_aws.py @@ -487,20 +487,13 @@ class TestDriverAws(tests.DBTestCase): for _ in iterate_timeout(30, Exception, 'ami deletion'): image = self.ec2.Image(image_id) try: - if image.state == 'deleted': - break - except botocore.exceptions.ClientError: - # Probably not found - break + # If this has a value the image was not deleted + self.assertIsNone(image.state) except AttributeError: - # NOTE(ianw) 2022-04-27 For reasons that are unclear - # but have been filed as - # https://github.com/spulec/moto/issues/5067 - # accessing the image.state property of a deleted image - # with moto 1.3.6 will no longer result in the ClientError - # above, but boto will get blank response and try to - # dereference a None value. Thus catching this is a - # work-around until we have a better solution. + # Per AWS API, a recently deleted image is empty and + # looking at the state raises an AttributeFailure; see + # https://github.com/boto/boto3/issues/2531. The image + # was deleted, so we continue on here break for _ in iterate_timeout(30, Exception, 'snapshot deletion'): diff --git a/test-requirements.txt b/test-requirements.txt index a48b7a5a5..eebcfd3fe 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,5 +6,5 @@ python-subunit stestr>=1.0.0 # Apache-2.0 testscenarios testtools>=0.9.27 -moto +moto>=3.1.6 responses>=0.12.1