Skip to content

Commit

Permalink
contrail raises wrong quota exception
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sajuptpm committed Jun 20, 2016
1 parent 7f3348d commit 186aeb7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/api-lib/vnc_api.py
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -996,7 +996,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))
Expand Down Expand Up @@ -1525,7 +1525,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
Expand Down Expand Up @@ -1778,7 +1778,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, ""

Expand Down
3 changes: 2 additions & 1 deletion src/config/api-server/vnc_quota.py
Expand Up @@ -4,6 +4,7 @@
from pprint import pformat
import cfgm_common.exceptions

QUOTA_OVER_ERROR_CODE = 412

class QuotaHelper(object):

Expand Down Expand Up @@ -82,6 +83,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, ""
3 changes: 3 additions & 0 deletions src/config/common/exceptions.py
Expand Up @@ -108,6 +108,9 @@ class PermissionDenied(VncError):
pass
# end class PermissionDenied

class OverQuota(VncError):
pass
# end class OverQuota

class RefsExistError(VncError):
pass
Expand Down
23 changes: 16 additions & 7 deletions src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Expand Up @@ -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',
overs=['security_group_rule'], msg=str(e))
except RefsExistError as e:
try:
rule_uuid = str(e).split(':')[1].strip()
Expand Down Expand Up @@ -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',
overs=[resource_type], msg=str(e))
return obj_uuid
#end _resource_create

Expand Down Expand Up @@ -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',
overs=['floatingip'], msg=str(e))
except Exception as e:
self._raise_contrail_exception('IpAddressGenerationFailure',
net_id=fip_q['floating_network_id'])
Expand Down

0 comments on commit 186aeb7

Please sign in to comment.