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: I02fdf80b04999f995ab34d00c4d18605648229d6
Closes-Bug: #1590930
  • Loading branch information
sajuptpm committed Jun 9, 2016
1 parent 646dddb commit 2641107
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 @@ -544,6 +544,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 @@ -572,7 +572,7 @@ def http_put(cls, id, fq_name, obj_dict, db_conn):
(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(read_result,
obj_dict)
if not ok:
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def http_put(cls, id, fq_name, obj_dict, db_conn):
(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 http_put
Expand Down Expand Up @@ -1364,7 +1364,7 @@ def http_post_collection(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 @@ -217,6 +217,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))
return
#end _security_group_rule_create

Expand Down Expand Up @@ -279,16 +282,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

Expand Down Expand Up @@ -3426,6 +3432,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'])
Expand Down

0 comments on commit 2641107

Please sign in to comment.