From 4467c231b029e608104068d33780b8ad021c00d1 Mon Sep 17 00:00:00 2001 From: Nikesh Kumar Mahalka Date: Mon, 20 May 2019 05:09:35 -0400 Subject: [PATCH] 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 (cherry picked from commit 49331b2bb6fc8154343fe2655a0c57e814cf4f7a) --- .../unit/volume/drivers/test_kaminario.py | 10 ++++++++ .../drivers/kaminario/kaminario_common.py | 11 ++++++--- .../volume/drivers/kaminario/kaminario_fc.py | 24 ++++++++++++++++++- ...io-cinder-driver-bug-44c728f026394a85.yaml | 6 +++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/kaminario-cinder-driver-bug-44c728f026394a85.yaml diff --git a/cinder/tests/unit/volume/drivers/test_kaminario.py b/cinder/tests/unit/volume/drivers/test_kaminario.py index 74b062a4ef6..144f8e07598 100644 --- a/cinder/tests/unit/volume/drivers/test_kaminario.py +++ b/cinder/tests/unit/volume/drivers/test_kaminario.py @@ -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'] diff --git a/cinder/volume/drivers/kaminario/kaminario_common.py b/cinder/volume/drivers/kaminario/kaminario_common.py index b1105f4dd2d..aac72515c07 100644 --- a/cinder/volume/drivers/kaminario/kaminario_common.py +++ b/cinder/volume/drivers/kaminario/kaminario_common.py @@ -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] diff --git a/cinder/volume/drivers/kaminario/kaminario_fc.py b/cinder/volume/drivers/kaminario/kaminario_fc.py index 83cfdd5f5c2..c275721ffcd 100644 --- a/cinder/volume/drivers/kaminario/kaminario_fc.py +++ b/cinder/volume/drivers/kaminario/kaminario_fc.py @@ -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, diff --git a/releasenotes/notes/kaminario-cinder-driver-bug-44c728f026394a85.yaml b/releasenotes/notes/kaminario-cinder-driver-bug-44c728f026394a85.yaml new file mode 100644 index 00000000000..66d7bc88803 --- /dev/null +++ b/releasenotes/notes/kaminario-cinder-driver-bug-44c728f026394a85.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Kaminario FC and iSCSI drivers: Fixed `bug 1829398 + `_ where + force detach would fail.