From a221a30b32aa94077f352719b2637b51c1809069 Mon Sep 17 00:00:00 2001 From: Li Min Liu Date: Tue, 22 Apr 2014 10:56:54 +0800 Subject: [PATCH] Storwize/SVC driver detach volume failed If config two backends on the same storage, but the protocol is different, one is FC and the other is iSCSI, that will create two hosts on the storage. When detaching the volume which is attached to the iSCSI host, the driver will get FC host by default, that causes volume status keeps 'detaching'. Change-Id: Idbdb3861574197549625b4a6b6141197e42857ff Closes-Bug: #1310559 --- cinder/tests/test_storwize_svc.py | 58 +++++++++++-------- .../drivers/ibm/storwize_svc/__init__.py | 10 ++++ 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index 1b747854a..39a06dfab 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -2398,15 +2398,13 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.assertNotIn(volume['id'], self.driver._vdiskcopyops) def test_storwize_initiator_multiple_preferred_nodes_matching(self): - # Set the context. - ctxt = context.get_admin_context() # Generate us a test volume - volume = self._generate_vol_info(None, None) - self.driver.create_volume(volume) + volume = self._create_volume() # Fibre Channel volume type - vol_type = volume_types.create(ctxt, 'FC', {'protocol': 'FC'}) + extra_spec = {'capabilities:storage_protocol': ' FC'} + vol_type = volume_types.create(self.ctxt, 'FC', extra_spec) volume['volume_type_id'] = vol_type['id'] @@ -2435,15 +2433,12 @@ class StorwizeSVCDriverTestCase(test.TestCase): 'AABBCCDDEEFF0010') def test_storwize_initiator_multiple_preferred_nodes_no_matching(self): - # Set the context. - ctxt = context.get_admin_context() - # Generate us a test volume - volume = self._generate_vol_info(None, None) - self.driver.create_volume(volume) + volume = self._create_volume() # Fibre Channel volume type - vol_type = volume_types.create(ctxt, 'FC', {'protocol': 'FC'}) + extra_spec = {'capabilities:storage_protocol': ' FC'} + vol_type = volume_types.create(self.ctxt, 'FC', extra_spec) volume['volume_type_id'] = vol_type['id'] @@ -2472,15 +2467,12 @@ class StorwizeSVCDriverTestCase(test.TestCase): 'AABBCCDDEEFF0001') def test_storwize_initiator_single_preferred_node_matching(self): - # Set the context - ctxt = context.get_admin_context() - # Generate us a test volume - volume = self._generate_vol_info(None, None) - self.driver.create_volume(volume) + volume = self._create_volume() # Fibre Channel volume type - vol_type = volume_types.create(ctxt, 'FC', {'protocol': 'FC'}) + extra_spec = {'capabilities:storage_protocol': ' FC'} + vol_type = volume_types.create(self.ctxt, 'FC', extra_spec) volume['volume_type_id'] = vol_type['id'] @@ -2507,16 +2499,36 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.assertEqual(init_ret['data']['target_wwn'], 'AABBCCDDEEFF0012') - def test_storwize_initiator_target_map(self): - # Create two volumes to be used in mappings - ctxt = context.get_admin_context() + def test_storwize_terminate_connection(self): + # create a FC volume + volume_fc = self._create_volume() + extra_spec = {'capabilities:storage_protocol': ' FC'} + vol_type_fc = volume_types.create(self.ctxt, 'FC', extra_spec) + volume_fc['volume_type_id'] = vol_type_fc['id'] + + # create a iSCSI volume + volume_iSCSI = self._create_volume() + extra_spec = {'capabilities:storage_protocol': ' iSCSI'} + vol_type_iSCSI = volume_types.create(self.ctxt, 'iSCSI', extra_spec) + volume_iSCSI['volume_type_id'] = vol_type_iSCSI['id'] + + connector = {'host': 'storwize-svc-host', + 'wwnns': ['20000090fa17311e', '20000090fa17311f'], + 'wwpns': ['ff00000000000000', 'ff00000000000001'], + 'initiator': 'iqn.1993-08.org.debian:01:eac5ccc1aaa'} + + self.driver.initialize_connection(volume_fc, connector) + self.driver.initialize_connection(volume_iSCSI, connector) + self.driver.terminate_connection(volume_iSCSI, connector) + self.driver.terminate_connection(volume_fc, connector) + def test_storwize_initiator_target_map(self): # Generate us a test volume - volume = self._generate_vol_info(None, None) - self.driver.create_volume(volume) + volume = self._create_volume() # FIbre Channel volume type - vol_type = volume_types.create(ctxt, 'FC', {'protocol': 'FC'}) + extra_spec = {'capabilities:storage_protocol': ' FC'} + vol_type = volume_types.create(self.ctxt, 'FC', extra_spec) volume['volume_type_id'] = vol_type['id'] diff --git a/cinder/volume/drivers/ibm/storwize_svc/__init__.py b/cinder/volume/drivers/ibm/storwize_svc/__init__.py index b1f26f947..e2bd9ea9b 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/__init__.py +++ b/cinder/volume/drivers/ibm/storwize_svc/__init__.py @@ -471,6 +471,16 @@ class StorwizeSVCDriver(san.SanDriver): vol_name = volume['name'] if 'host' in connector: + # maybe two hosts on the storage, one is for FC and the other for + # iSCSI, so get host according to protocol + vol_opts = self._get_vdisk_params(volume['volume_type_id']) + connector = connector.copy() + if vol_opts['protocol'] == 'FC': + connector.pop('initiator', None) + elif vol_opts['protocol'] == 'iSCSI': + connector.pop('wwnns', None) + connector.pop('wwpns', None) + host_name = self._helpers.get_host_from_connector(connector) if host_name is None: msg = (_('terminate_connection: Failed to get host name from' -- 2.45.2