Merge "[SVF] Update rccg details for mirror volumes"

This commit is contained in:
Zuul 2021-09-07 18:06:10 +00:00 committed by Gerrit Code Review
commit eb9deed8e3
3 changed files with 114 additions and 45 deletions

View File

@ -12340,15 +12340,19 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
group = self._create_test_rccg(self.rccg_type, [self.mm_type.id]) group = self._create_test_rccg(self.rccg_type, [self.mm_type.id])
mm_vol, model_update = self._create_test_volume(self.mm_type) mm_vol, model_update = self._create_test_volume(self.mm_type)
gm_vol, model_update = self._create_test_volume(self.gm_type) gm_vol, model_update = self._create_test_volume(self.gm_type)
add_vols = [mm_vol, gm_vol] with mock.patch.object(storwize_svc_common.StorwizeSVCCommonDriver,
(model_update, add_volumes_update, '_update_rccg_properties') as update_rccg_prop:
remove_volumes_update) = self.driver.update_group( add_vols = [mm_vol, gm_vol]
self.ctxt, group, add_vols, []) (model_update, add_volumes_update,
self.assertEqual(fields.GroupStatus.ERROR, model_update['status']) remove_volumes_update) = self.driver.update_group(
self.assertEqual([{'id': mm_vol.id, 'group_id': group.id}], self.ctxt, group, add_vols, [])
add_volumes_update) update_rccg_prop.assert_called()
self.assertEqual([], remove_volumes_update) self.assertEqual(1, update_rccg_prop.call_count)
self.driver.delete_group(self.ctxt, group, add_vols) self.assertEqual(fields.GroupStatus.ERROR, model_update['status'])
self.assertEqual([{'id': mm_vol.id, 'group_id': group.id}],
add_volumes_update)
self.assertEqual([], remove_volumes_update)
self.driver.delete_group(self.ctxt, group, add_vols)
group = self._create_test_rccg(self.rccg_type, [self.mm_type.id]) group = self._create_test_rccg(self.rccg_type, [self.mm_type.id])
rccg_name = self.driver._get_rccg_name(group) rccg_name = self.driver._get_rccg_name(group)
@ -12366,27 +12370,41 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
rcrel = self.driver._helpers.get_relationship_info(mm_vol4.name) rcrel = self.driver._helpers.get_relationship_info(mm_vol4.name)
self.sim._rc_state_transition('wait', rcrel) self.sim._rc_state_transition('wait', rcrel)
add_vols = [mm_vol1, mm_vol2] with mock.patch.object(storwize_svc_common.StorwizeSVCCommonDriver,
(model_update, add_volumes_update, '_update_rccg_properties') as update_rccg_prop:
remove_volumes_update) = self.driver.update_group( add_vols = [mm_vol1, mm_vol2]
self.ctxt, group, add_vols, []) (model_update, add_volumes_update,
self.assertEqual( remove_volumes_update) = self.driver.update_group(
rccg_name, self.ctxt, group, add_vols, [])
self.driver._helpers.get_rccg_info(mm_vol1.name)['name']) update_rccg_prop.assert_called()
self.assertEqual( self.assertEqual(2, update_rccg_prop.call_count)
rccg_name, self.assertEqual(
self.driver._helpers.get_rccg_info(mm_vol2.name)['name']) rccg_name,
self.assertEqual(fields.GroupStatus.AVAILABLE, model_update['status']) self.driver._helpers.get_rccg_info(mm_vol1.name)['name'])
self.assertEqual([{'id': mm_vol1.id, 'group_id': group.id}, self.assertEqual(
{'id': mm_vol2.id, 'group_id': group.id}], rccg_name,
add_volumes_update) self.driver._helpers.get_rccg_info(mm_vol2.name)['name'])
self.assertEqual([], remove_volumes_update) self.assertEqual(fields.GroupStatus.AVAILABLE,
model_update['status'])
self.assertEqual([{'id': mm_vol1.id, 'group_id': group.id},
{'id': mm_vol2.id, 'group_id': group.id}],
add_volumes_update)
self.assertEqual([], remove_volumes_update)
add_vols = [mm_vol3, mm_vol4] add_vols = [mm_vol3, mm_vol4]
rmv_vols = [mm_vol1, mm_vol2] rmv_vols = [mm_vol1, mm_vol2]
(model_update, add_volumes_update, (model_update, add_volumes_update,
remove_volumes_update) = self.driver.update_group( remove_volumes_update) = self.driver.update_group(
self.ctxt, group, add_volumes=add_vols, remove_volumes=rmv_vols) self.ctxt, group, add_volumes=add_vols, remove_volumes=rmv_vols)
# Validating the rccg property value from metadata of the volume
# mm_vol3 that is added to a group
self.assertEqual(rccg_name, mm_vol3.metadata['Consistency Group Name'])
# Validating the rccg property value from metadata of the volume
# mm_vol1 that is removed from a group
exp_rccg_name = ''
self.assertEqual(exp_rccg_name,
mm_vol1.metadata['Consistency Group Name'])
self.assertIsNone(self.driver._helpers.get_rccg_info(mm_vol1.name)) self.assertIsNone(self.driver._helpers.get_rccg_info(mm_vol1.name))
self.assertIsNone(self.driver._helpers.get_rccg_info(mm_vol2.name)) self.assertIsNone(self.driver._helpers.get_rccg_info(mm_vol2.name))
self.assertEqual( self.assertEqual(
@ -12405,6 +12423,28 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
self.driver.delete_group(self.ctxt, group, [mm_vol1, mm_vol2, self.driver.delete_group(self.ctxt, group, [mm_vol1, mm_vol2,
mm_vol3, mm_vol4]) mm_vol3, mm_vol4])
def test_storwize_rep_volume_rccg_properties_update(self):
"""Test rep volume rccg_properties update."""
self.driver.configuration.set_override('replication_device',
[self.rep_target])
self.driver.do_setup(self.ctxt)
group = self._create_test_rccg(self.rccg_type, [self.mm_type.id])
# Create metro mirror replication.
mm_vol, model_update = self._create_test_volume(self.mm_type)
# Validating the rccg property value of volume-metadata that updated
# during the call to the function _update_rccg_properties by passing
# the parameter 'group'
self.driver._update_rccg_properties(self.ctxt, mm_vol, group)
rccg_name = self.driver._get_rccg_name(group)
self.assertEqual(rccg_name, mm_vol.metadata['Consistency Group Name'])
# Validating the rccg property value of volume-metadata that updated
# during the call to the function _update_rccg_properties by not
# passing the parameter 'group'
self.driver._update_rccg_properties(self.ctxt, mm_vol)
exp_rccg_name = ""
self.assertEqual(exp_rccg_name,
mm_vol.metadata['Consistency Group Name'])
@mock.patch.object(storwize_svc_common.StorwizeSSH, @mock.patch.object(storwize_svc_common.StorwizeSSH,
'startrcconsistgrp') 'startrcconsistgrp')
def test_storwize_enable_replication_error(self, startrccg): def test_storwize_enable_replication_error(self, startrccg):
@ -13044,16 +13084,20 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
clone_volumes = self.db.volume_get_all_by_generic_group( clone_volumes = self.db.volume_get_all_by_generic_group(
self.ctxt.elevated(), clone_group.id) self.ctxt.elevated(), clone_group.id)
model_update, volumes_model_update = ( with mock.patch.object(
self.driver.create_group_from_src(self.ctxt, clone_group, storwize_svc_common.StorwizeSVCCommonDriver,
clone_volumes, None, None, '_update_rccg_properties'):
src_group, model_update, volumes_model_update = (
src_volumes)) self.driver.create_group_from_src(self.ctxt, clone_group,
clone_volumes, None, None,
src_group,
src_volumes))
self.assertEqual(fields.GroupStatus.AVAILABLE, model_update['status']) self.assertEqual(fields.GroupStatus.AVAILABLE,
for vol_model_update in volumes_model_update: model_update['status'])
self.assertEqual(fields.VolumeStatus.AVAILABLE, for vol_model_update in volumes_model_update:
vol_model_update['status']) self.assertEqual(fields.VolumeStatus.AVAILABLE,
vol_model_update['status'])
src_chg_vol_storage_pool = ( src_chg_vol_storage_pool = (
svc_src_childpool if svc_src_childpool else _get_test_pool()) svc_src_childpool if svc_src_childpool else _get_test_pool())
@ -13085,17 +13129,19 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
group_snapshot, snapshots = self._create_group_snapshot( group_snapshot, snapshots = self._create_group_snapshot(
src_group.id, group_type_id=self.rccg_type.id) src_group.id, group_type_id=self.rccg_type.id)
model_update, volumes_model_update = ( with mock.patch.object(
self.driver.create_group_from_src(self.ctxt, storwize_svc_common.StorwizeSVCCommonDriver,
group_from_src_group_snapshot, '_update_rccg_properties'):
group_volumes, model_update, volumes_model_update = (
group_snapshot, self.driver.create_group_from_src(
snapshots, None, None)) self.ctxt, group_from_src_group_snapshot, group_volumes,
group_snapshot, snapshots, None, None))
self.assertEqual(fields.GroupStatus.AVAILABLE, model_update['status']) self.assertEqual(fields.GroupStatus.AVAILABLE,
for vol_model_update in volumes_model_update: model_update['status'])
self.assertEqual(fields.VolumeStatus.AVAILABLE, for vol_model_update in volumes_model_update:
vol_model_update['status']) self.assertEqual(fields.VolumeStatus.AVAILABLE,
vol_model_update['status'])
src_chg_vol_storage_pool = ( src_chg_vol_storage_pool = (
svc_src_childpool if svc_src_childpool else _get_test_pool()) svc_src_childpool if svc_src_childpool else _get_test_pool())
@ -13145,7 +13191,9 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
) )
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=testutils.ZeroIntervalLoopingCall) new=testutils.ZeroIntervalLoopingCall)
def test_create_group_from_src_grp(self, vol_spec): @mock.patch.object(storwize_svc_common.StorwizeSVCCommonDriver,
'_update_rccg_properties')
def test_create_group_from_src_grp(self, vol_spec, update_rccg_properties):
self.driver.configuration.set_override('replication_device', self.driver.configuration.set_override('replication_device',
[self.rep_target]) [self.rep_target])
@ -13259,9 +13307,12 @@ class StorwizeSVCReplicationTestCase(test.TestCase):
) )
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=testutils.ZeroIntervalLoopingCall) new=testutils.ZeroIntervalLoopingCall)
@mock.patch.object(storwize_svc_common.StorwizeSVCCommonDriver,
'_update_rccg_properties')
@mock.patch('cinder.volume.volume_utils.is_group_a_cg_snapshot_type') @mock.patch('cinder.volume.volume_utils.is_group_a_cg_snapshot_type')
def test_create_group_from_grp_snapshot(self, vol_spec, def test_create_group_from_grp_snapshot(self, vol_spec,
is_group_a_cg_snap_type): is_group_a_cg_snap_type,
update_rccg_properties):
self.driver.configuration.set_override('replication_device', self.driver.configuration.set_override('replication_device',
[self.rep_target]) [self.rep_target])
is_group_a_cg_snap_type.return_value = False is_group_a_cg_snap_type.return_value = False

View File

@ -3510,6 +3510,13 @@ class StorwizeSVCCommonDriver(san.SanDriver,
model_update['metadata'][key] = rel_info.get(value) model_update['metadata'][key] = rel_info.get(value)
return model_update return model_update
def _update_rccg_properties(self, ctxt, volume, group=None):
rccg_name = self._get_rccg_name(group) if group else ""
if not volume.metadata:
volume.metadata = dict()
volume.metadata['Consistency Group Name'] = rccg_name
volume.save()
def create_volume(self, volume): def create_volume(self, volume):
LOG.debug('enter: create_volume: volume %s', volume['name']) LOG.debug('enter: create_volume: volume %s', volume['name'])
# Create a replication or hyperswap volume with group_id is not # Create a replication or hyperswap volume with group_id is not
@ -6383,6 +6390,8 @@ class StorwizeSVCCommonDriver(san.SanDriver,
rccg = self._helpers.get_rccg(rccg_name) rccg = self._helpers.get_rccg(rccg_name)
added_vols.append({'id': volume.id, added_vols.append({'id': volume.id,
'group_id': group.id}) 'group_id': group.id})
# Updating RCCG properties for a volume
self._update_rccg_properties(context, volume, group)
except exception.VolumeBackendAPIException as err: except exception.VolumeBackendAPIException as err:
model_update['status'] = fields.GroupStatus.ERROR model_update['status'] = fields.GroupStatus.ERROR
LOG.error("Failed to add the remote copy of volume %(vol)s to " LOG.error("Failed to add the remote copy of volume %(vol)s to "
@ -6414,6 +6423,8 @@ class StorwizeSVCCommonDriver(san.SanDriver,
self._helpers.chrcrelationship(rcrel['name']) self._helpers.chrcrelationship(rcrel['name'])
removed_vols.append({'id': volume.id, removed_vols.append({'id': volume.id,
'group_id': None}) 'group_id': None})
# Updating RCCG properties for a volume
self._update_rccg_properties(context, volume)
except exception.VolumeBackendAPIException as err: except exception.VolumeBackendAPIException as err:
model_update['status'] = fields.GroupStatus.ERROR model_update['status'] = fields.GroupStatus.ERROR
LOG.error("Failed to remove the remote copy of volume %(vol)s " LOG.error("Failed to remove the remote copy of volume %(vol)s "

View File

@ -0,0 +1,7 @@
---
fixes:
- |
IBM Spectrum Virtualize Family driver
`Bug #1926491 <https://bugs.launchpad.net/cinder/+bug/1926491>`_:
Updating volume metadata with rccg properties for the volumes with
replication enabled and added to a group or removed from a group.