Merge "Fix refresh in VolumeMapping object"

This commit is contained in:
Zuul 2019-03-26 09:23:46 +00:00 committed by Gerrit Code Review
commit e0d40fa857
3 changed files with 32 additions and 3 deletions

View File

@ -107,3 +107,26 @@ class Volume(base.ZunPersistentObject, base.ZunObject):
updates.pop('id', None)
dbapi.update_volume(context, self.uuid, updates)
self.obj_reset_changes()
@base.remotable
def refresh(self, context=None):
"""Loads updates for this Volume.
Loads a volume with the same id from the database and
checks for updated attributes. Updates are applied from
the loaded volume column by column, if there are any updates.
:param context: Security context. NOTE: This should only
be used internally by the indirection_api.
Unfortunately, RPC requires context as the first
argument, even though we don't use it.
A context should be set when instantiating the
object.
"""
current = self.__class__.get_by_id(self._context, self.id)
for field in self.fields:
if not self.obj_attr_is_set(field):
continue
if getattr(self, field) != getattr(current, field):
setattr(self, field, getattr(current, field))
self.obj_reset_changes()

View File

@ -251,9 +251,15 @@ class VolumeMapping(base.ZunPersistentObject, base.ZunObject):
"""
current = self.__class__.get_by_uuid(self._context, uuid=self.uuid)
for field in self.fields:
if self.obj_attr_is_set(field) and \
getattr(self, field) != getattr(current, field):
if not self.obj_attr_is_set(field):
continue
if field == 'volume':
self.volume.refresh()
elif field == 'container':
self.container.refresh()
elif getattr(self, field) != getattr(current, field):
setattr(self, field, getattr(current, field))
self.obj_reset_changes()
def obj_load_attr(self, attrname):
if attrname not in VOLUME_MAPPING_OPTIONAL_ATTRS:

View File

@ -349,7 +349,7 @@ object_data = {
'CapsuleInitContainer': '1.0-64f11ebe03a0f7d5e74e4876b1f5a98f',
'Container': '1.39-dd75db8ef7f620f9781de1f484b9e5d0',
'Cpuset': '1.0-06c4e6335683c18b87e2e54080f8c341',
'Volume': '1.0-4ec18c39ea49f898cc354f9ca178dfb7',
'Volume': '1.0-034768f2f5c5e89acb5ee45c6d3f3403',
'VolumeMapping': '1.5-57febc66526185a75a744637e7a387c7',
'Image': '1.2-80504fdd797e9dd86128a91680e876ad',
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',