Merge "Swap volume type for migration started by retype"
This commit is contained in:
commit
a75789bb90
@ -456,8 +456,14 @@ class Volume(cleanable.CinderCleanableObject, base.CinderObject,
|
|||||||
# We swap fields between source (i.e. self) and destination at the
|
# We swap fields between source (i.e. self) and destination at the
|
||||||
# end of migration because we want to keep the original volume id
|
# end of migration because we want to keep the original volume id
|
||||||
# in the DB but now pointing to the migrated volume.
|
# in the DB but now pointing to the migrated volume.
|
||||||
skip = ({'id', 'provider_location', 'glance_metadata',
|
skip = {'id', 'provider_location', 'glance_metadata'
|
||||||
'volume_type'} | set(self.obj_extra_fields))
|
} | set(self.obj_extra_fields)
|
||||||
|
|
||||||
|
# For the migration started by retype, we should swap the
|
||||||
|
# volume type, other circumstances still skip volume type.
|
||||||
|
if self.status != 'retyping':
|
||||||
|
skip.add('volume_type')
|
||||||
|
|
||||||
for key in set(dest_volume.fields.keys()) - skip:
|
for key in set(dest_volume.fields.keys()) - skip:
|
||||||
# Only swap attributes that are already set. We do not want to
|
# Only swap attributes that are already set. We do not want to
|
||||||
# unexpectedly trigger a lazy-load.
|
# unexpectedly trigger a lazy-load.
|
||||||
|
@ -353,15 +353,22 @@ class TestVolume(test_objects.BaseObjectsTestCase):
|
|||||||
@ddt.data({'src_vol_type_id': fake.VOLUME_TYPE_ID,
|
@ddt.data({'src_vol_type_id': fake.VOLUME_TYPE_ID,
|
||||||
'dest_vol_type_id': fake.VOLUME_TYPE2_ID},
|
'dest_vol_type_id': fake.VOLUME_TYPE2_ID},
|
||||||
{'src_vol_type_id': None,
|
{'src_vol_type_id': None,
|
||||||
'dest_vol_type_id': fake.VOLUME_TYPE2_ID})
|
'dest_vol_type_id': fake.VOLUME_TYPE2_ID},
|
||||||
|
{'src_vol_type_id': fake.VOLUME_TYPE_ID,
|
||||||
|
'dest_vol_type_id': fake.VOLUME_TYPE2_ID,
|
||||||
|
'src_vol_status': 'retyping'},)
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
def test_finish_volume_migration(self, volume_update, metadata_update,
|
def test_finish_volume_migration(self, volume_update, metadata_update,
|
||||||
src_vol_type_id, dest_vol_type_id):
|
src_vol_type_id, dest_vol_type_id,
|
||||||
|
src_vol_status=None):
|
||||||
src_volume_db = fake_volume.fake_db_volume(
|
src_volume_db = fake_volume.fake_db_volume(
|
||||||
**{'id': fake.VOLUME_ID, 'volume_type_id': src_vol_type_id})
|
**{'id': fake.VOLUME_ID, 'volume_type_id': src_vol_type_id})
|
||||||
if src_vol_type_id:
|
if src_vol_type_id:
|
||||||
src_volume_db['volume_type'] = fake_volume.fake_db_volume_type(
|
src_volume_db['volume_type'] = fake_volume.fake_db_volume_type(
|
||||||
id=src_vol_type_id)
|
id=src_vol_type_id)
|
||||||
|
if src_vol_status:
|
||||||
|
src_volume_db['status'] = src_vol_status
|
||||||
|
|
||||||
dest_volume_db = fake_volume.fake_db_volume(
|
dest_volume_db = fake_volume.fake_db_volume(
|
||||||
**{'id': fake.VOLUME2_ID, 'volume_type_id': dest_vol_type_id})
|
**{'id': fake.VOLUME2_ID, 'volume_type_id': dest_vol_type_id})
|
||||||
if dest_vol_type_id:
|
if dest_vol_type_id:
|
||||||
@ -385,6 +392,10 @@ class TestVolume(test_objects.BaseObjectsTestCase):
|
|||||||
mock.call(self.context, src_volume.id, mock.ANY),
|
mock.call(self.context, src_volume.id, mock.ANY),
|
||||||
mock.call(self.context, dest_volume.id, mock.ANY)])
|
mock.call(self.context, dest_volume.id, mock.ANY)])
|
||||||
ctxt, vol_id, updates = volume_update.call_args[0]
|
ctxt, vol_id, updates = volume_update.call_args[0]
|
||||||
|
|
||||||
|
if src_vol_status and src_vol_status == 'retyping':
|
||||||
|
self.assertIn('volume_type', updates)
|
||||||
|
else:
|
||||||
self.assertNotIn('volume_type', updates)
|
self.assertNotIn('volume_type', updates)
|
||||||
|
|
||||||
# Ensure that the destination volume type has not been overwritten
|
# Ensure that the destination volume type has not been overwritten
|
||||||
|
Loading…
Reference in New Issue
Block a user