Merge "Moving the OPTIONAL_FIELDS inside the OVO object"

This commit is contained in:
Jenkins 2016-07-08 16:43:12 +00:00 committed by Gerrit Code Review
commit 61602912f4

View File

@ -19,14 +19,14 @@ from cinder import objects
from cinder.objects import base from cinder.objects import base
from oslo_versionedobjects import fields from oslo_versionedobjects import fields
OPTIONAL_FIELDS = ['consistencygroup', 'snapshots']
@base.CinderObjectRegistry.register @base.CinderObjectRegistry.register
class CGSnapshot(base.CinderPersistentObject, base.CinderObject, class CGSnapshot(base.CinderPersistentObject, base.CinderObject,
base.CinderObjectDictCompat): base.CinderObjectDictCompat):
VERSION = '1.0' VERSION = '1.0'
OPTIONAL_FIELDS = ['consistencygroup', 'snapshots']
fields = { fields = {
'id': fields.UUIDField(), 'id': fields.UUIDField(),
'consistencygroup_id': fields.UUIDField(nullable=True), 'consistencygroup_id': fields.UUIDField(nullable=True),
@ -40,12 +40,12 @@ class CGSnapshot(base.CinderPersistentObject, base.CinderObject,
'snapshots': fields.ObjectField('SnapshotList', nullable=True), 'snapshots': fields.ObjectField('SnapshotList', nullable=True),
} }
@staticmethod @classmethod
def _from_db_object(context, cgsnapshot, db_cgsnapshots, def _from_db_object(cls, context, cgsnapshot, db_cgsnapshots,
expected_attrs=None): expected_attrs=None):
expected_attrs = expected_attrs or [] expected_attrs = expected_attrs or []
for name, field in cgsnapshot.fields.items(): for name, field in cgsnapshot.fields.items():
if name in OPTIONAL_FIELDS: if name in cls.OPTIONAL_FIELDS:
continue continue
value = db_cgsnapshots.get(name) value = db_cgsnapshots.get(name)
setattr(cgsnapshot, name, value) setattr(cgsnapshot, name, value)
@ -82,7 +82,7 @@ class CGSnapshot(base.CinderPersistentObject, base.CinderObject,
self._from_db_object(self._context, self, db_cgsnapshots) self._from_db_object(self._context, self, db_cgsnapshots)
def obj_load_attr(self, attrname): def obj_load_attr(self, attrname):
if attrname not in OPTIONAL_FIELDS: if attrname not in self.OPTIONAL_FIELDS:
raise exception.ObjectActionError( raise exception.ObjectActionError(
action='obj_load_attr', action='obj_load_attr',
reason=_('attribute %s not lazy-loadable') % attrname) reason=_('attribute %s not lazy-loadable') % attrname)