[Urgent] Fix UT error caused by segment callback

1. What is the problem
In delete_network, NeutronDbPluginV2 will notify network precommit-delete
event which is subscribed by SegmentDbMixin. While handling the event,
SegmentDbMixin tries to access 'description' field of Segment object in
get_segments function and fails. Therefore unit test fails.

2. What is the solution for the problem
In FakeSession, extend standard attributes for newly added object, which
include 'description'.

3. What the features need to be implemented to the Tricircle to
realize the solution
N/A.

Change-Id: Ib099f0a5616f25b47ae881e784d49ec739bca8bc
This commit is contained in:
zhiyuan_cai 2017-03-08 16:50:30 +08:00
parent 82095e27d4
commit 3e15d42dd9
1 changed files with 14 additions and 2 deletions

View File

@ -247,8 +247,12 @@ class DotDict(dict):
self[key] = value
def __getattr__(self, item):
if item == 'rbac_entries':
return []
dummy_value_map = {
'rbac_entries': [],
'segment_host_mapping': []
}
if item in dummy_value_map:
return dummy_value_map[item]
return self.get(item)
def __copy__(self):
@ -887,6 +891,12 @@ class FakeSession(object):
return FakeQuery(RES_MAP[model.__tablename__],
model.__tablename__)
def _extend_standard_attr(self, model_dict):
if 'standard_attr' in model_dict:
for field in ('resource_type', 'description', 'revision_number',
'created_at', 'updated_at'):
model_dict[field] = getattr(model_dict['standard_attr'], field)
def add(self, model_obj):
if model_obj.__tablename__ not in RES_MAP:
return
@ -953,6 +963,8 @@ class FakeSession(object):
subnet['dns_nameservers'].append(dnsnameservers)
break
self._extend_standard_attr(model_dict)
RES_MAP[model_obj.__tablename__].append(model_dict)
def _cascade_delete(self, model_dict, foreign_key, table, key):