From: Zhongyue Luo Date: Mon, 24 Dec 2012 06:15:21 +0000 (+0800) Subject: Readjust try/catch block in quantum.api.v2.base.create() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=012e47f820f1e213297c687f17159794e371823e;p=openstack-build%2Fneutron-build.git Readjust try/catch block in quantum.api.v2.base.create() Removed the outer try/catch block to handle all exceptions in one block. Moved irrelevant statements out of the block Change-Id: I5c248403b8419f664ef6f17e70a016e7c0cd4ae6 --- diff --git a/quantum/api/v2/base.py b/quantum/api/v2/base.py index 8a9eb58e6..de462ac50 100644 --- a/quantum/api/v2/base.py +++ b/quantum/api/v2/base.py @@ -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,