]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Readjust try/catch block in quantum.api.v2.base.create()
authorZhongyue Luo <zhongyue.nah@intel.com>
Mon, 24 Dec 2012 06:15:21 +0000 (14:15 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 31 Dec 2012 02:27:03 +0000 (10:27 +0800)
Removed the outer try/catch block to handle all exceptions in one block.
Moved irrelevant statements out of the block

Change-Id: I5c248403b8419f664ef6f17e70a016e7c0cd4ae6

quantum/api/v2/base.py

index 8a9eb58e6443edd50d347f0a1b3155a7e8834394..de462ac50381a48f07593677aa0802e089929c4b 100644 (file)
@@ -1,17 +1,19 @@
-# Copyright (c) 2012 OpenStack, LLC.
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 OpenStack LLC.
+# All Rights Reserved.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
 #
-#    http://www.apache.org/licenses/LICENSE-2.0
+#         http://www.apache.org/licenses/LICENSE-2.0
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
 
 import netaddr
 import webob.exc
@@ -287,45 +289,39 @@ class Controller(object):
                                                allow_bulk=self._allow_bulk)
         action = self._plugin_handlers[self.CREATE]
         # Check authz
-        try:
-            if self._collection in body:
-                # Have to account for bulk create
-                items = body[self._collection]
-                deltas = {}
-                bulk = True
-            else:
-                items = [body]
-                bulk = False
-            for item in items:
-                self._validate_network_tenant_ownership(request,
-                                                        item[self._resource])
-                policy.enforce(request.context,
-                               action,
-                               item[self._resource],
-                               plugin=self._plugin)
-                try:
-                    tenant_id = item[self._resource]['tenant_id']
-                    count = QUOTAS.count(request.context, self._resource,
-                                         self._plugin, self._collection,
-                                         tenant_id)
-                    if bulk:
-                        delta = deltas.get(tenant_id, 0) + 1
-                        deltas[tenant_id] = delta
-                    else:
-                        delta = 1
-                    kwargs = {self._resource: count + delta}
-                except exceptions.QuotaResourceUnknown as e:
-                    # We don't want to quota this resource
-                    LOG.debug(e)
-                except Exception:
-                    raise
+        if self._collection in body:
+            # Have to account for bulk create
+            items = body[self._collection]
+            deltas = {}
+            bulk = True
+        else:
+            items = [body]
+            bulk = False
+        for item in items:
+            self._validate_network_tenant_ownership(request,
+                                                    item[self._resource])
+            policy.enforce(request.context,
+                           action,
+                           item[self._resource],
+                           plugin=self._plugin)
+            try:
+                tenant_id = item[self._resource]['tenant_id']
+                count = QUOTAS.count(request.context, self._resource,
+                                     self._plugin, self._collection,
+                                     tenant_id)
+                if bulk:
+                    delta = deltas.get(tenant_id, 0) + 1
+                    deltas[tenant_id] = delta
                 else:
-                    QUOTAS.limit_check(request.context,
-                                       item[self._resource]['tenant_id'],
-                                       **kwargs)
-        except exceptions.PolicyNotAuthorized:
-            LOG.exception(_("Create operation not authorized"))
-            raise webob.exc.HTTPForbidden()
+                    delta = 1
+                kwargs = {self._resource: count + delta}
+            except exceptions.QuotaResourceUnknown as e:
+                # We don't want to quota this resource
+                LOG.debug(e)
+            else:
+                QUOTAS.limit_check(request.context,
+                                   item[self._resource]['tenant_id'],
+                                   **kwargs)
 
         def notify(create_result):
             notifier_api.notify(request.context,