From 5b753500d0d2f652488c981d14e7f63aa6717542 Mon Sep 17 00:00:00 2001 From: Hampapur Ajay Date: Thu, 22 Jan 2015 21:39:00 -0800 Subject: [PATCH] Do not read subnet-uuid from useragent kv if not necessary. Since we don't check+store in useragent-kv for subnet mapping in common case, handle this when neutron is asked about a subnet it doesn't know (created by contrail API/UI) and do the mapping store in the exception case. Change-Id: Ia5531059b3eaecc3cff2bf5a3de671aad0a17bc3 Closes-Bug: #1413864 (cherry picked from commit a7bdf2fee2a8b8ba916a2e62a8317fb851b407a7) --- .../vnc_openstack/neutron_plugin_db.py | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) 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 8bd18adf24a..73608b3d97e 100644 --- a/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py +++ b/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py @@ -1163,16 +1163,46 @@ def _subnet_vnc_create_mapping(self, subnet_id, subnet_key): #end _subnet_vnc_create_mapping def _subnet_vnc_read_mapping(self, id=None, key=None): + def _subnet_id_to_key(): + all_net_objs = self._virtual_network_list(detail=True) + for net_obj in all_net_objs: + ipam_refs = net_obj.get_network_ipam_refs() + net_uuid = net_obj.uuid + for ipam_ref in ipam_refs: + subnet_vncs = ipam_ref['attr'].get_ipam_subnets() + for subnet_vnc in subnet_vncs: + if subnet_vnc.subnet_uuid == id: + return self._subnet_vnc_get_key(subnet_vnc, + net_uuid) + return None + # _subnet_id_to_key + if id: try: subnet_key = self._vnc_lib.kv_retrieve(id) - self._db_cache['q_subnet_maps'][id] = subnet_key - return subnet_key except NoIdError: - self._raise_contrail_exception(404, exceptions.SubnetNotFound(subnet_id=id)) + # contrail UI/api might have been used to create the subnet, + # create id to key mapping now/here. + subnet_key = _subnet_id_to_key() + if not subnet_key: + self._raise_contrail_exception(404, exceptions.SubnetNotFound(subnet_id=id)) + # persist to avoid this calculation later + self._subnet_vnc_create_mapping(id, subnet_key) + + self._db_cache['q_subnet_maps'][id] = subnet_key + return subnet_key if key: - subnet_id = self._vnc_lib.kv_retrieve(key) + try: + subnet_id = self._vnc_lib.kv_retrieve(key) + except NoIdError: + # contrail UI/api might have been used to create the subnet, + # create key to id mapping now/here. + subnet_vnc = self._subnet_read(key) + subnet_id = subnet_vnc.uuid + # persist to avoid this calculation later + self._subnet_vnc_create_mapping(subnet_id, key) + self._db_cache['q_subnet_maps'][key] = subnet_id return subnet_id @@ -1206,7 +1236,8 @@ def _subnet_vnc_get_key(self, subnet_vnc, net_id): return '%s %s/%s' % (net_id, str(network.ip), pfx_len) #end _subnet_vnc_get_key - def _subnet_read(self, net_uuid, subnet_key): + def _subnet_read(self, subnet_key): + net_uuid = subnet_key.split(' ')[0] try: net_obj = self._virtual_network_read(net_id=net_uuid) except NoIdError: @@ -1730,9 +1761,13 @@ def _subnet_vnc_to_neutron(self, subnet_vnc, net_obj, ipam_fq_name): subnet_vnc.subnet.get_ip_prefix_len()) sn_q_dict['cidr'] = cidr - subnet_key = self._subnet_vnc_get_key(subnet_vnc, net_obj.uuid) - sn_id = self._subnet_vnc_read_or_create_mapping(id=subnet_vnc.subnet_uuid, - key=subnet_key) + # 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_or_create_mapping(id=subnet_vnc.subnet_uuid, + key=subnet_key) sn_q_dict['id'] = sn_id @@ -2840,7 +2875,7 @@ def subnet_create(self, subnet_q): self._subnet_vnc_create_mapping(subnet_id, subnet_key) # Read in subnet from server to get updated values for gw etc. - subnet_vnc = self._subnet_read(net_obj.uuid, subnet_key) + subnet_vnc = self._subnet_read(subnet_key) subnet_info = self._subnet_vnc_to_neutron(subnet_vnc, net_obj, ipam_fq_name)