From: Liang Chen Date: Tue, 3 Sep 2013 06:35:07 +0000 (+0800) Subject: Use the generic RequestLimitExceeded exception when possible X-Git-Tag: 2014.1~45^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=34e01f8c620326c8d9111aa08852ca57b669e369;p=openstack-build%2Fheat-build.git Use the generic RequestLimitExceeded exception when possible Rather than having lots of specific exceptions that all pertain to request limitation, we can just use the RequestLimitExceeded exception when applicable, which can also simplify the handling of exception mapping in fault.py. Change-Id: I61b1e59912087fad286e74c22af15ffe6382bb65 --- diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index ef3a685a..8f8083d5 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -71,6 +71,7 @@ class FaultWrapper(wsgi.Middleware): 'NotSupported': webob.exc.HTTPBadRequest, 'MissingCredentialError': webob.exc.HTTPBadRequest, 'UserParameterMissing': webob.exc.HTTPBadRequest, + 'RequestLimitExceeded': webob.exc.HTTPBadRequest, } def _error(self, ex): diff --git a/heat/common/exception.py b/heat/common/exception.py index bc175e80..22bc4f8e 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -302,10 +302,6 @@ class HTTPExceptionDisguise(Exception): self.tb = sys.exc_info()[2] -class TemplateTooBig(HeatException): - message = _('Template exceeds maximum allowed size.') - - class EgressRuleNotAllowed(HeatException): message = _("Egress rules are only allowed when " "Neutron is used and the 'VpcId' property is set.") @@ -324,13 +320,5 @@ class InvalidContentType(HeatException): message = "Invalid content type %(content_type)s" -class StackRecursionLimitReached(HeatException): - message = _("Recursion depth exceeds %d.") - - def __init__(self, recursion_depth): - self.message = self.message % recursion_depth - super(StackRecursionLimitReached, self).__init__() - - class RequestLimitExceeded(HeatException): message = _('Request limit exceeded: %(message)s') diff --git a/heat/common/template_format.py b/heat/common/template_format.py index a77b30dd..1e74b4a9 100644 --- a/heat/common/template_format.py +++ b/heat/common/template_format.py @@ -59,7 +59,8 @@ def parse(tmpl_str): JSON or YAML format. ''' if len(tmpl_str) > cfg.CONF.max_template_size: - raise exception.TemplateTooBig() + msg = _('Template exceeds maximum allowed size.') + raise exception.RequestLimitExceeded(message=msg) if tmpl_str.startswith('{'): tpl = json.loads(tmpl_str) else: diff --git a/heat/engine/stack_resource.py b/heat/engine/stack_resource.py index ca86cbab..0e15bddd 100644 --- a/heat/engine/stack_resource.py +++ b/heat/engine/stack_resource.py @@ -71,8 +71,9 @@ class StackResource(resource.Resource): Handle the creation of the nested stack from a given JSON template. ''' if self.recursion_depth >= cfg.CONF.max_nested_stack_depth: - raise exception.StackRecursionLimitReached( - cfg.CONF.max_nested_stack_depth) + msg = _("Recursion depth exceeds %d.") % \ + cfg.CONF.max_nested_stack_depth + raise exception.RequestLimitExceeded(message=msg) template = parser.Template(child_template) self._outputs_to_attribs(child_template) diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index 2dd2a676..20a46486 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -99,8 +99,10 @@ Outputs: {} limit = config.cfg.CONF.max_template_size long_yaml = yaml.safe_dump(template) self.assertTrue(len(long_yaml) > limit) - self.assertRaises(exception.TemplateTooBig, template_format.parse, - long_yaml) + ex = self.assertRaises(exception.RequestLimitExceeded, + template_format.parse, long_yaml) + msg = 'Request limit exceeded: Template exceeds maximum allowed size.' + self.assertEqual(msg, str(ex)) class JsonYamlResolvedCompareTest(HeatTestCase):