Merge pull request #634 from SplunkStorm/fix_cfn_error_message_and_delete_stack

Fix cfn error message and delete stack
This commit is contained in:
Steve Pulec 2016-06-17 18:03:23 -04:00 committed by GitHub
commit b6d7260f7f
3 changed files with 36 additions and 9 deletions

View File

@ -11,7 +11,7 @@ class UnformattedGetAttTemplateException(Exception):
class ValidationError(BadRequest):
def __init__(self, name_or_id, message=None):
if message is None:
messgae="Stack:{0} does not exist".format(name_or_id),
message="Stack:{0} does not exist".format(name_or_id),
template = Template(ERROR_RESPONSE)
super(ValidationError, self).__init__()

View File

@ -403,19 +403,18 @@ class ResourceMap(collections.Mapping):
while remaining_resources and tries < 5:
for resource in remaining_resources.copy():
parsed_resource = self._parsed_resources.get(resource)
if parsed_resource:
try:
try:
if parsed_resource and hasattr(parsed_resource, 'delete'):
parsed_resource.delete(self._region_name)
except Exception as e:
# skip over dependency violations, and try again in a second pass
last_exception = e
else:
remaining_resources.remove(resource)
except Exception as e:
# skip over dependency violations, and try again in a second pass
last_exception = e
else:
remaining_resources.remove(resource)
tries += 1
if tries == 5:
raise last_exception
class OutputMap(collections.Mapping):
def __init__(self, resources, template):
self._template = template

View File

@ -27,8 +27,23 @@ dummy_template2 = {
"Resources": {},
}
# template with resource which has no delete attribute defined
dummy_template3 = {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Stack 3",
"Resources": {
"VPC": {
"Properties": {
"CidrBlock": "192.168.0.0/16",
},
"Type": "AWS::EC2::VPC"
}
},
}
dummy_template_json = json.dumps(dummy_template)
dummy_template_json2 = json.dumps(dummy_template2)
dummy_template_json3 = json.dumps(dummy_template3)
@mock_cloudformation
@ -220,6 +235,19 @@ def test_delete_stack_by_id():
conn.describe_stacks(stack_id).should.have.length_of(1)
@mock_cloudformation
def test_delete_stack_with_resource_missing_delete_attr():
conn = boto.connect_cloudformation()
conn.create_stack(
"test_stack",
template_body=dummy_template_json3,
)
conn.list_stacks().should.have.length_of(1)
conn.delete_stack("test_stack")
conn.list_stacks().should.have.length_of(0)
@mock_cloudformation
def test_bad_describe_stack():
conn = boto.connect_cloudformation()