Skip to content

Commit

Permalink
Fix subnet_key calculation
Browse files Browse the repository at this point in the history
Two issues being fixed:
1. When subnet is added, we are adding an entry in kv-store to get
   the mapping from subnet uuid to key. In neutron backend, we
   calculate the key by converting prefix/len to IPNetwork and
   then converting it back to string values. While creating this
   mapping, we were directly using the supplied prefix and len.
   The former method could normalize ip v6 prefixes by stripping
   trailing 0 that may not be required. Fixed to use the same method
   in both places.
2. If subnet id is available, use it compare whenever possible to
   avoid the above issue.

Change-Id: Icee9fe8e77688427aa2fab415e059f7bdbd35e5d
Closes-Bug: 1596763
(cherry picked from commit 390287e)
  • Loading branch information
Sachin Bansal committed Aug 5, 2016
1 parent cc448ab commit 86865e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/config/vnc_openstack/vnc_openstack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def post_virtual_network_create(self, vn_dict):
prefix = subnet_dict['ip_prefix']
prefix_len = subnet_dict['ip_prefix_len']
network = IPNetwork('%s/%s' % (prefix, prefix_len))
subnet_name = vn_dict['uuid'] + ' ' + subnet_dict['ip_prefix'] + '/' + str(
subnet_name = vn_dict['uuid'] + ' ' + str(network.ip) + '/' + str(
subnet_dict['ip_prefix_len'])
subnet_uuid = ipam_subnet['subnet_uuid']
self._vnc_lib.kv_store(subnet_uuid, subnet_name)
Expand Down
21 changes: 5 additions & 16 deletions src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,14 +1428,7 @@ def _subnet_vnc_to_neutron(self, subnet_vnc, net_obj, ipam_fq_name):
sn_q_dict['cidr'] = cidr
sn_q_dict['ip_version'] = IPNetwork(cidr).version # 4 or 6

# read from useragent kv only for old subnets created
# before schema had uuid in subnet
sn_id = subnet_vnc.subnet_uuid
if not sn_id:
subnet_key = self._subnet_vnc_get_key(subnet_vnc, net_obj.uuid)
sn_id = self._subnet_vnc_read_mapping(id=subnet_vnc.subnet_uuid,
key=subnet_key)

sn_q_dict['id'] = sn_id

sn_q_dict['gateway_ip'] = subnet_vnc.default_gateway
Expand Down Expand Up @@ -2222,8 +2215,7 @@ def _port_check_and_add_iface_route_table(self, fixed_ips, net_obj,
host_routes = subnet.get_host_routes()
if host_routes is None:
continue
subnet_key = self._subnet_vnc_get_key(subnet, net_obj.uuid)
sn_id = self._subnet_vnc_read_mapping(key=subnet_key)
sn_id = subnet.subnet_uuid
subnet_cidr = '%s/%s' % (subnet.subnet.get_ip_prefix(),
subnet.subnet.get_ip_prefix_len())

Expand Down Expand Up @@ -2623,7 +2615,7 @@ def subnet_create(self, subnet_q):
else: # virtual-network already linked to this ipam
for subnet in net_ipam_ref['attr'].get_ipam_subnets():
if subnet_key == self._subnet_vnc_get_key(subnet, net_id):
existing_sn_id = self._subnet_vnc_read_mapping(key=subnet_key)
existing_sn_id = subnet.subnet_uuid
# duplicate !!
msg = _("Cidr %s overlaps with another subnet of subnet %s"
) % (subnet_q['cidr'], existing_sn_id)
Expand Down Expand Up @@ -2662,8 +2654,7 @@ def subnet_read(self, subnet_id):
for ipam_ref in ipam_refs:
subnet_vncs = ipam_ref['attr'].get_ipam_subnets()
for subnet_vnc in subnet_vncs:
if (self._subnet_vnc_get_key(subnet_vnc, net_id) ==
subnet_key):
if subnet_vnc.subnet_uuid == subnet_id:
ret_subnet_q = self._subnet_vnc_to_neutron(
subnet_vnc, net_obj, ipam_ref['to'])
return ret_subnet_q
Expand Down Expand Up @@ -2698,8 +2689,7 @@ def subnet_update(self, subnet_id, subnet_q):
for ipam_ref in ipam_refs:
subnets = ipam_ref['attr'].get_ipam_subnets()
for subnet_vnc in subnets:
if self._subnet_vnc_get_key(subnet_vnc,
net_id) == subnet_key:
if subnet_vnc.subnet_uuid == subnet_id:
subnet_found = True
break
if subnet_found:
Expand Down Expand Up @@ -2770,8 +2760,7 @@ def subnet_delete(self, subnet_id):
for ipam_ref in ipam_refs:
orig_subnets = ipam_ref['attr'].get_ipam_subnets()
new_subnets = [subnet_vnc for subnet_vnc in orig_subnets
if self._subnet_vnc_get_key(subnet_vnc,
net_id) != subnet_key]
if subnet_vnc.subnet_uuid != subnet_id]
if len(orig_subnets) != len(new_subnets):
# matched subnet to be deleted
ipam_ref['attr'].set_ipam_subnets(new_subnets)
Expand Down

0 comments on commit 86865e0

Please sign in to comment.