From 88c8b42194333566c085489b160d77fc71b61b86 Mon Sep 17 00:00:00 2001 From: Erik Zaadi Date: Tue, 14 May 2013 10:20:43 +0300 Subject: [PATCH] Storwize/SVC: fix attach bug for live migration. Add force flag for mkvdiskhostmap command to allow multi host mapping Change-Id: I290a5986b213a0aaeae0d0ea0ad57350c9dee3c9 Fixes: bug #1179773 --- cinder/tests/test_storwize_svc.py | 45 +++++++++++++++++++++++++-- cinder/volume/drivers/storwize_svc.py | 26 +++++++++++++--- 2 files changed, 64 insertions(+), 7 deletions(-) mode change 100644 => 100755 cinder/tests/test_storwize_svc.py mode change 100644 => 100755 cinder/volume/drivers/storwize_svc.py diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py old mode 100644 new mode 100755 index cad040a02..83f0cbfa9 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -884,9 +884,17 @@ port_speed!N/A (v['lun'] == mapping_info['lun'])): return self._errors['CMMVC5879E'] - self._mappings_list[mapping_info['vol']] = mapping_info - return ('Virtual Disk to Host map, id [%s], successfully created' - % (mapping_info['id']), '') + if kwargs.get('host', '').startswith('duplicate_mapping'): + if 'force' in kwargs: + self._mappings_list[mapping_info['vol']] = mapping_info + return ('Virtual Disk to Host map, id [%s], ' + 'successfully created' % (mapping_info['id']), '') + else: + return self._errors['CMMVC6071E'] + else: + self._mappings_list[mapping_info['vol']] = mapping_info + return ('Virtual Disk to Host map, id [%s], successfully created' + % (mapping_info['id']), '') # Delete a vdisk-host mapping def _cmd_rmvdiskhostmap(self, **kwargs): @@ -1777,6 +1785,37 @@ class StorwizeSVCDriverTestCase(test.TestCase): ret = self.driver._get_host_from_connector(conn) self.assertEqual(ret, None) + def test_storwize_svc_multi_host_maps(self): + # Create a volume to be used in mappings + ctxt = context.get_admin_context() + volume = self._generate_vol_info(None, None) + self.driver.create_volume(volume) + + # Create volume types that we created + types = {} + for protocol in ['FC', 'iSCSI']: + opts = {'storage_protocol': ' ' + protocol} + types[protocol] = volume_types.create(ctxt, protocol, opts) + + conn = {'initiator': self._iscsi_name, + 'ip': '11.11.11.11', + 'host': 'duplicate_mapping'} + + for protocol in ['FC', 'iSCSI']: + volume['volume_type_id'] = types[protocol]['id'] + + # Make sure that the volumes have been created + self._assert_vol_exists(volume['name'], True) + + self.driver.initialize_connection(volume, conn) + self.driver.terminate_connection(volume, conn) + + self._set_flag('storwize_svc_multihostmap_enabled', False) + self.assertRaises(exception.CinderException, + self.driver.initialize_connection, volume, conn) + self.driver.terminate_connection(volume, conn) + self._reset_flags() + def test_storwize_svc_delete_volume_snapshots(self): # Create a volume with two snapshots master = self._generate_vol_info(None, None) diff --git a/cinder/volume/drivers/storwize_svc.py b/cinder/volume/drivers/storwize_svc.py old mode 100644 new mode 100755 index 4da610e02..e69a4f754 --- a/cinder/volume/drivers/storwize_svc.py +++ b/cinder/volume/drivers/storwize_svc.py @@ -95,6 +95,9 @@ storwize_svc_opts = [ cfg.BoolOpt('storwize_svc_multipath_enabled', default=False, help='Connect with multipath (currently FC-only)'), + cfg.BoolOpt('storwize_svc_multihostmap_enabled', + default=True, + help='Allows vdisk to multi host mapping'), ] @@ -600,10 +603,25 @@ class StorwizeSVCDriver(san.SanISCSIDriver): {'host_name': host_name, 'result_lun': result_lun, 'volume_name': volume_name}) - out, err = self._run_ssh(ssh_cmd) - self._assert_ssh_return('successfully created' in out, - '_map_vol_to_host', ssh_cmd, out, err) - + out, err = self._run_ssh(ssh_cmd, check_exit_code=False) + if err and err.startswith('CMMVC6071E'): + if not self.configuration.storwize_svc_multihostmap_enabled: + LOG.error(_('storwize_svc_multihostmap_enabled is set ' + 'to Flase, Not allow multi host mapping')) + exception_msg = 'CMMVC6071E The VDisk-to-host mapping '\ + 'was not created because the VDisk is '\ + 'already mapped to a host.\n"' + raise exception.CinderException(data=exception_msg) + ssh_cmd = ssh_cmd.replace('mkvdiskhostmap', + 'mkvdiskhostmap -force') + # try to map one volume to multiple hosts + out, err = self._run_ssh(ssh_cmd) + LOG.warn(_('volume %s mapping to multi host') % volume_name) + self._assert_ssh_return('successfully created' in out, + '_map_vol_to_host', ssh_cmd, out, err) + else: + self._assert_ssh_return('successfully created' in out, + '_map_vol_to_host', ssh_cmd, out, err) LOG.debug(_('leave: _map_vol_to_host: LUN %(result_lun)s, volume ' '%(volume_name)s, host %(host_name)s') % {'result_lun': result_lun, -- 2.45.2