Merge "Storwize Support iSCSI host when FC volume is there"

This commit is contained in:
Jenkins 2017-06-20 20:09:42 +00:00 committed by Gerrit Code Review
commit ea2d1db31f
3 changed files with 49 additions and 43 deletions

View File

@ -2412,7 +2412,8 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.iscsi_driver.initialize_connection(volume_iSCSI, connector)
self.iscsi_driver.initialize_connection(volume_iSCSI, connector2)
for conn in [connector, connector2]:
host = self.iscsi_driver._helpers.get_host_from_connector(conn)
host = self.iscsi_driver._helpers.get_host_from_connector(
conn, iscsi=True)
self.assertIsNotNone(host)
self.iscsi_driver.terminate_connection(volume_iSCSI, connector)
self.iscsi_driver.terminate_connection(volume_iSCSI, connector2)
@ -2425,11 +2426,11 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.iscsi_driver.initialize_connection(volume_iSCSI, connector2)
# Test multiple attachments case
host_name = self.iscsi_driver._helpers.get_host_from_connector(
connector2)
connector2, iscsi=True)
self.iscsi_driver._helpers.unmap_vol_from_host(
volume_iSCSI['name'], host_name)
host_name = self.iscsi_driver._helpers.get_host_from_connector(
connector2)
connector2, iscsi=True)
self.assertIsNotNone(host_name)
with mock.patch.object(storwize_svc_common.StorwizeSSH,
'rmvdiskhostmap') as rmmap:
@ -2437,7 +2438,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.iscsi_driver.terminate_connection(volume_iSCSI,
connector2)
host_name = self.iscsi_driver._helpers.get_host_from_connector(
connector2)
connector2, iscsi=True)
self.assertIsNone(host_name)
# Test single attachment case
self.iscsi_driver._helpers.unmap_vol_from_host(
@ -2448,7 +2449,8 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.iscsi_driver.terminate_connection(volume_iSCSI, connector)
# validate that the host entries are deleted
for conn in [connector, connector2]:
host = self.iscsi_driver._helpers.get_host_from_connector(conn)
host = self.iscsi_driver._helpers.get_host_from_connector(
conn, iscsi=True)
self.assertIsNone(host)
def test_storwize_initialize_iscsi_connection_single_path(self):
@ -2478,7 +2480,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
# Check case where no hosts exist
ret = self.iscsi_driver._helpers.get_host_from_connector(
connector)
connector, iscsi=True)
self.assertIsNone(ret)
# Initialize connection to map volume to a host
@ -2492,7 +2494,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.assertEqual(v, ret['data'][k])
ret = self.iscsi_driver._helpers.get_host_from_connector(
connector)
connector, iscsi=True)
self.assertIsNotNone(ret)
def test_storwize_initialize_iscsi_connection_multipath(self):
@ -2530,7 +2532,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
# Check case where no hosts exist
ret = self.iscsi_driver._helpers.get_host_from_connector(
connector)
connector, iscsi=True)
self.assertIsNone(ret)
# Initialize connection to map volume to a host
@ -2544,7 +2546,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
self.assertEqual(v, ret['data'][k])
ret = self.iscsi_driver._helpers.get_host_from_connector(
connector)
connector, iscsi=True)
self.assertIsNotNone(ret)
def test_storwize_svc_iscsi_host_maps(self):
@ -2684,7 +2686,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
# Make sure our host still exists
host_name = self.iscsi_driver._helpers.get_host_from_connector(
self._connector)
self._connector, iscsi=True)
self.assertIsNotNone(host_name)
# Remove the mapping from the 2nd volume. The host should
@ -2696,11 +2698,11 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
fake_conn = {'ip': '127.0.0.1', 'initiator': 'iqn.fake'}
self.iscsi_driver.initialize_connection(volume2, self._connector)
host_name = self.iscsi_driver._helpers.get_host_from_connector(
self._connector)
self._connector, iscsi=True)
self.assertIsNotNone(host_name)
self.iscsi_driver.terminate_connection(volume2, fake_conn)
host_name = self.iscsi_driver._helpers.get_host_from_connector(
self._connector)
self._connector, iscsi=True)
self.assertIsNone(host_name)
self.iscsi_driver.delete_volume(volume2)
self._assert_vol_exists(volume2['name'], False)
@ -2713,7 +2715,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase):
if self.USESIM:
ret = (
self.iscsi_driver._helpers.get_host_from_connector(
self._connector))
self._connector, iscsi=True))
self.assertIsNone(ret)
def test_storwize_svc_iscsi_multi_host_maps(self):
@ -2878,18 +2880,12 @@ class StorwizeSVCFcDriverTestCase(test.TestCase):
'wwnns': ['20000090fa17311e', '20000090fa17311f'],
'wwpns': ['ff00000000000000', 'ff00000000000001'],
'initiator': 'iqn.1993-08.org.debian:01:eac5ccc1aaa'}
self.fc_driver.initialize_connection(volume_fc, connector)
# Create a FC host
helper = self.fc_driver._helpers
if self.USESIM:
# tell lsfabric to not return anything
self.sim.error_injection('lsfabric', 'no_hosts')
host_name = helper.get_host_from_connector(
connector, volume_fc['name'])
if self.USESIM:
self.sim.error_injection('lsfabric', 'no_hosts')
self.assertIsNotNone(host_name)
def test_storwize_get_host_from_connector_with_lshost_failure(self):
@ -4206,19 +4202,20 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase):
tmpconn1 = {'initiator': u'unicode:initiator1.%s' % rand_id,
'ip': '10.10.10.10',
'host': u'unicode.foo}.bar{.baz-%s' % rand_id}
self.driver._helpers.create_host(tmpconn1)
self.driver._helpers.create_host(tmpconn1, iscsi=True)
# Add a host with a different prefix
tmpconn2 = {'initiator': u'unicode:initiator2.%s' % rand_id,
'ip': '10.10.10.11',
'host': u'unicode.hello.world-%s' % rand_id}
self.driver._helpers.create_host(tmpconn2)
self.driver._helpers.create_host(tmpconn2, iscsi=True)
conn = {'initiator': u'unicode:initiator3.%s' % rand_id,
'ip': '10.10.10.12',
'host': u'unicode.foo}.bar}.baz-%s' % rand_id}
self.driver.initialize_connection(volume1, conn)
host_name = self.driver._helpers.get_host_from_connector(conn)
host_name = self.driver._helpers.get_host_from_connector(
conn, iscsi=True)
self.assertIsNotNone(host_name)
self.driver.terminate_connection(volume1, conn)
host_name = self.driver._helpers.get_host_from_connector(conn)
@ -4227,7 +4224,8 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase):
# Clean up temporary hosts
for tmpconn in [tmpconn1, tmpconn2]:
host_name = self.driver._helpers.get_host_from_connector(tmpconn)
host_name = self.driver._helpers.get_host_from_connector(
tmpconn, iscsi=True)
self.assertIsNotNone(host_name)
self.driver._helpers.delete_host(host_name)

View File

@ -823,13 +823,14 @@ class StorwizeHelpers(object):
wwpns.add(wwpn)
return list(wwpns)
def get_host_from_connector(self, connector, volume_name=None):
def get_host_from_connector(self, connector, volume_name=None,
iscsi=False):
"""Return the Storwize host described by the connector."""
LOG.debug('Enter: get_host_from_connector: %s.', connector)
# If we have FC information, we have a faster lookup option
host_name = None
if 'wwpns' in connector:
if 'wwpns' in connector and not iscsi:
for wwpn in connector['wwpns']:
resp = self.ssh.lsfabric(wwpn=wwpn)
for wwpn_info in resp:
@ -894,12 +895,13 @@ class StorwizeHelpers(object):
# unexpected error so reraise it
with excutils.save_and_reraise_exception():
pass
if 'initiator' in connector:
for iscsi in resp.select('iscsi_name'):
if iscsi == connector['initiator']:
host_name = name
found = True
break
if iscsi:
if 'initiator' in connector:
for iscsi in resp.select('iscsi_name'):
if iscsi == connector['initiator']:
host_name = name
found = True
break
elif 'wwpns' in connector and len(connector['wwpns']):
connector_wwpns = [str(x).lower() for x in connector['wwpns']]
for wwpn in resp.select('WWPN'):
@ -913,7 +915,7 @@ class StorwizeHelpers(object):
LOG.debug('Leave: get_host_from_connector: host %s.', host_name)
return host_name
def create_host(self, connector):
def create_host(self, connector, iscsi=False):
"""Create a new host on the storage system.
We create a host name and associate it with the given connection
@ -932,13 +934,18 @@ class StorwizeHelpers(object):
raise exception.VolumeDriverException(message=msg)
ports = []
if 'initiator' in connector:
ports.append(['initiator', '%s' % connector['initiator']])
if 'wwpns' in connector:
for wwpn in connector['wwpns']:
ports.append(['wwpn', '%s' % wwpn])
if iscsi:
if 'initiator' in connector:
ports.append(['initiator', '%s' % connector['initiator']])
else:
msg = _('create_host: No initiators supplied.')
else:
if 'wwpns' in connector:
for wwpn in connector['wwpns']:
ports.append(['wwpn', '%s' % wwpn])
else:
msg = _('create_host: No wwpns supplied.')
if not len(ports):
msg = _('create_host: No initiators or wwpns supplied.')
LOG.error(msg)
raise exception.VolumeDriverException(message=msg)

View File

@ -135,10 +135,11 @@ class StorwizeSVCISCSIDriver(storwize_common.StorwizeSVCCommonDriver):
volume_name = self._get_target_vol(volume)
# Check if a host object is defined for this host name
host_name = self._helpers.get_host_from_connector(connector)
host_name = self._helpers.get_host_from_connector(connector,
iscsi=True)
if host_name is None:
# Host does not exist - add a new host to Storwize/SVC
host_name = self._helpers.create_host(connector)
host_name = self._helpers.create_host(connector, iscsi=True)
chap_secret = self._helpers.get_chap_secret_for_host(host_name)
chap_enabled = self.configuration.storwize_svc_iscsi_chap_enabled
@ -242,7 +243,7 @@ class StorwizeSVCISCSIDriver(storwize_common.StorwizeSVCCommonDriver):
auth_password=chap_secret,
discovery_auth_method='CHAP',
discovery_auth_username=connector['initiator'],
discovery_auth_password= chap_secret)
discovery_auth_password=chap_secret)
LOG.debug('leave: _get_single_iscsi_data:\n volume: %(vol)s\n '
'connector: %(conn)s\n lun_id: %(lun_id)s\n '
'properties: %(prop)s',
@ -334,8 +335,8 @@ class StorwizeSVCISCSIDriver(storwize_common.StorwizeSVCCommonDriver):
# get host according to iSCSI protocol
info = {'driver_volume_type': 'iscsi',
'data': {}}
host_name = self._helpers.get_host_from_connector(connector)
host_name = self._helpers.get_host_from_connector(connector,
iscsi=True)
if host_name is None:
msg = (_('terminate_connection: Failed to get host name from'
' connector.'))