Fix "connector=None" issue in Kaminario drivers

Currently, Kaminario Cinder FC and iSCSI volume drivers are not
handling "connector=None" in the terminate_connection. This causes
the failure of the following tempest test:
test_volumes_actions.VolumesActionsTest.test_force_detach_volume

This patch handles "connector=None" in the terminate_connection
for Kaminario Cinder FC and iSCSI volume drivers.

Change-Id: Id0e9c235d7260081da20ef7ced7ad28d42e3e03a
Closes-Bug: #1829398
Co-Authored-By: Srinivas Dasthagiri <srinivasd@biarca.com>
(cherry picked from commit 49331b2bb6)
This commit is contained in:
Nikesh Kumar Mahalka 2019-05-20 05:09:35 -04:00 committed by nikesh
parent 6e5180441d
commit 4467c231b0
4 changed files with 47 additions and 4 deletions

View File

@ -586,6 +586,11 @@ class TestKaminarioISCSI(TestKaminarioCommon):
result = self.driver.terminate_connection(self.vol, CONNECTOR)
self.assertIsNone(result)
def test_terminate_connection_without_connector(self):
"""Test terminate_connection_without_connector."""
result = self.driver.terminate_connection(self.vol, None)
self.assertIsNone(result)
class TestKaminarioFC(TestKaminarioCommon):
@ -614,6 +619,11 @@ class TestKaminarioFC(TestKaminarioCommon):
result = self.driver.terminate_connection(self.vol, CONNECTOR)
self.assertIn('data', result)
def test_terminate_connection_without_connector(self):
"""Test terminate_connection_without_connector."""
result = self.driver.terminate_connection(self.vol, None)
self.assertIn('data', result)
def test_get_initiator_host_name_unique(self):
connector = CONNECTOR.copy()
del connector['initiator']

View File

@ -917,9 +917,14 @@ class KaminarioCinderDriver(cinder.volume.driver.ISCSIDriver):
volume = volume_rs.hits[0]
else:
vol_name = volume.name
# Get host object.
host_name = self.get_initiator_host_name(connector)
host_name = ""
if connector is None:
vol_map_rs = self.client.search("mappings", {"volume": volume})
if hasattr(vol_map_rs, "hits") and vol_map_rs.total != 0:
host_name = vol_map_rs.hits[0].host.name
else:
# Get host object.
host_name = self.get_initiator_host_name(connector)
host_rs = self.client.search("hosts", name=host_name)
if hasattr(host_rs, "hits") and host_rs.total != 0 and volume:
host = host_rs.hits[0]

View File

@ -83,9 +83,30 @@ class KaminarioFCDriver(common.KaminarioCinderDriver):
fczm_utils.add_fc_zone(conn_info)
return conn_info
def get_hostname_initiator_pwwn(self, volume):
init_host = None
init_host_name = ""
init_pwwn = []
vol_map_rs = self.client.search("mappings", {"volume": volume})
if hasattr(vol_map_rs, "hits") and vol_map_rs.total != 0:
init_host = vol_map_rs.hits[0].host
init_host_name = init_host.name
if init_host is not None:
host_fc_ports = self.client.search("host_fc_ports", host=init_host)
if hasattr(host_fc_ports, "hits") and host_fc_ports.total != 0:
for port in host_fc_ports.hits:
if port.pwwn:
init_pwwn.append((port.pwwn).replace(':', ''))
return init_host_name, init_pwwn
@utils.trace
@coordination.synchronized('{self.k2_lock_name}')
def terminate_connection(self, volume, connector, **kwargs):
if connector is None:
host_name, init_pwwn = self.get_hostname_initiator_pwwn(volume)
else:
host_name = self.get_initiator_host_name(connector)
# To support replication failback
temp_client = None
if (hasattr(volume, 'replication_status') and
@ -94,13 +115,14 @@ class KaminarioFCDriver(common.KaminarioCinderDriver):
self.client = self.target
super(KaminarioFCDriver, self).terminate_connection(volume, connector)
properties = {"driver_volume_type": "fibre_channel", "data": {}}
host_name = self.get_initiator_host_name(connector)
host_rs = self.client.search("hosts", name=host_name)
# In terminate_connection, host_entry is deleted if host
# is not attached to any volume
if host_rs.total == 0:
# Get target wwpns.
target_wwpns = self.get_target_info(volume)
if connector is None:
connector = {'wwpns': init_pwwn}
target_wwpns, init_target_map = self._build_initiator_target_map(
connector, target_wwpns)
properties["data"] = {"target_wwn": target_wwpns,

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Kaminario FC and iSCSI drivers: Fixed `bug 1829398
<https://bugs.launchpad.net/cinder/+bug/1829398>`_ where
force detach would fail.