Merge "Pop "consistencygroup" from volume object"
This commit is contained in:
commit
817f34ce5d
@ -342,12 +342,16 @@ class Volume(cleanable.CinderCleanableObject, base.CinderObject,
|
|||||||
def save(self):
|
def save(self):
|
||||||
updates = self.cinder_obj_get_changes()
|
updates = self.cinder_obj_get_changes()
|
||||||
if updates:
|
if updates:
|
||||||
if 'consistencygroup' in updates:
|
# NOTE(xyang): Allow this to pass if 'consistencygroup' is
|
||||||
# NOTE(xyang): Allow this to pass if 'consistencygroup' is
|
# set to None. This is to support backward compatibility.
|
||||||
# set to None. This is to support backward compatibility.
|
# Also remove 'consistencygroup' from updates because
|
||||||
if updates.get('consistencygroup'):
|
# consistencygroup is the name of a relationship in the ORM
|
||||||
raise exception.ObjectActionError(
|
# Volume model, so SQLA tries to do some kind of update of
|
||||||
action='save', reason=_('consistencygroup changed'))
|
# the foreign key based on the provided updates if
|
||||||
|
# 'consistencygroup' is in updates.
|
||||||
|
if updates.pop('consistencygroup', None):
|
||||||
|
raise exception.ObjectActionError(
|
||||||
|
action='save', reason=_('consistencygroup changed'))
|
||||||
if 'group' in updates:
|
if 'group' in updates:
|
||||||
raise exception.ObjectActionError(
|
raise exception.ObjectActionError(
|
||||||
action='save', reason=_('group changed'))
|
action='save', reason=_('group changed'))
|
||||||
|
@ -63,15 +63,28 @@ class TestVolume(test_objects.BaseObjectsTestCase):
|
|||||||
self.assertEqual(db_volume['id'], volume.id)
|
self.assertEqual(db_volume['id'], volume.id)
|
||||||
|
|
||||||
@mock.patch('cinder.db.volume_update')
|
@mock.patch('cinder.db.volume_update')
|
||||||
def test_save(self, volume_update):
|
@ddt.data(False, True)
|
||||||
|
def test_save(self, test_cg, volume_update):
|
||||||
db_volume = fake_volume.fake_db_volume()
|
db_volume = fake_volume.fake_db_volume()
|
||||||
volume = objects.Volume._from_db_object(self.context,
|
volume = objects.Volume._from_db_object(self.context,
|
||||||
objects.Volume(), db_volume)
|
objects.Volume(), db_volume)
|
||||||
volume.display_name = 'foobar'
|
volume.display_name = 'foobar'
|
||||||
|
if test_cg:
|
||||||
|
volume.consistencygroup = None
|
||||||
volume.save()
|
volume.save()
|
||||||
volume_update.assert_called_once_with(self.context, volume.id,
|
volume_update.assert_called_once_with(self.context, volume.id,
|
||||||
{'display_name': 'foobar'})
|
{'display_name': 'foobar'})
|
||||||
|
|
||||||
|
def test_save_error(self):
|
||||||
|
db_volume = fake_volume.fake_db_volume()
|
||||||
|
volume = objects.Volume._from_db_object(self.context,
|
||||||
|
objects.Volume(), db_volume)
|
||||||
|
volume.display_name = 'foobar'
|
||||||
|
volume.consistencygroup = (
|
||||||
|
fake_consistencygroup.fake_consistencyobject_obj(self.context))
|
||||||
|
self.assertRaises(exception.ObjectActionError,
|
||||||
|
volume.save)
|
||||||
|
|
||||||
@mock.patch('cinder.db.volume_metadata_update',
|
@mock.patch('cinder.db.volume_metadata_update',
|
||||||
return_value={'key1': 'value1'})
|
return_value={'key1': 'value1'})
|
||||||
@mock.patch('cinder.db.volume_update')
|
@mock.patch('cinder.db.volume_update')
|
||||||
|
Loading…
Reference in New Issue
Block a user