Skip to content

Commit 57ae2b8

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
[integ-tests-framework] Retry deletion of VPC stacks
VPC deletion failure is sporadic caused by resources in the VPC not fully deleted. Retrying deletion give more time for the resources to be deleted and VPC deleted successfully. Other resources deletions are not retried,because we want to investigate those failures. Signed-off-by: Hanwen <hanwenli@amazon.com>
1 parent 80a4472 commit 57ae2b8

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tests/integration-tests/cfn_stacks_factory.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def update_stack(
304304
"Couldn't find stack with name {0} in region {1}. Skipping update.".format(name, region)
305305
)
306306

307-
def delete_all_stacks(self, excluded_stacks=None):
307+
def delete_all_stacks(self, excluded_stacks=None): # noqa: C901
308308
"""Destroy all created stacks except for those in excluded_stacks."""
309309
logging.debug("Destroying all cfn stacks")
310310
for value in reversed(OrderedDict(self.__created_stacks).values()):
@@ -319,11 +319,27 @@ def delete_all_stacks(self, excluded_stacks=None):
319319
try:
320320
self.delete_stack(value.name, value.region)
321321
except Exception as e:
322-
logging.error(
323-
"Failed when destroying stack {0} in region {1} with exception {2}.".format(
324-
value.name, value.region, e
322+
if "-vpc-" in value.name:
323+
# Retry deletion only if it is a VPC stack.
324+
# Because VPC stack is not part of the released product, we can ignore deletion failures.
325+
logging.warning(
326+
"Failed when destroying stack {0} in region {1} with exception {2}. "
327+
"Trying delete again.".format(value.name, value.region, e)
328+
)
329+
try:
330+
self.delete_stack(value.name, value.region)
331+
except Exception as e:
332+
logging.error(
333+
"Failed when destroying stack {0} in region {1} with exception {2}.".format(
334+
value.name, value.region, e
335+
)
336+
)
337+
else:
338+
logging.error(
339+
"Failed when destroying stack {0} in region {1} with exception {2}.".format(
340+
value.name, value.region, e
341+
)
325342
)
326-
)
327343

328344
@retry(
329345
retry_on_result=lambda result: result == "CREATE_IN_PROGRESS",

0 commit comments

Comments
 (0)