Merge "Raise exception when synthetic field invalid"

This commit is contained in:
Zuul 2017-11-16 02:26:31 +00:00 committed by Gerrit Code Review
commit 4f818482ab
2 changed files with 26 additions and 0 deletions

View File

@ -290,6 +290,11 @@ class DeclarativeObject(abc.ABCMeta):
if 'project_id' in cls.fields and 'tenant_id' not in cls.fields:
cls.extra_filter_names.add('tenant_id')
invalid_fields = [f for f in cls.synthetic_fields
if f not in cls.fields]
if invalid_fields:
raise o_exc.NeutronObjectValidatorException(fields=invalid_fields)
@six.add_metaclass(DeclarativeObject)
class NeutronDbObject(NeutronObject):

View File

@ -1991,3 +1991,24 @@ class OperationOnStringAndJsonTestCase(test_base.BaseTestCase):
res = base.NeutronDbObject.filter_to_json_str(field_val,
default_val)
self.assertEqual(default_val, res)
class NeutronObjectValidatorTestCase(test_base.BaseTestCase):
def test_load_wrong_synthetic_fields(self):
try:
@obj_base.VersionedObjectRegistry.register_if(False)
class FakeNeutronObjectSyntheticFieldWrong(base.NeutronDbObject):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = FakeModel
fields = {
'id': common_types.UUIDField(),
'obj_field': common_types.UUIDField()
}
synthetic_fields = ['obj_field', 'wrong_synthetic_field_name']
except o_exc.NeutronObjectValidatorException as exc:
self.assertIn('wrong_synthetic_field_name', str(exc))