From 2d888670817a1761e27d7482267ad1fcab0443a9 Mon Sep 17 00:00:00 2001 From: Tingting Zha Date: Thu, 3 Aug 2017 14:14:07 +0800 Subject: [PATCH] Fujitsu Driver: Fix exception in terminate_connection with no connector Force-detach should be ok when connector is None. When connector is None, we change the driver to detach the volume from anything its attached to. Change-Id: I244e392ff00ef333a4ea823fb7b27da457c4fcea Closes-Bug: #1708329 --- .../tests/unit/volume/drivers/test_fujitsu.py | 17 +++++++++++++++++ .../volume/drivers/fujitsu/eternus_dx_common.py | 3 ++- cinder/volume/drivers/fujitsu/eternus_dx_fc.py | 15 +++++++++------ .../volume/drivers/fujitsu/eternus_dx_iscsi.py | 4 +++- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/test_fujitsu.py b/cinder/tests/unit/volume/drivers/test_fujitsu.py index 535cc14b6c2..0471953a29d 100644 --- a/cinder/tests/unit/volume/drivers/test_fujitsu.py +++ b/cinder/tests/unit/volume/drivers/test_fujitsu.py @@ -761,8 +761,17 @@ class FJFCDriverTestCase(test.TestCase): info = self.driver.initialize_connection(TEST_VOLUME, TEST_CONNECTOR) self.assertEqual(fake_info, info) + # Call terminate_connection with connector. self.driver.terminate_connection(TEST_VOLUME, TEST_CONNECTOR) + + info = self.driver.initialize_connection(TEST_VOLUME, + TEST_CONNECTOR) + self.assertEqual(fake_info, info) + # Call terminate_connection without connector. + self.driver.terminate_connection(TEST_VOLUME, + None) + self.driver.delete_volume(TEST_VOLUME) def test_create_and_delete_snapshot(self): @@ -879,8 +888,16 @@ class FJISCSIDriverTestCase(test.TestCase): info = self.driver.initialize_connection(TEST_VOLUME, TEST_CONNECTOR) self.assertEqual(fake_info, info) + # Call terminate_connection with connector. self.driver.terminate_connection(TEST_VOLUME, TEST_CONNECTOR) + + info = self.driver.initialize_connection(TEST_VOLUME, + TEST_CONNECTOR) + self.assertEqual(fake_info, info) + # Call terminate_connection without connector. + self.driver.terminate_connection(TEST_VOLUME, + None) self.driver.delete_volume(TEST_VOLUME) def test_create_and_delete_snapshot(self): diff --git a/cinder/volume/drivers/fujitsu/eternus_dx_common.py b/cinder/volume/drivers/fujitsu/eternus_dx_common.py index 16649678b5a..04ba94f9eee 100644 --- a/cinder/volume/drivers/fujitsu/eternus_dx_common.py +++ b/cinder/volume/drivers/fujitsu/eternus_dx_common.py @@ -728,7 +728,8 @@ class FJDXCommon(object): {'vid': volume['id'], 'prtcl': self.protocol, 'frc': force}) self.conn = self._get_eternus_connection() - map_exist = self._unmap_lun(volume, connector) + force = True if not connector else force + map_exist = self._unmap_lun(volume, connector, force) LOG.debug('terminate_connection, map_exist: %s.', map_exist) return map_exist diff --git a/cinder/volume/drivers/fujitsu/eternus_dx_fc.py b/cinder/volume/drivers/fujitsu/eternus_dx_fc.py index dd667c7e73d..efc90498028 100644 --- a/cinder/volume/drivers/fujitsu/eternus_dx_fc.py +++ b/cinder/volume/drivers/fujitsu/eternus_dx_fc.py @@ -171,20 +171,23 @@ class FJDXFCDriver(driver.FibreChannelDriver): @fczm_utils.remove_fc_zone def terminate_connection(self, volume, connector, **kwargs): """Disallow connection from connector.""" + wwpns = connector.get('wwpns') if connector else None + LOG.debug('terminate_connection, volume id: %(vid)s, ' 'wwpns: %(wwpns)s, enter method.', - {'vid': volume['id'], 'wwpns': connector['wwpns']}) + {'vid': volume['id'], 'wwpns': wwpns}) map_exist = self.common.terminate_connection(volume, connector) - attached = self.common.check_attached_volume_in_zone(connector) info = {'driver_volume_type': 'fibre_channel', 'data': {}} - if not attached: - # No more volumes attached to the host - init_tgt_map = self.common.build_fc_init_tgt_map(connector) - info['data'] = {'initiator_target_map': init_tgt_map} + if connector: + attached = self.common.check_attached_volume_in_zone(connector) + if not attached: + # No more volumes attached to the host + init_tgt_map = self.common.build_fc_init_tgt_map(connector) + info['data'] = {'initiator_target_map': init_tgt_map} LOG.debug('terminate_connection, unmap: %(unmap)s, ' 'connection info: %(info)s, exit method', diff --git a/cinder/volume/drivers/fujitsu/eternus_dx_iscsi.py b/cinder/volume/drivers/fujitsu/eternus_dx_iscsi.py index dcb14b1b690..bdd654be258 100644 --- a/cinder/volume/drivers/fujitsu/eternus_dx_iscsi.py +++ b/cinder/volume/drivers/fujitsu/eternus_dx_iscsi.py @@ -173,9 +173,11 @@ class FJDXISCSIDriver(driver.ISCSIDriver): def terminate_connection(self, volume, connector, **kwargs): """Disallow connection from connector.""" + initiator = connector.get('initiator') if connector else None + LOG.info('terminate_connection, volume id: %(vid)s, ' 'initiator: %(initiator)s, Enter method.', - {'vid': volume['id'], 'initiator': connector['initiator']}) + {'vid': volume['id'], 'initiator': initiator}) map_exist = self.common.terminate_connection(volume, connector)