Skip to content

Commit

Permalink
If the API client updates a network object with subnets and does not …
Browse files Browse the repository at this point in the history
…send a subnet_uuid, we were allocating a new UUID. If the subnet already exists, we should reuse the subnet_uuid. Now, we read from cassandra before generating a new UUID.

Change-Id: I13426663c8a2a8e79fbf170dffb81c726506cee1
Closes-Bug: 1381779
(cherry picked from commit c2f71af5f2e9a6f31ce65e48c0e4a4c62e82f0c8)
  • Loading branch information
Sachin Bansal committed Oct 15, 2014
1 parent 8dadd77 commit 0f67b7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
28 changes: 17 additions & 11 deletions src/config/api-server/vnc_cfg_ifmap.py
Expand Up @@ -1269,17 +1269,23 @@ def match_uuid(self, obj_dict, obj_uuid):
return False
# end match_uuid

def _update_subnet_uuid(self, vn_dict):
vn_uuid = vn_dict['uuid']
def update_subnet_uuid(self, vn_dict, do_update=False):
vn_uuid = vn_dict.get('uuid')

def _get_subnet_key(subnet):
def _read_subnet_uuid(subnet):
if vn_uuid is None:
return None
pfx = subnet['subnet']['ip_prefix']
pfx_len = subnet['subnet']['ip_prefix_len']

network = IPNetwork('%s/%s' % (pfx, pfx_len))
return '%s %s/%s' % (vn_uuid, str(network.ip), pfx_len)
subnet_key = '%s %s/%s' % (vn_uuid, str(network.ip), pfx_len)
try:
return self.useragent_kv_retrieve(subnet_key)
except NoUserAgentKey:
return None

ipam_refs = vn_dict['network_ipam_refs']
ipam_refs = vn_dict.get('network_ipam_refs', [])
updated = False
for ipam in ipam_refs:
vnsn = ipam['attr']
Expand All @@ -1288,15 +1294,15 @@ def _get_subnet_key(subnet):
if subnet.get('subnet_uuid'):
continue

subnet_key = _get_subnet_key(subnet)
subnet_uuid = self.useragent_kv_retrieve(subnet_key)
subnet_uuid = _read_subnet_uuid(subnet) or str(uuid.uuid4())
subnet['subnet_uuid'] = subnet_uuid
if not updated:
updated = True

if updated:
self._cassandra_db._cassandra_virtual_network_update(vn_uuid, vn_dict)
# end _update_subnet_uuid
if updated and do_update:
self._cassandra_db._cassandra_virtual_network_update(vn_uuid,
vn_dict)
# end update_subnet_uuid

def _dbe_resync(self, obj_uuid, obj_cols):
obj_type = None
Expand All @@ -1315,7 +1321,7 @@ def _dbe_resync(self, obj_uuid, obj_cols):

if (obj_type == 'virtual_network' and
'network_ipam_refs' in obj_dict):
self._update_subnet_uuid(obj_dict)
self._update_subnet_uuid(obj_dict, do_update=True)
except Exception as e:
self.config_object_error(
obj_uuid, None, obj_type, 'dbe_resync:cassandra_read', str(e))
Expand Down
15 changes: 2 additions & 13 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -418,17 +418,6 @@ def _check_route_targets(cls, obj_dict, db_conn):
return (True, '')
# end _check_route_targets

@classmethod
def _check_and_create_subnet_uuid(cls, vn_dict):
ipam_refs = vn_dict.get('network_ipam_refs', [])
for ipam in ipam_refs:
vnsn = ipam['attr']
subnets = vnsn['ipam_subnets']
for subnet in subnets:
if not subnet.get('subnet_uuid'):
subnet['subnet_uuid'] = str(uuid.uuid4())
# end _check_and_create_subnet_uuid

@classmethod
def http_post_collection(cls, tenant_name, obj_dict, db_conn):
try:
Expand All @@ -450,7 +439,7 @@ def http_post_collection(cls, tenant_name, obj_dict, db_conn):
if not ok:
return (False, (403, pformat(obj_dict['fq_name']) + ' : ' + quota_limit))

cls._check_and_create_subnet_uuid(obj_dict)
db_conn.update_subnet_uuid(obj_dict)

(ok, error) = cls._check_route_targets(obj_dict, db_conn)
if not ok:
Expand Down Expand Up @@ -507,7 +496,7 @@ def http_put(cls, id, fq_name, obj_dict, db_conn):
except Exception as e:
return (False, (500, str(e)))

cls._check_and_create_subnet_uuid(obj_dict)
db_conn.update_subnet_uuid(obj_dict)

(ok, error) = cls._check_route_targets(obj_dict, db_conn)
if not ok:
Expand Down

0 comments on commit 0f67b7d

Please sign in to comment.