Skip to content

Commit

Permalink
Do not read subnet-uuid from useragent kv if not necessary.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Hampapur Ajay committed Feb 4, 2015
1 parent 65285f8 commit a7bdf2f
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Expand Up @@ -770,16 +770,44 @@ 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)
return subnet_key
except NoIdError:
self._raise_contrail_exception('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('SubnetNotFound',
subnet_id=id)
# persist to avoid this calculation later
self._subnet_vnc_create_mapping(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)
return subnet_id

#end _subnet_vnc_read_mapping
Expand Down Expand Up @@ -807,7 +835,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:
Expand Down Expand Up @@ -1332,9 +1361,13 @@ 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

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

Expand Down Expand Up @@ -2415,7 +2448,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)

Expand Down

0 comments on commit a7bdf2f

Please sign in to comment.