From 7064505f322c95b12704a2daba412ffb4ec008b2 Mon Sep 17 00:00:00 2001 From: Saju Madhavan Date: Fri, 10 Jun 2016 00:45:48 +0530 Subject: [PATCH] contrail raises wrong quota exception I added a new exception named OverQuota to raise on quota hit.Also added new status code 412 to catch and raise new quota exception.I also have path in contrail-neutron-plugin to catch this new OverQuota exception. Change-Id: I6f0e6844006c5822c28fd92af73e22fbbfac4d2f Closes-Bug: #1590930 --- src/api-lib/vnc_api.py | 2 ++ src/config/api-server/vnc_cfg_types.py | 6 ++--- src/config/api-server/vnc_quota.py | 3 ++- src/config/common/exceptions.py | 3 +++ .../vnc_openstack/neutron_plugin_db.py | 23 +++++++++++++------ 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/api-lib/vnc_api.py b/src/api-lib/vnc_api.py index 28cc39dbb09..83c1ccba396 100644 --- a/src/api-lib/vnc_api.py +++ b/src/api-lib/vnc_api.py @@ -753,6 +753,8 @@ def _request(self, op, url, data=None, retry_on_error=True, % (op, url, data, content)) elif status == 403: raise PermissionDenied(content) + elif status == 412: + raise OverQuota(content) elif status == 409: raise RefsExistError(content) elif status == 504: diff --git a/src/config/api-server/vnc_cfg_types.py b/src/config/api-server/vnc_cfg_types.py index 51ca0c40492..cf108f779d6 100644 --- a/src/config/api-server/vnc_cfg_types.py +++ b/src/config/api-server/vnc_cfg_types.py @@ -992,7 +992,7 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs): (ok, result) = cls.addr_mgmt.net_check_subnet_quota(read_result, obj_dict, db_conn) if not ok: - return (ok, (403, result)) + return (ok, (vnc_quota.QUOTA_OVER_ERROR_CODE, result)) (ok, result) = cls.addr_mgmt.net_check_subnet_overlap(obj_dict) if not ok: return (ok, (409, result)) @@ -1524,7 +1524,7 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs): (ok, quota_limit) = QuotaHelper.check_quota_limit( proj_dict, obj_type, rule_count-1) if not ok: - return (False, (403, pformat(fq_name) + ' : ' + quota_limit)) + return (False, (vnc_quota.QUOTA_OVER_ERROR_CODE, pformat(fq_name) + ' : ' + quota_limit)) return _check_policy_rules(obj_dict.get('security_group_entries')) # end pre_dbe_update @@ -1777,7 +1777,7 @@ def pre_dbe_create(cls, tenant_name, obj_dict, db_conn): (ok, quota_limit) = QuotaHelper.check_quota_limit( proj_dict, 'loadbalancer-member', quota_count) if not ok: - return (False, (403, pformat(fq_name) + ' : ' + quota_limit)) + return (False, (vnc_quota.QUOTA_OVER_ERROR_CODE, pformat(fq_name) + ' : ' + quota_limit)) return True, "" diff --git a/src/config/api-server/vnc_quota.py b/src/config/api-server/vnc_quota.py index 5242a5bae43..7ed77046ac1 100644 --- a/src/config/api-server/vnc_quota.py +++ b/src/config/api-server/vnc_quota.py @@ -3,6 +3,7 @@ from pprint import pformat import cfgm_common.exceptions +QUOTA_OVER_ERROR_CODE = 412 class QuotaHelper(object): @@ -81,6 +82,6 @@ def verify_quota_for_resource(cls, db_conn, resource, obj_type, if quota_count >= quota_limit: msg = ('quota limit (%d) exceeded for resource %s' % (quota_limit, obj_type)) - return (False, (403, pformat(fq_name) + ' : ' + msg)) + return (False, (QUOTA_OVER_ERROR_CODE, pformat(fq_name) + ' : ' + msg)) return True, "" diff --git a/src/config/common/exceptions.py b/src/config/common/exceptions.py index 9c5a085d318..2d8fcb0eb1c 100644 --- a/src/config/common/exceptions.py +++ b/src/config/common/exceptions.py @@ -108,6 +108,9 @@ class PermissionDenied(VncError): pass # end class PermissionDenied +class OverQuota(VncError): + pass +# end class OverQuota class RefsExistError(VncError): pass diff --git a/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py b/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py index 0ff16c91f14..704d77d8d97 100644 --- a/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py +++ b/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py @@ -212,6 +212,9 @@ def _security_group_rule_create(self, sg_id, sg_rule): except PermissionDenied as e: self._raise_contrail_exception('BadRequest', resource='security_group_rule', msg=str(e)) + except OverQuota as e: + self._raise_contrail_exception('OverQuota', + resource='security_group_rule', msg=str(e)) except RefsExistError as e: try: rule_uuid = str(e).split(':')[1].strip() @@ -281,16 +284,19 @@ def _route_table_delete(self, rt_id): def _resource_create(self, resource_type, obj): create_method = getattr(self._vnc_lib, resource_type + '_create') try: - obj_uuid = create_method(obj) - except RefsExistError: - obj.uuid = str(uuid.uuid4()) - obj.name += '-' + obj.uuid - obj.fq_name[-1] += '-' + obj.uuid - obj_uuid = create_method(obj) + try: + obj_uuid = create_method(obj) + except RefsExistError: + obj.uuid = str(uuid.uuid4()) + obj.name += '-' + obj.uuid + obj.fq_name[-1] += '-' + obj.uuid + obj_uuid = create_method(obj) except (PermissionDenied, BadRequest) as e: self._raise_contrail_exception('BadRequest', resource=resource_type, msg=str(e)) - + except OverQuota as e: + self._raise_contrail_exception('OverQuota', + resource=resource_type, msg=str(e)) return obj_uuid #end _resource_create @@ -3357,6 +3363,9 @@ def floatingip_create(self, context, fip_q): resource='floatingip', msg=msg) try: fip_uuid = self._vnc_lib.floating_ip_create(fip_obj) + except OverQuota as e: + self._raise_contrail_exception('OverQuota', + resource='floatingip', msg=str(e)) except Exception as e: self._raise_contrail_exception('IpAddressGenerationFailure', net_id=fip_q['floating_network_id'])