Merge "objects: support tenant_id filter for get_* if project_id is present"

This commit is contained in:
Jenkins 2017-07-02 09:32:42 +00:00 committed by Gerrit Code Review
commit 352afb37af
3 changed files with 24 additions and 0 deletions
neutron
objects
tests/unit/objects

@ -285,6 +285,9 @@ class DeclarativeObject(abc.ABCMeta):
standardattributes.add_standard_attributes(cls)
# Instantiate extra filters per class
cls.extra_filter_names = set(cls.extra_filter_names)
# add tenant_id filter for objects that have project_id
if 'project_id' in cls.fields and 'tenant_id' not in cls.fields:
cls.extra_filter_names.add('tenant_id')
@six.add_metaclass(DeclarativeObject)

@ -1222,6 +1222,10 @@ class BaseObjectIfaceWithProjectIdTestCase(BaseObjectIfaceTestCase):
self.assertEqual(set(['field2']), obj.obj_what_changed())
self.assertEqual(tenant_id, obj.project_id)
def test_tenant_id_filter_added_when_project_id_present(self):
self._test_class.get_objects(
self.context, tenant_id=self.obj_fields[0]['project_id'])
class BaseDbObjectMultipleForeignKeysTestCase(_BaseObjectTestCase,
test_base.BaseTestCase):

@ -178,3 +178,20 @@ class TrunkDbObjectTestCase(test_base.BaseDbObjectTestCase,
trunk_v1_0 = trunk_new.obj_to_primitive(target_version='1.0')
self.assertNotIn('project_id', trunk_v1_0['versioned_object.data'])
self.assertIn('tenant_id', trunk_v1_0['versioned_object.data'])
def test_get_objects_tenant_id(self):
trunk = t_obj.Trunk(context=self.context,
project_id='faketenant',
port_id=self.db_objs[0]['port_id'])
trunk.create()
self.assertIsNotNone(
t_obj.Trunk.get_objects(self.context, tenant_id='faketenant'))
def test_get_objects_both_tenant_and_project_ids(self):
trunk = t_obj.Trunk(context=self.context,
project_id='faketenant',
port_id=self.db_objs[0]['port_id'])
trunk.create()
self.assertIsNotNone(
t_obj.Trunk.get_objects(
self.context, tenant_id='faketenant', project_id='faketenant'))