Fixes issue #575: cloudformation update_stack response ResponseParserError.
This commit is contained in:
parent
100ec4e7c8
commit
3017181862
@ -51,6 +51,7 @@ class FakeStack(object):
|
|||||||
self.template = template
|
self.template = template
|
||||||
self.resource_map.update(json.loads(template))
|
self.resource_map.update(json.loads(template))
|
||||||
self.output_map = self._create_output_map()
|
self.output_map = self._create_output_map()
|
||||||
|
self.status = 'UPDATE_COMPLETE'
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self.resource_map.delete()
|
self.resource_map.delete()
|
||||||
|
@ -130,14 +130,18 @@ class CloudFormationResponse(BaseResponse):
|
|||||||
name=stack_name,
|
name=stack_name,
|
||||||
template=stack_body,
|
template=stack_body,
|
||||||
)
|
)
|
||||||
stack_body = {
|
|
||||||
'UpdateStackResponse': {
|
if self.request_json:
|
||||||
'UpdateStackResult': {
|
return json.dumps({
|
||||||
'StackId': stack.name,
|
'UpdateStackResponse': {
|
||||||
|
'UpdateStackResult': {
|
||||||
|
'StackId': stack.name,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
else:
|
||||||
return json.dumps(stack_body)
|
template = self.response_template(UPDATE_STACK_RESPONSE_TEMPLATE)
|
||||||
|
return template.render(stack=stack)
|
||||||
|
|
||||||
def delete_stack(self):
|
def delete_stack(self):
|
||||||
name_or_stack_id = self.querystring.get('StackName')[0]
|
name_or_stack_id = self.querystring.get('StackName')[0]
|
||||||
@ -164,6 +168,15 @@ CREATE_STACK_RESPONSE_TEMPLATE = """<CreateStackResponse>
|
|||||||
</CreateStackResponse>
|
</CreateStackResponse>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
UPDATE_STACK_RESPONSE_TEMPLATE = """<UpdateStackResponse>
|
||||||
|
<UpdateStackResult>
|
||||||
|
<StackId>{{ stack.stack_id }}</StackId>
|
||||||
|
</UpdateStackResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>b9b5b068-3a41-11e5-94eb-example</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</UpdateStackResponse>
|
||||||
|
"""
|
||||||
|
|
||||||
DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResponse>
|
DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResponse>
|
||||||
<DescribeStacksResult>
|
<DescribeStacksResult>
|
||||||
|
@ -263,24 +263,24 @@ def test_stack_tags():
|
|||||||
dict(stack.tags).should.equal({"foo": "bar", "baz": "bleh"})
|
dict(stack.tags).should.equal({"foo": "bar", "baz": "bleh"})
|
||||||
|
|
||||||
|
|
||||||
# @mock_cloudformation
|
@mock_cloudformation
|
||||||
# def test_update_stack():
|
def test_update_stack():
|
||||||
# conn = boto.connect_cloudformation()
|
conn = boto.connect_cloudformation()
|
||||||
# conn.create_stack(
|
conn.create_stack(
|
||||||
# "test_stack",
|
"test_stack",
|
||||||
# template_body=dummy_template_json,
|
template_body=dummy_template_json,
|
||||||
# )
|
)
|
||||||
|
|
||||||
# conn.update_stack("test_stack", dummy_template_json2)
|
conn.update_stack("test_stack", dummy_template_json2)
|
||||||
|
|
||||||
# stack = conn.describe_stacks()[0]
|
stack = conn.describe_stacks()[0]
|
||||||
# stack.get_template().should.equal({
|
stack.get_template().should.equal({
|
||||||
# 'GetTemplateResponse': {
|
'GetTemplateResponse': {
|
||||||
# 'GetTemplateResult': {
|
'GetTemplateResult': {
|
||||||
# 'TemplateBody': dummy_template_json2,
|
'TemplateBody': dummy_template_json2,
|
||||||
# 'ResponseMetadata': {
|
'ResponseMetadata': {
|
||||||
# 'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE'
|
'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE'
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
# })
|
})
|
||||||
|
@ -19,7 +19,27 @@ dummy_template = {
|
|||||||
"Resources": {},
|
"Resources": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dummy_update_template = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Parameters": {
|
||||||
|
"KeyName": {
|
||||||
|
"Description": "Name of an existing EC2 KeyPair",
|
||||||
|
"Type": "AWS::EC2::KeyPair::KeyName",
|
||||||
|
"ConstraintDescription": "must be the name of an existing EC2 KeyPair."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Resources": {
|
||||||
|
"Instance": {
|
||||||
|
"Type": "AWS::EC2::Instance",
|
||||||
|
"Properties": {
|
||||||
|
"ImageId": "ami-08111162"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dummy_template_json = json.dumps(dummy_template)
|
dummy_template_json = json.dumps(dummy_template)
|
||||||
|
dummy_update_template_json = json.dumps(dummy_template)
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_boto3_create_stack():
|
def test_boto3_create_stack():
|
||||||
@ -169,6 +189,25 @@ def test_describe_deleted_stack():
|
|||||||
stack_by_id['StackName'].should.equal("test_stack")
|
stack_by_id['StackName'].should.equal("test_stack")
|
||||||
stack_by_id['StackStatus'].should.equal("DELETE_COMPLETE")
|
stack_by_id['StackStatus'].should.equal("DELETE_COMPLETE")
|
||||||
|
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_describe_updated_stack():
|
||||||
|
cf_conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||||
|
cf_conn.create_stack(
|
||||||
|
StackName="test_stack",
|
||||||
|
TemplateBody=dummy_template_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
cf_conn.update_stack(
|
||||||
|
StackName="test_stack",
|
||||||
|
TemplateBody=dummy_update_template_json)
|
||||||
|
|
||||||
|
stack = cf_conn.describe_stacks(StackName="test_stack")['Stacks'][0]
|
||||||
|
stack_id = stack['StackId']
|
||||||
|
stack_by_id = cf_conn.describe_stacks(StackName=stack_id)['Stacks'][0]
|
||||||
|
stack_by_id['StackId'].should.equal(stack['StackId'])
|
||||||
|
stack_by_id['StackName'].should.equal("test_stack")
|
||||||
|
stack_by_id['StackStatus'].should.equal("UPDATE_COMPLETE")
|
||||||
|
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_bad_describe_stack():
|
def test_bad_describe_stack():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user