Skip to content

Commit

Permalink
This will check if allocation-pool is already added in another vrouter
Browse files Browse the repository at this point in the history
if alloc-pool is already added in existing vrouter-ipam link, it is not
allowed to another vrouter on the same ipam
Closes-Bug: #1728542

Change-Id: Ic2fbe91626a76980f071153e251c5db54dca35db
  • Loading branch information
moghea committed Nov 2, 2017
1 parent b0c0c04 commit e469cab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/config/api-server/tests/test_ip_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,19 @@ def test_flat_ipam_vrouter_allocation_pools(self):
except cfgm_common.exceptions.BadRequest:
logger.debug('Can not Delete allocation pool, ip-addr in use')

# try creating another vrouter but with already used allocation-pool
# create a vr_ipam_type2 with same allocation pool as in vr_ipam_type1
# vrouter create should fail in exception
vr1_uuid = vr1.uuid
vr2 = VirtualRouter('vrouter2', global_sys_config)
vr_ipam_type2 = VirtualRouterNetworkIpamType(vr_pool_list1, [])
vr_ipam_type2.set_allocation_pools(vr_pool_list1)
vr2.add_network_ipam(ipam0, vr_ipam_type2)
with ExpectedException(cfgm_common.exceptions.BadRequest,
'vrouter allocation-pool start:13.1.1.24, end:13.1.1.25 is'
' used in other vrouter:%s' %(vr1_uuid)) as e:
self._vnc_lib.virtual_router_create(vr2)

#cleanup
self._vnc_lib.instance_ip_delete(id=ipv4_id5)
self._vnc_lib.instance_ip_delete(id=ipv4_id4)
Expand Down
26 changes: 25 additions & 1 deletion src/config/api-server/vnc_cfg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,11 +2018,13 @@ def _validate_vrouter_alloc_pools(cls, vrouter_dict, db_conn, ipam_refs):
if not ipam_refs:
return True, ''

vrouter_uuid = vrouter_dict['uuid']
ipam_uuid_list = [(ipam_ref['uuid']) for ipam_ref in ipam_refs]
(ok, ipam_list, _) = db_conn.dbe_list('network_ipam',
obj_uuids=ipam_uuid_list,
field_names=['ipam_subnet_method',
'ipam_subnets'])
'ipam_subnets',
'virtual_router_back_refs'])
if not ok:
return (ok, 400, 'Error in dbe_list: %s' % pformat(ipam_list))

Expand Down Expand Up @@ -2075,6 +2077,28 @@ def _validate_vrouter_alloc_pools(cls, vrouter_dict, db_conn, ipam_refs):
'not in ipam' %(vr_alloc_pool['start'],
vr_alloc_pool['end']))

if 'virtual_router_back_refs' not in ipam:
continue

vr_back_refs = ipam['virtual_router_back_refs']
for vr_back_ref in vr_back_refs:
if vr_back_ref['uuid'] == vrouter_uuid:
continue

back_ref_ipam_data = vr_back_ref['attr']
bref_alloc_pools = back_ref_ipam_data.get('allocation_pools')
if not bref_alloc_pools:
continue

for vr_alloc_pool in vr_alloc_pools:
if vr_alloc_pool in bref_alloc_pools:
return (False,
'vrouter allocation-pool start:%s, end:%s '
'is used in other vrouter:%s'
%(vr_alloc_pool['start'],
vr_alloc_pool['end'],
vr_back_ref['uuid']))

return True, ''

@classmethod
Expand Down

0 comments on commit e469cab

Please sign in to comment.