Merge "Workaround in NetworkSegmentRange OVO until "project_id" migration" into stable/train

This commit is contained in:
Zuul 2020-05-04 02:23:12 +00:00 committed by Gerrit Code Review
commit f53ff5515b
3 changed files with 13 additions and 4 deletions

View File

@ -83,7 +83,11 @@ class NetworkSegmentRange(base.NeutronDbObject):
# AttrtibuteError can be raised when accessing self.db_obj
# or self.db_obj.standard_attr
pass
return db_utils.resource_fields(_dict, fields)
# NOTE(ralonsoh): this workaround should be removed once the migration
# from "tenant_id" to "project_id" is finished.
_dict = db_utils.resource_fields(_dict, fields)
_dict.pop('tenant_id', None)
return _dict
def _check_shared_project_id(self, action):
if self.shared is False and not self.project_id:

View File

@ -726,6 +726,7 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
self.model_map = collections.defaultdict(list)
self.model_map[self._test_class.db_model] = self.db_objs
self.pager_map = collections.defaultdict(lambda: None)
self.extra_fields_not_in_dict = []
self.get_objects_mock = mock.patch.object(
obj_db_api, 'get_objects',
@ -1156,8 +1157,11 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
for field in self._test_class.obj_extra_fields:
# field is accessible and cannot be set by any value
getattr(obj, field)
self.assertIn(field, obj.to_dict().keys())
self.assertRaises(AttributeError, setattr, obj, field, "1")
if field in self.extra_fields_not_in_dict:
self.assertNotIn(field, obj.to_dict().keys())
else:
self.assertIn(field, obj.to_dict().keys())
self.assertRaises(AttributeError, setattr, obj, field, "1")
def test_to_dict_makes_primitive_field_value(self):
obj = self._test_class(self.context, **self.obj_fields[0])

View File

@ -57,13 +57,14 @@ class NetworkSegmentRangeIfaceObjectTestCase(
# `shared` and `network_type` respectively.
# Hack to always populate test project_id and physical_network
# fields in network segment range Iface object testing so that related
# tests like `test_extra_fields`, `test_create_updates_from_db_object`,
# tests like `test_create_updates_from_db_object` and
# `test_update_updates_from_db_object` can have those fields.
# Alternatives can be skipping those tests when executing
# NetworkSegmentRangeIfaceObjectTestCase, or making base test case
# adjustments.
self.update_obj_fields({'project_id': TEST_TENANT_ID,
'physical_network': TEST_PHYSICAL_NETWORK})
self.extra_fields_not_in_dict = ['tenant_id']
class NetworkSegmentRangeDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,