From 8fa625c3def8287882c8193bf72bf778510db3d2 Mon Sep 17 00:00:00 2001 From: Jeremie Tharaud <46786750+jeremietharaud@users.noreply.github.com> Date: Fri, 29 May 2020 08:33:24 +0200 Subject: [PATCH] Cfn change set fix outputs (#3033) * set creation time of the change set * fix status, execution status, stak id, creation time and update tests --- moto/cloudformation/models.py | 6 ++++-- moto/cloudformation/responses.py | 2 +- .../test_cloudformation_stack_crud_boto3.py | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index 281ab5e19..16ceafdb8 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -240,7 +240,8 @@ class FakeStack(BaseModel): self.resource_map = self._create_resource_map() self.output_map = self._create_output_map() if create_change_set: - self.status = "REVIEW_IN_PROGRESS" + self.status = "CREATE_COMPLETE" + self.execution_status = "AVAILABLE" else: self.create_resources() self._add_stack_event("CREATE_COMPLETE") @@ -397,6 +398,7 @@ class FakeChangeSet(FakeStack): self.change_set_id = change_set_id self.change_set_name = change_set_name self.changes = self.diff(template=template, parameters=parameters) + self.creation_time = datetime.utcnow() def diff(self, template, parameters=None): self.template = template @@ -587,7 +589,7 @@ class CloudFormationBackend(BaseBackend): if stack is None: raise ValidationError(stack_name) else: - stack_id = generate_stack_id(stack_name) + stack_id = generate_stack_id(stack_name, region_name) stack_template = template change_set_id = generate_changeset_id(change_set_name, region_name) diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index 782d68946..c028421ca 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -609,7 +609,7 @@ DESCRIBE_CHANGE_SET_RESPONSE_TEMPLATE = """ {% endfor %} - 2011-05-23T15:47:44Z + {{ change_set.creation_time_iso_8601 }} {{ change_set.execution_status }} {{ change_set.status }} {{ change_set.status_reason }} diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 58d505d89..c4fddcad0 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -819,7 +819,7 @@ def test_create_change_set_from_s3_url(): in response["Id"] ) assert ( - "arn:aws:cloudformation:us-east-1:123456789:stack/NewStack" + "arn:aws:cloudformation:us-west-1:123456789:stack/NewStack" in response["StackId"] ) @@ -838,7 +838,12 @@ def test_describe_change_set(): stack["ChangeSetName"].should.equal("NewChangeSet") stack["StackName"].should.equal("NewStack") - stack["Status"].should.equal("REVIEW_IN_PROGRESS") + stack["Status"].should.equal("CREATE_COMPLETE") + stack["ExecutionStatus"].should.equal("AVAILABLE") + two_secs_ago = datetime.now(tz=pytz.UTC) - timedelta(seconds=2) + assert ( + two_secs_ago < stack["CreationTime"] < datetime.now(tz=pytz.UTC) + ), "Change set should have been created recently" cf_conn.create_change_set( StackName="NewStack", @@ -868,7 +873,7 @@ def test_execute_change_set_w_arn(): ) ec2.describe_instances()["Reservations"].should.have.length_of(0) cf_conn.describe_change_set(ChangeSetName="NewChangeSet")["Status"].should.equal( - "REVIEW_IN_PROGRESS" + "CREATE_COMPLETE" ) # Execute change set cf_conn.execute_change_set(ChangeSetName=change_set["Id"])