Skip to content

Commit 0dea023

Browse files
authored
test: delete created change sets in companion stack if empty (#3807)
1 parent 880c41e commit 0dea023

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

integration/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def clean_all_integ_buckets():
6363
@pytest.fixture()
6464
def setup_companion_stack_once(tmpdir_factory, get_prefix):
6565
tests_integ_dir = Path(__file__).resolve().parents[1]
66-
template_foler = Path(tests_integ_dir, "integration", "setup")
67-
companion_stack_tempalte_path = Path(template_foler, COMPANION_STACK_TEMPLATE)
66+
template_folder = Path(tests_integ_dir, "integration", "setup")
67+
companion_stack_template_path = Path(template_folder, COMPANION_STACK_TEMPLATE)
6868
cfn_client = ClientProvider().cfn_client
6969
output_dir = tmpdir_factory.mktemp("data")
7070
stack_name = get_prefix + COMPANION_STACK_NAME
71-
companion_stack = Stack(stack_name, companion_stack_tempalte_path, cfn_client, output_dir)
71+
companion_stack = Stack(stack_name, companion_stack_template_path, cfn_client, output_dir)
7272
companion_stack.create_or_update(_stack_exists(stack_name))
7373

7474

integration/helpers/deployer/deployer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ def create_and_wait_for_changeset(
373373
self.describe_changeset(result["Id"], stack_name)
374374
return result
375375
except deploy_exceptions.ChangeEmptyError:
376+
try:
377+
# Delete the most recent change set that failed to create because it was empty
378+
changeset = sorted(
379+
self._client.list_change_sets(StackName=stack_name).get("Summaries"),
380+
key=lambda c: c["CreationTime"],
381+
)[-1]
382+
if changeset.get("Status") == "FAILED" and changeset.get("ExecutionStatus") == "UNAVAILABLE":
383+
self._client.delete_change_set(ChangeSetName=changeset["ChangeSetId"], StackName=stack_name)
384+
except Exception as ex:
385+
LOG.warning("Failed to clean up empty changeset", exc_info=ex)
376386
return {}
377387
except botocore.exceptions.ClientError as ex:
378388
raise deploy_exceptions.DeployFailedError(stack_name=stack_name, msg=str(ex))

0 commit comments

Comments
 (0)