Merge "Stop nested stack updates exceeding resource limit"

This commit is contained in:
Jenkins 2013-09-25 07:48:46 +00:00 committed by Gerrit Code Review
commit 6bbdb23c75
2 changed files with 87 additions and 0 deletions

View File

@ -125,6 +125,13 @@ class StackResource(resource.Resource):
# on updated templates we should make sure it's optional because not
# all subclasses want that behavior, since they may offer custom
# attributes.
nested_stack = self.nested()
if nested_stack is not None:
res_diff = (
len(template[tmpl.RESOURCES]) - len(nested_stack.resources))
new_size = nested_stack.root_stack.total_resources() + res_diff
if new_size > cfg.CONF.max_resources_per_stack:
raise exception.StackResourceLimitExceeded()
# Note we disable rollback for nested stacks, since they
# should be rolled back by the parent stack on failure

View File

@ -206,6 +206,86 @@ Outputs:
self.m.VerifyAll()
def test_nested_stack_update_equals_resource_limit(self):
resource._register_class('GenericResource',
generic_rsrc.GenericResource)
urlfetch.get('https://server.test/the.template').MultipleTimes().\
AndReturn(self.nested_template)
urlfetch.get('https://server.test/new.template').MultipleTimes().\
AndReturn('''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
KeyName:
Type: String
Resources:
NestedResource:
Type: GenericResource
Outputs:
Bar:
Value: foo
''')
self.m.ReplayAll()
stack = self.create_stack(self.test_template)
cfg.CONF.set_override('max_resources_per_stack', 2)
rsrc = stack['the_nested']
original_nested_id = rsrc.resource_id
t = template_format.parse(self.test_template)
new_res = copy.deepcopy(t['Resources']['the_nested'])
new_res['Properties']['TemplateURL'] = (
'https://server.test/new.template')
prop_diff = {'TemplateURL': 'https://server.test/new.template'}
updater = rsrc.handle_update(new_res, {}, prop_diff)
updater.run_to_completion()
self.assertEqual(True, rsrc.check_update_complete(updater))
self.assertEqual('foo', rsrc.FnGetAtt('Outputs.Bar'))
rsrc.delete()
self.m.VerifyAll()
def test_nested_stack_update_exceeds_limit(self):
resource._register_class('GenericResource',
generic_rsrc.GenericResource)
urlfetch.get('https://server.test/the.template').MultipleTimes().\
AndReturn(self.nested_template)
urlfetch.get('https://server.test/new.template').MultipleTimes().\
AndReturn('''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
KeyName:
Type: String
Resources:
NestedResource:
Type: GenericResource
Outputs:
Bar:
Value: foo
''')
self.m.ReplayAll()
stack = self.create_stack(self.test_template)
cfg.CONF.set_override('max_resources_per_stack', 1)
rsrc = stack['the_nested']
original_nested_id = rsrc.resource_id
t = template_format.parse(self.test_template)
new_res = copy.deepcopy(t['Resources']['the_nested'])
new_res['Properties']['TemplateURL'] = (
'https://server.test/new.template')
prop_diff = {'TemplateURL': 'https://server.test/new.template'}
self.assertRaises(exception.StackResourceLimitExceeded,
rsrc.handle_update, new_res, {}, prop_diff)
rsrc.delete()
self.m.VerifyAll()
def test_nested_stack_suspend_resume(self):
urlfetch.get('https://server.test/the.template').AndReturn(
self.nested_template)