Merge "Unlimited option max_resources_per_stack"

This commit is contained in:
Jenkins 2015-06-05 19:08:38 +00:00 committed by Gerrit Code Review
commit dc32f99a68
4 changed files with 21 additions and 3 deletions

View File

@ -115,7 +115,8 @@ engine_opts = [
' delegated to heat when creating a stack.')),
cfg.IntOpt('max_resources_per_stack',
default=1000,
help=_('Maximum resources allowed per top-level stack.')),
help=_('Maximum resources allowed per top-level stack. '
'-1 stands for unlimited.')),
cfg.IntOpt('max_stacks_per_tenant',
default=100,
help=_('Maximum number of stacks any one tenant may have'

View File

@ -224,6 +224,8 @@ class StackResource(resource.Resource):
return parsed_template
def _validate_nested_resources(self, templ):
if cfg.CONF.max_resources_per_stack == -1:
return
root_stack_id = self.stack.root_stack_id()
total_resources = (len(templ[templ.RESOURCES]) +
self.stack.total_resources(root_stack_id))

View File

@ -574,8 +574,11 @@ class EngineService(service.Service):
" Please delete some stacks.") % tenant_limit
raise exception.RequestLimitExceeded(message=message)
max_resources = cfg.CONF.max_resources_per_stack
if max_resources == -1:
return
num_resources = len(parsed_template[parsed_template.RESOURCES])
if num_resources > cfg.CONF.max_resources_per_stack:
if num_resources > max_resources:
message = exception.StackResourceLimitExceeded.msg_fmt
raise exception.RequestLimitExceeded(message=message)
@ -757,7 +760,8 @@ class EngineService(service.Service):
current_stack.env,
args.get(rpc_api.PARAM_CLEAR_PARAMETERS, []))
tmpl = templatem.Template(template, files=files, env=env)
if len(tmpl[tmpl.RESOURCES]) > cfg.CONF.max_resources_per_stack:
max_resources = cfg.CONF.max_resources_per_stack
if max_resources != -1 and len(tmpl[tmpl.RESOURCES]) > max_resources:
raise exception.RequestLimitExceeded(
message=exception.StackResourceLimitExceeded.msg_fmt)
stack_name = current_stack.name

View File

@ -21,6 +21,7 @@ from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import properties
from heat.engine import resource as res
from heat.engine.resources.aws.ec2 import instance as instances
from heat.engine import service
from heat.engine import stack
from heat.engine import template as templatem
@ -339,3 +340,13 @@ class StackCreateTest(common.HeatTestCase):
ctx, stk)
self.assertEqual('Missing required credential: X-Auth-Key',
six.text_type(ex))
@mock.patch.object(instances.Instance, 'validate')
@mock.patch.object(stack.Stack, 'total_resources')
def test_stack_create_max_unlimited(self, total_res_mock, validate_mock):
total_res_mock.return_value = 9999
validate_mock.return_value = None
cfg.CONF.set_override('max_resources_per_stack', -1)
stack_name = 'service_create_test_max_unlimited'
stack = tools.get_stack(stack_name, self.ctx)
self.man.create_stack(self.ctx, stack_name, stack.t.t, {}, None, {})