From 86865e0a2b1e8196226d3e411b76071ad4c58e77 Mon Sep 17 00:00:00 2001 From: Sachin Bansal Date: Fri, 5 Aug 2016 13:50:39 -0700 Subject: [PATCH] Fix subnet_key calculation 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 390287ec271cca2c90ebe18d24c4f0d808e2e3ea) --- .../vnc_openstack/vnc_openstack/__init__.py | 2 +- .../vnc_openstack/neutron_plugin_db.py | 21 +++++-------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/config/vnc_openstack/vnc_openstack/__init__.py b/src/config/vnc_openstack/vnc_openstack/__init__.py index c899ea97a8a..ca2843daa8d 100644 --- a/src/config/vnc_openstack/vnc_openstack/__init__.py +++ b/src/config/vnc_openstack/vnc_openstack/__init__.py @@ -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) diff --git a/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py b/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py index 3d31048e026..3c393fecd63 100644 --- a/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py +++ b/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py @@ -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 @@ -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()) @@ -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) @@ -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 @@ -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: @@ -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)