Moving the OPTIONAL_FIELDS inside the OVO object

In working patch 251989, Michal Dulko points out that
all the OVOs should have OPTIONAL_FIELDS inside object.

This patch will fix the issue in OVO, CGSnapshot.

Now that the OPTIONAL_FIELDS is part of the class definition,
_from_db_object should no longer be a staticmethod,
but should be a classmethod.

Change-Id: I9603cc3839dfd6e1cf102a77aeed3e9edc661bb4
This commit is contained in:
Xinli Guan 2016-07-06 20:14:16 +00:00
parent ca850533e5
commit 606dc15675
1 changed files with 6 additions and 6 deletions

View File

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