From 6f1531ab1b5cc62c3e1a5e659119854e4e98601d Mon Sep 17 00:00:00 2001 From: GirishChilukuri Date: Mon, 21 Sep 2020 19:26:03 +0000 Subject: [PATCH] [SVF]: Volume name is not validated for host [Spectrum Virtualize Family] During terminate_connection volume_name is passed as input to ensure that volume mapping for the host is removed. Currently get_host_by_connector ignore the volume_name validation if the host is found in the connector wwpns. This causes issues in some scenarios where WWPNS from different host entry are passed. Closes-Bug: #1892034 Change-Id: I55f7dd92a4a1bab4a6b00d1b42707aa98b4b2eae --- .../volume/drivers/ibm/test_storwize_svc.py | 53 +++++++++++++++++++ .../ibm/storwize_svc/storwize_svc_common.py | 14 +++++ ...t-validated-for-host-4ec0d1bd14281c77.yaml | 7 +++ 3 files changed, 74 insertions(+) create mode 100644 releasenotes/notes/bug-1892034-Volume-name-is-not-validated-for-host-4ec0d1bd14281c77.yaml diff --git a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py index 31e9c3d4053..7df0dc3a184 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py @@ -8364,6 +8364,59 @@ class StorwizeHelpersTestCase(test.TestCase): self.storwize_svc_common.pretreatment_before_revert(vol) stopfcmap.assert_called_once_with('4', split=True) + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lsfabric') + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lshost') + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lsvdiskhostmap') + def test_get_host_from_connector_with_vol(self, + lsvdishosmap, + lshost, + lsfabric): + vol = 'testvol' + connector = {"wwpns": ["10000090fa3870d7", "C050760825191B00"]} + lsfabric.return_value = [{"remote_wwpn": "10000090fa3870d7", + "name": "test_host"}] + raw = "id!name!host_id!host_name!vdisk_UID\n2594!testvol!315!"\ + "test_host!60050768028110A4700000000001168E" + ssh_cmd = ['svcinfo', 'lsvdiskhostmap', '-delim', '!', '"%s"' % vol] + lsvdishosmap.return_value = storwize_svc_common.CLIResponse(raw, + ssh_cmd, + '!', + True) + host = self.storwize_svc_common.get_host_from_connector(connector, + vol) + self.assertEqual(host, "test_host") + lsfabric.assert_called_with(wwpn='10000090fa3870d7') + self.assertEqual(1, lsfabric.call_count) + lsvdishosmap.assert_called_with(vol) + self.assertEqual(1, lsvdishosmap.call_count) + lshost.assert_not_called() + + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lsfabric') + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lshost') + @mock.patch.object(storwize_svc_common.StorwizeSSH, 'lsvdiskhostmap') + def test_get_host_from_connector_wo_vol(self, + lsvdishosmap, + lshost, + lsfabric): + vol = 'testvol' + connector = {"wwpns": ["10000090fa3870d7", "C050760825191B00"]} + lsfabric.return_value = [{"remote_wwpn": "10000090fa3870d7", + "name": "test_host"}] + raw = "id!name!host_id!host_name!vdisk_UID\n2594!testvol!315!"\ + "test_host!60050768028110A4700000000001168E" + ssh_cmd = ['svcinfo', 'lsvdiskhostmap', '-delim', '!', '"%s"' % vol] + lsvdishosmap.return_value = storwize_svc_common.CLIResponse(raw, + ssh_cmd, + '!', + True) + host = self.storwize_svc_common.get_host_from_connector(connector) + self.assertEqual(host, "test_host") + lsfabric.assert_called_with(wwpn='10000090fa3870d7') + self.assertEqual(1, lsfabric.call_count) + lsvdishosmap.assert_not_called() + self.assertEqual(0, lsvdishosmap.call_count) + lshost.assert_not_called() + @ddt.ddt class StorwizeSSHTestCase(test.TestCase): diff --git a/cinder/volume/drivers/ibm/storwize_svc/storwize_svc_common.py b/cinder/volume/drivers/ibm/storwize_svc/storwize_svc_common.py index 26c3e9eaaa3..9577ef0dd87 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/storwize_svc_common.py +++ b/cinder/volume/drivers/ibm/storwize_svc/storwize_svc_common.py @@ -1038,6 +1038,20 @@ class StorwizeHelpers(object): self.handle_keyerror('lsfabric', wwpn_info) if host_name: break + + if host_name and volume_name: + hosts_map_info = self.ssh.lsvdiskhostmap(volume_name) + hosts_map_info_list = list(hosts_map_info.select('host_name')) + if host_name in hosts_map_info_list: + LOG.debug("get_host_from_connector: hosts_map_info:" + " %s", hosts_map_info_list) + LOG.debug('Leave: get_host_from_connector host %s', host_name) + return host_name + else: + LOG.debug('get_host_from_connector: host %s not mapped ' + 'to volume', host_name) + host_name = None + if host_name: LOG.debug('Leave: get_host_from_connector: host %s.', host_name) return host_name diff --git a/releasenotes/notes/bug-1892034-Volume-name-is-not-validated-for-host-4ec0d1bd14281c77.yaml b/releasenotes/notes/bug-1892034-Volume-name-is-not-validated-for-host-4ec0d1bd14281c77.yaml new file mode 100644 index 00000000000..b25fcca94be --- /dev/null +++ b/releasenotes/notes/bug-1892034-Volume-name-is-not-validated-for-host-4ec0d1bd14281c77.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + IBM Spectrum Virtualize Family driver `Bug #1892034 + `_: Fixed issue in + get_host_from_connector that volume name is not validated to get the + host during terminate connection when the volume name is passed as input.