Add missing changes when creating a change set (#3039)

* Display changes when creating a change set

* add change set id and description when describing stack

* fix lint with flake8 and black
This commit is contained in:
Jeremie Tharaud 2020-06-03 07:08:35 +02:00 committed by GitHub
commit 90e200f0f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 25 deletions

View file

@ -573,9 +573,9 @@ def test_boto3_create_stack_set_with_yaml():
def test_create_stack_set_from_s3_url():
s3 = boto3.client("s3")
s3_conn = boto3.resource("s3", region_name="us-east-1")
bucket = s3_conn.create_bucket(Bucket="foobar")
s3_conn.create_bucket(Bucket="foobar")
key = s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
key_url = s3.generate_presigned_url(
ClientMethod="get_object", Params={"Bucket": "foobar", "Key": "template-key"}
)
@ -716,9 +716,9 @@ def test_create_stack_with_role_arn():
def test_create_stack_from_s3_url():
s3 = boto3.client("s3")
s3_conn = boto3.resource("s3", region_name="us-east-1")
bucket = s3_conn.create_bucket(Bucket="foobar")
s3_conn.create_bucket(Bucket="foobar")
key = s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
key_url = s3.generate_presigned_url(
ClientMethod="get_object", Params={"Bucket": "foobar", "Key": "template-key"}
)
@ -800,9 +800,9 @@ def test_update_stack_from_s3_url():
def test_create_change_set_from_s3_url():
s3 = boto3.client("s3")
s3_conn = boto3.resource("s3", region_name="us-east-1")
bucket = s3_conn.create_bucket(Bucket="foobar")
s3_conn.create_bucket(Bucket="foobar")
key = s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
s3_conn.Object("foobar", "template-key").put(Body=dummy_template_json)
key_url = s3.generate_presigned_url(
ClientMethod="get_object", Params={"Bucket": "foobar", "Key": "template-key"}
)
@ -844,6 +844,25 @@ def test_describe_change_set():
assert (
two_secs_ago < stack["CreationTime"] < datetime.now(tz=pytz.UTC)
), "Change set should have been created recently"
stack["Changes"].should.have.length_of(1)
stack["Changes"][0].should.equal(
dict(
{
"Type": "Resource",
"ResourceChange": {
"Action": "Add",
"LogicalResourceId": "EC2Instance1",
"ResourceType": "AWS::EC2::Instance",
},
}
)
)
# Execute change set
cf_conn.execute_change_set(ChangeSetName="NewChangeSet")
# Verify that the changes have been applied
stack = cf_conn.describe_change_set(ChangeSetName="NewChangeSet")
stack["Changes"].should.have.length_of(1)
cf_conn.create_change_set(
StackName="NewStack",
@ -887,7 +906,7 @@ def test_execute_change_set_w_arn():
@mock_cloudformation
def test_execute_change_set_w_name():
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
change_set = cf_conn.create_change_set(
cf_conn.create_change_set(
StackName="NewStack",
TemplateBody=dummy_template_json,
ChangeSetName="NewChangeSet",
@ -1221,9 +1240,7 @@ def test_delete_stack_with_export():
@mock_cloudformation
def test_export_names_must_be_unique():
cf = boto3.resource("cloudformation", region_name="us-east-1")
first_stack = cf.create_stack(
StackName="test_stack", TemplateBody=dummy_output_template_json
)
cf.create_stack(StackName="test_stack", TemplateBody=dummy_output_template_json)
with assert_raises(ClientError):
cf.create_stack(StackName="test_stack", TemplateBody=dummy_output_template_json)
@ -1237,9 +1254,7 @@ def test_stack_with_imports():
output_stack = cf.create_stack(
StackName="test_stack1", TemplateBody=dummy_output_template_json
)
import_stack = cf.create_stack(
StackName="test_stack2", TemplateBody=dummy_import_template_json
)
cf.create_stack(StackName="test_stack2", TemplateBody=dummy_import_template_json)
output_stack.outputs.should.have.length_of(1)
output = output_stack.outputs[0]["OutputValue"]

View file

@ -1,7 +1,6 @@
from __future__ import unicode_literals
import json
import base64
from decimal import Decimal
import boto
@ -28,7 +27,6 @@ from moto import (
mock_dynamodb2,
mock_ec2,
mock_ec2_deprecated,
mock_elb,
mock_elb_deprecated,
mock_events,
mock_iam_deprecated,
@ -37,18 +35,14 @@ from moto import (
mock_logs,
mock_rds_deprecated,
mock_rds2,
mock_rds2_deprecated,
mock_redshift,
mock_redshift_deprecated,
mock_route53_deprecated,
mock_s3,
mock_sns_deprecated,
mock_sqs,
mock_sqs_deprecated,
mock_elbv2,
)
from moto.core import ACCOUNT_ID
from moto.dynamodb2.models import Table
from tests.test_cloudformation.fixtures import (
ec2_classic_eip,