(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):
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': '<in> ' + 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)
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'),
]
{'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,