Skip to content

Commit

Permalink
Added support for pre_dbe_create and resource exhaustion error
Browse files Browse the repository at this point in the history
partial-jira-bug: CEM-15158

1. AE-IDs can not be allocated during pre_dbe_create of VPG
   as the existing infra creates refs internally
   so added an exception when PI refs are sent along during
   VPG create. VPG must be created before adding PIs to them
2. Added Resource Exhaustion exception when more than
   supported AE-IDs are requested
3. Added UTs for all these usecases

Change-Id: Id0132b3f05b8bd5b85ff7dd4174945055875d3b2
  • Loading branch information
snmurali committed Jul 14, 2020
1 parent 0a700de commit 035d119
Show file tree
Hide file tree
Showing 2 changed files with 359 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from cfgm_common.exceptions import HttpError
from cfgm_common.exceptions import NoIdError
from cfgm_common.exceptions import ResourceExhaustionError
from pysandesh.gen_py.sandesh.ttypes import SandeshLevel
from vnc_api.gen.resource_common import VirtualPortGroup
from vnc_api.gen.resource_xsd import VpgInterfaceParametersType
Expand Down Expand Up @@ -39,15 +40,21 @@ def _notify_ae_id_modified(cls, obj_dict=None, notify=False):

@classmethod
def _alloc_ae_id(cls, prouter_name, vpg_name):
pi_ae = cls.vnc_zk_client.alloc_ae_id(prouter_name, vpg_name)
try:
pi_ae = cls.vnc_zk_client.alloc_ae_id(prouter_name, vpg_name)
except ResourceExhaustionError as exc:
err_msg = ('ResourceExhaustionError: when allocating AE-ID for '
'virtual-port-group (%s) at physical-router (%s)' % (
vpg_name, prouter_name))
return False, (400, err_msg)
attr_obj = VpgInterfaceParametersType(pi_ae)
attr_dict = attr_obj.__dict__
alloc_dict = {
'ae_id': pi_ae,
'prouter_name': prouter_name,
'vpg_name': vpg_name,
}
return attr_dict, alloc_dict
return True, (attr_dict, alloc_dict)

@classmethod
def _dealloc_ae_id(cls, prouter_name, ae_id, vpg_name):
Expand Down Expand Up @@ -108,7 +115,10 @@ def _process_alloc_ae_id(cls, db_obj_dict, vpg_name, obj_dict=None):
pi_ae = db_pr_dict.get(pi_pr)
if pi_ae is None:
# allocate
attr_dict, _alloc_dict = cls._alloc_ae_id(pi_pr, vpg_name)
ok, result = cls._alloc_ae_id(pi_pr, vpg_name)
if not ok:
return ok, result
attr_dict, _alloc_dict = result
alloc_dealloc_dict['allocated_ae_id'].append(_alloc_dict)
msg = "Allocating AE-ID(%s) for PI(%s) at VPG(%s)/PR(%s)" % (
attr_dict, pi_uuid, vpg_name, pi_pr)
Expand All @@ -122,7 +132,10 @@ def _process_alloc_ae_id(cls, db_obj_dict, vpg_name, obj_dict=None):
if (db_pi_dict.values()[0] != curr_pi_dict.get(create_pi_uuids[0])):
# allocate a new ae-id as it belongs to different PR
db_pr = db_pi_dict.values()[0]
attr_dict_leftover_pi, _alloc_dict = cls._alloc_ae_id(db_pr, vpg_name)
ok, result = cls._alloc_ae_id(db_pr, vpg_name)
if not ok:
return ok, result
attr_dict_leftover_pi, _alloc_dict = result
alloc_dealloc_dict['allocated_ae_id'].append(_alloc_dict)
msg = "Allocating AE-ID(%s) for PI(%s) at VPG(%s)/PR(%s)" % (
attr_dict_leftover_pi, db_pi_uuid, vpg_name, db_pr)
Expand Down Expand Up @@ -298,7 +311,7 @@ def update_physical_intf_type(cls, obj_dict=None,
# end update_physical_intf_type

@classmethod
def pre_dbe_create(cls, tenant_name, obj_dict, db_conn):
def pre_dbe_create(cls, tenant_name, obj_dict, db_conn, **kwargs):
ret_val = ''
if ('vpg-internal' in obj_dict['fq_name'][2] and
obj_dict.get('virtual_port_group_user_created', True)):
Expand Down
Loading

0 comments on commit 035d119

Please sign in to comment.