Skip to content

Commit

Permalink
Storwize/SVC: fix attach bug for live migration.
Browse files Browse the repository at this point in the history
Add force flag for mkvdiskhostmap command to allow multi host mapping

Change-Id: I290a5986b213a0aaeae0d0ea0ad57350c9dee3c9
Fixes: bug #1179773
  • Loading branch information
Erik Zaadi committed May 14, 2013
1 parent e831013 commit 88c8b42
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
45 changes: 42 additions & 3 deletions cinder/tests/test_storwize_svc.py 100644 → 100755
Expand Up @@ -884,9 +884,17 @@ def _cmd_mkvdiskhostmap(self, **kwargs):
(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):
Expand Down Expand Up @@ -1777,6 +1785,37 @@ def test_storwize_svc_host_maps(self):
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)
Expand Down
26 changes: 22 additions & 4 deletions cinder/volume/drivers/storwize_svc.py 100644 → 100755
Expand Up @@ -95,6 +95,9 @@
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'),
]


Expand Down Expand Up @@ -600,10 +603,25 @@ def _map_vol_to_host(self, volume_name, host_name):
{'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,
Expand Down

0 comments on commit 88c8b42

Please sign in to comment.