diff --git a/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py b/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py index 7f447326042..e826b259f13 100644 --- a/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py +++ b/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py @@ -27,6 +27,7 @@ pyxcli_client.mirroring = mock.Mock() pyxcli_client.transports = fake_pyxcli_exceptions pyxcli_client.mirroring.cg_recovery_manager = mock.Mock() pyxcli_client.version = '1.1.5' +pyxcli_client.mirroring.mirrored_entities = mock.Mock() sys.modules['pyxcli'] = pyxcli_client sys.modules['pyxcli.events'] = pyxcli_client.events diff --git a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py index 67530aae708..34d53281851 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py @@ -33,6 +33,7 @@ from cinder.volume import group_types errors = fake_pyxcli.pyxcli_client.errors mirroring = fake_pyxcli.pyxcli_client.mirroring +mirrored_entities = fake_pyxcli.pyxcli_client.mirroring.mirrored_entities test_mock = mock.MagicMock() module_patcher = mock.MagicMock() @@ -613,6 +614,41 @@ class XIVProxyTest(test.TestCase): vol=volume['name'], cg='cg') + @mock.patch('pyxcli.mirroring.mirrored_entities.' + 'MirroredEntities', mock.MagicMock()) + @mock.patch('cinder.volume.utils.is_group_a_type', + mock.MagicMock(return_value=True)) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_proxy.XIVProxy._get_extra_specs", + mock.MagicMock(return_value=TEST_EXTRA_SPECS_REPL)) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_replication.VolumeReplication.create_replication", + mock.MagicMock()) + def test_create_volume_with_consistency_group_diff_state(self): + """Test Create volume with consistency_group but diff state""" + driver = mock.MagicMock() + driver.VERSION = "VERSION" + + p = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver) + + p.ibm_storage_cli = mock.MagicMock() + p._cg_name_from_volume = mock.MagicMock(return_value="cg") + + vol_type = testutils.create_volume_type(self.ctxt, name='WTF') + volume = testutils.create_volume( + self.ctxt, size=16, volume_type_id=vol_type.id, + host=self._get_test_host()['name']) + + grp = self._create_test_group('WTF') + grp['replication_status'] = 'enabled' + volume.group = grp + ex = getattr(p, "_get_exception")() + self.assertRaises(ex, p.create_volume, volume) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." "xiv_replication.VolumeReplication.create_replication", mock.MagicMock()) diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index b0d07a2fa3d..bde8fc58496 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -522,18 +522,21 @@ class XIVProxy(proxy.IBMStorageProxy): ' should be the same') elif volume.host != volume.group.host: msg = 'Cannot add volume to Group on different host' - else: + elif volume.group['replication_status'] == 'enabled': + # if group is mirrored and enabled, compare state. group_name = self._cg_name_from_group(volume.group) me = mirrored_entities.MirroredEntities( self.ibm_storage_cli) me_objs = me.get_mirror_resources_by_name_map() - vol_sync_state = me_objs['volumes'][volume.name].sync_state - cg_sync_state = me_objs['cgs'][group_name].sync_state + vol_obj = me_objs['volumes'][volume.name] + vol_sync_state = vol_obj['sync_state'] + cg_sync_state = me_objs['cgs'][group_name]['sync_state'] if (vol_sync_state != 'Synchronized' or cg_sync_state != 'Synchronized'): msg = ('Cannot add volume to Group. Both volume and ' 'group should have sync_state = Synchronized') + if msg: LOG.error(msg) raise self.meta['exception'].VolumeBackendAPIException( @@ -590,8 +593,10 @@ class XIVProxy(proxy.IBMStorageProxy): self._update_consistencygroup(context, group, remove_volumes=volumes) for volume in volumes: - repl.VolumeReplication(self).create_replication( - volume.name, replication_info) + enabled_status = fields.ReplicationStatus.ENABLED + if volume['replication_status'] != enabled_status: + repl.VolumeReplication(self).create_replication( + volume.name, replication_info) # mirror entire group group_name = self._cg_name_from_group(group)