Include OPTIONAL_FIELDS in VolumeType OVO class

Current code has OPTIONAL_FIELDS as part of the VolumeType library
instead of as a class attribute of the VolumeType OVO class.  This is
not how it should be, as there are methods -like conditional update-
that rely on the OPTIONAL_FIELDS being there.

This patch moves the OPTIONAL_FIELDS inside the VolumeType class.

Change-Id: I18404a2f32abc6c9d9b7d932a7acd299c4e708e5
(cherry picked from commit f63f1463c6)
This commit is contained in:
Gorka Eguileor 2016-09-07 16:17:37 +02:00
parent d3f3791416
commit b5a1cee26c
1 changed files with 5 additions and 6 deletions

View File

@ -23,9 +23,6 @@ from cinder.objects import base
from cinder.volume import volume_types
OPTIONAL_FIELDS = ['extra_specs', 'projects', 'qos_specs']
@base.CinderObjectRegistry.register
class VolumeType(base.CinderPersistentObject, base.CinderObject,
base.CinderObjectDictCompat, base.CinderComparableObject):
@ -34,6 +31,8 @@ class VolumeType(base.CinderPersistentObject, base.CinderObject,
# Version 1.2: Added qos_specs
VERSION = '1.2'
OPTIONAL_FIELDS = ('extra_specs', 'projects', 'qos_specs')
fields = {
'id': fields.UUIDField(),
'name': fields.StringField(nullable=True),
@ -62,12 +61,12 @@ class VolumeType(base.CinderPersistentObject, base.CinderObject,
def _get_expected_attrs(cls, context, *args, **kwargs):
return 'extra_specs', 'projects'
@staticmethod
def _from_db_object(context, type, db_type, expected_attrs=None):
@classmethod
def _from_db_object(cls, context, type, db_type, expected_attrs=None):
if expected_attrs is None:
expected_attrs = ['extra_specs', 'projects']
for name, field in type.fields.items():
if name in OPTIONAL_FIELDS:
if name in cls.OPTIONAL_FIELDS:
continue
value = db_type[name]
if isinstance(field, fields.IntegerField):