From 606dc156754a1541915901c2df8f0270f1d2eb78 Mon Sep 17 00:00:00 2001 From: Xinli Guan <xinli@us.ibm.com> Date: Wed, 6 Jul 2016 20:14:16 +0000 Subject: [PATCH] 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 --- cinder/objects/cgsnapshot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cinder/objects/cgsnapshot.py b/cinder/objects/cgsnapshot.py index 9fa715a0287..d5ad3772e49 100644 --- a/cinder/objects/cgsnapshot.py +++ b/cinder/objects/cgsnapshot.py @@ -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)