Correct the attributes of volume which created by clone a CG

If a volume in a consistency group is bootable or allow
multi-attach, after clone the consistency group, the created
volume is not bootable and allow multi-attach is set to False.
This patch will correct the attributes of volume according to
the source volume.

Change-Id: Icb4fad78cb218a134bb87e7d522829297cf93b94
Closes-Bug: #1498783
This commit is contained in:
haobing1 2016-11-30 21:40:31 +08:00
parent 514aff0f5e
commit 57406b22a7
2 changed files with 22 additions and 1 deletions

View File

@ -230,6 +230,10 @@ class GroupManagerTestCase(test.TestCase):
self.volume.db.volume_get.reset_mock()
self.volume.db.volume_get = volume_get_orig
@mock.patch('cinder.db.sqlalchemy.api.'
'volume_glance_metadata_copy_to_volume')
@mock.patch('cinder.db.sqlalchemy.api.'
'volume_glance_metadata_copy_from_volume_to_volume')
@mock.patch.object(driver.VolumeDriver,
"create_group",
return_value={'status': 'available'})
@ -256,7 +260,9 @@ class GroupManagerTestCase(test.TestCase):
mock_delete_grpsnap,
mock_create_grpsnap,
mock_delete_grp,
mock_create_grp):
mock_create_grp,
mock_metadata_copy_volume_to_volume,
mock_metadata_copy_to_volume):
"""Test group can be created and deleted."""
group = tests_utils.create_group(
self.context,
@ -269,6 +275,8 @@ class GroupManagerTestCase(test.TestCase):
self.context,
group_id=group.id,
status='available',
multiattach=True,
bootable=True,
host=group.host,
volume_type_id=fake.VOLUME_TYPE_ID,
size=1)
@ -371,11 +379,14 @@ class GroupManagerTestCase(test.TestCase):
self.context, group3, source_group=group)
grp3 = objects.Group.get_by_id(self.context, group3.id)
vol3 = objects.Volume.get_by_id(self.context, volume3.id)
self.assertEqual(fields.GroupStatus.AVAILABLE, grp3.status)
self.assertEqual(group3.id, grp3.id)
self.assertEqual(group.id, grp3.source_group_id)
self.assertIsNone(grp3.group_snapshot_id)
self.assertEqual(volume.multiattach, vol3.multiattach)
self.assertEqual(volume.bootable, vol3.bootable)
self.volume.delete_group_snapshot(self.context, group_snapshot)
self.volume.delete_group(self.context, group)

View File

@ -2825,6 +2825,7 @@ class VolumeManager(manager.CleanableManager,
def _update_volume_from_src(self, context, vol, update, group=None):
try:
snapshot_id = vol.get('snapshot_id')
source_volid = vol.get('source_volid')
if snapshot_id:
snapshot = objects.Snapshot.get_by_id(context, snapshot_id)
orig_vref = self.db.volume_get(context,
@ -2833,6 +2834,15 @@ class VolumeManager(manager.CleanableManager,
update['bootable'] = True
self.db.volume_glance_metadata_copy_to_volume(
context, vol['id'], snapshot_id)
if source_volid:
source_vol = objects.Volume.get_by_id(context, source_volid)
if source_vol.bootable:
update['bootable'] = True
self.db.volume_glance_metadata_copy_from_volume_to_volume(
context, source_volid, vol['id'])
if source_vol.multiattach:
update['multiattach'] = True
except exception.SnapshotNotFound:
LOG.error(_LE("Source snapshot %(snapshot_id)s cannot be found."),
{'snapshot_id': vol['snapshot_id']})