Skip to content

Commit

Permalink
[config] fix notify hooks
Browse files Browse the repository at this point in the history
Fix attribute type in notify hook methods in vnc_cfg_types and improve
retruned error in that methods.

Change-Id: I65eab626f9a8aeff361c9a02bc7416a7793de1e3
Closes-Bug: #1769959
(cherry picked from commit b2469a5)
  • Loading branch information
Édouard Thuleau committed Jul 26, 2018
1 parent 3d2a830 commit 1848f66
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 96 deletions.
86 changes: 38 additions & 48 deletions src/config/api-server/vnc_cfg_api_server/vnc_addr_mgmt.py
Expand Up @@ -900,22 +900,7 @@ def net_create_req(self, obj_dict):
alloc_pool_change=[])
# end net_create_req

def net_create_notify(self, obj_id):
db_conn = self._get_db_conn()
try:
(ok, result) = db_conn.dbe_read(
'virtual_network',
obj_id=obj_id,
obj_fields=['fq_name', 'network_ipam_refs'])
except cfgm_common.exceptions.NoIdError:
return

if not ok:
db_conn.config_log("Error: %s in net_create_notify" %(result),
level=SandeshLevel.SYS_ERR)
return

vn_dict = result
def net_create_notify(self, obj_id, vn_dict):
vn_fq_name_str = ':'.join(vn_dict['fq_name'])
self._create_net_subnet_objs(vn_fq_name_str, obj_id, vn_dict,
should_persist=False,
Expand Down Expand Up @@ -979,18 +964,15 @@ def net_update_req(self, vn_fq_name, db_vn_dict, req_vn_dict, obj_uuid=None):
def net_update_notify(self, obj_id):
db_conn = self._get_db_conn()
try:
(ok, result) = db_conn.dbe_read(
obj_type='virtual_network',
obj_id=obj_id,
obj_fields=['fq_name', 'network_ipam_refs'])
except cfgm_common.exceptions.NoIdError:
return

ok, result = db_conn.dbe_read(
obj_type='virtual_network',
obj_id=obj_id,
obj_fields=['fq_name', 'network_ipam_refs'],
)
except cfgm_common.exceptions.NoIdError as e:
return False, (404, str(e))
if not ok:
db_conn.config_log("Error: %s in net_update_notify" %(result),
level=SandeshLevel.SYS_ERR)
return

return False, result
vn_dict = result
vn_fq_name_str = ':'.join(vn_dict['fq_name'])

Expand All @@ -1008,6 +990,8 @@ def net_update_notify(self, obj_id):
self._create_net_subnet_objs(vn_fq_name_str, obj_id, vn_dict,
should_persist=False,
alloc_pool_change=[])

return True, ''
# end net_update_notify

def get_subnet_quota_counter(self, obj_dict, proj_dict, db_vn_dict=None):
Expand Down Expand Up @@ -2134,11 +2118,11 @@ def _ipam_ip_free_notify(self, ip_addr, vn_uuid, ipam_refs=None):
if not ipam_refs:
# Read in the VN
obj_fields=['network_ipam_refs']
(ok, vn_dict) = self._uuid_to_obj_dict('virtual_network', vn_uuid,
obj_fields)
ok, result = self._uuid_to_obj_dict('virtual_network', vn_uuid,
obj_fields)
if not ok:
raise cfgm_common.exceptions.VncError(vn_dict)
ipam_refs = vn_dict['network_ipam_refs']
raise False, result
ipam_refs = result['network_ipam_refs']

for ipam_ref in ipam_refs:
ipam_uuid = ipam_ref['uuid']
Expand All @@ -2147,9 +2131,9 @@ def _ipam_ip_free_notify(self, ip_addr, vn_uuid, ipam_refs=None):
subnet_obj = self._subnet_objs[ipam_uuid][subnet_name]
if subnet_obj.ip_belongs(ip_addr):
subnet_obj.ip_reset_in_use(ip_addr)
return True
return True, ''

return False
return True, ''
# end _ipam_ip_free_notify

def _net_ip_free_notify(self, ip_addr, vn_uuid):
Expand All @@ -2161,25 +2145,32 @@ def _net_ip_free_notify(self, ip_addr, vn_uuid):
return False
# end _net_ip_free_notify

def ip_free_notify(self, ip_addr, vn_fq_name, alloc_id=None, ipam_refs=None):
def ip_free_notify(self, ip_addr, vn_fq_name, alloc_id=None,
ipam_refs=None):
db_conn = self._get_db_conn()
if ipam_refs:
self._ipam_ip_free_notify(ip_addr, None, ipam_refs)
return
vn_uuid = db_conn.fq_name_to_uuid('virtual_network', vn_fq_name)
return self._ipam_ip_free_notify(ip_addr, None, ipam_refs)

try:
vn_uuid = db_conn.fq_name_to_uuid('virtual_network', vn_fq_name)
except cfgm_common.exceptions.NoIdError:
return False, (400, str(e))

if alloc_id:
# In case of inconsistency in the zk db, we should read and check
# the allocated IP belongs to the interface we are freing. If not
# the allocated IP belongs to the interface we are freeing. If not
# continuing to delete the interface and keeping the zk IP lock.
# That permits to recover from the zk inconsistency.
# https://bugs.launchpad.net/juniperopenstack/+bug/1702596
allocated_id = self.is_ip_allocated(ip_addr, vn_fq_name,
vn_uuid=vn_uuid)
if allocated_id is not None and alloc_id != allocated_id:
return
return True, ''

if not (self._net_ip_free_notify(ip_addr, vn_uuid)):
self._ipam_ip_free_notify(ip_addr, vn_uuid)
return self._ipam_ip_free_notify(ip_addr, vn_uuid)

return True, ''
# end _ip_free_notify

def mac_alloc(self, obj_dict):
Expand Down Expand Up @@ -2314,16 +2305,13 @@ def ipam_update_req(self, ipam_fq_name, db_ipam_dict, req_ipam_dict,
def ipam_update_notify(self, obj_id):
db_conn = self._get_db_conn()
try:
(ok, result) = db_conn.dbe_read('network_ipam', obj_id=obj_id)
except cfgm_common.exceptions.NoIdError:
return

ok, result = db_conn.dbe_read('network_ipam', obj_id=obj_id)
except cfgm_common.exceptions.NoIdError as e:
return False, (404, str(e))
if not ok:
db_conn.config_log("Error: %s in ipam_update_notify" %(result),
level=SandeshLevel.SYS_ERR)
return

return False, result
ipam_dict = result

ipam_fq_name_str = ':'.join(ipam_dict['fq_name'])
ipam_list_subnets = self._ipam_to_subnets(ipam_dict) or []
if obj_id in self._subnet_objs:
Expand All @@ -2337,6 +2325,8 @@ def ipam_update_notify(self, obj_id):

self._create_ipam_subnet_objs(obj_id, ipam_dict,
should_persist=False)

return True, ''
# end ipam_update_notify

def _ipam_is_gateway_ip(self, vn_dict, ip_addr):
Expand Down

0 comments on commit 1848f66

Please sign in to comment.