]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Use the generic RequestLimitExceeded exception when possible
authorLiang Chen <cbjchen@cn.ibm.com>
Tue, 3 Sep 2013 06:35:07 +0000 (14:35 +0800)
committerLiang Chen <cbjchen@cn.ibm.com>
Fri, 13 Sep 2013 11:10:34 +0000 (19:10 +0800)
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

heat/api/middleware/fault.py
heat/common/exception.py
heat/common/template_format.py
heat/engine/stack_resource.py
heat/tests/test_template_format.py

index ef3a685a0cd9b2b42295914988152c597890d943..8f8083d5c0c51a471ecda7082d24504755290cc8 100644 (file)
@@ -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):
index bc175e8096478021b4bef60c40e9081ffdc838b9..22bc4f8ead92b81cb8d8261205daefb01400531e 100644 (file)
@@ -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')
index a77b30dd9b09fd9bcbc646751141e47e73a8f31a..1e74b4a98f449d642a2461a1986938c2bef8a2ba 100644 (file)
@@ -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:
index ca86cbab49b12494b3ae536627aa64436201097b..0e15bddd389fa8bbd444ab160caa35187f961eda 100644 (file)
@@ -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)
 
index 2dd2a6763c0a14e13c8b741db672dbf6f6704ebf..20a464861d727357201bf60e6463cab6da9f9e38 100644 (file)
@@ -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):