From aca3a197d96db8b2a4efc94c3eeb3c5976d6703d Mon Sep 17 00:00:00 2001 From: Avishay Traeger Date: Tue, 16 Jul 2013 12:24:30 +0300 Subject: [PATCH] Implement validate_connector for Storwize/SVC. Implement the new validate_connector API for the Storwize/SVC driver. Change-Id: I637f406c2592b158a7941da3657a0517972b0996 --- cinder/tests/test_storwize_svc.py | 29 +++++++++++++++++++++++++++ cinder/volume/drivers/storwize_svc.py | 13 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index ad083a4a2..4b27c046c 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -1661,6 +1661,35 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.assertNotEqual(host_name, None) self.driver._delete_host(host_name) + def test_storwize_svc_validate_connector(self): + conn_neither = {'host': 'host'} + conn_iscsi = {'host': 'host', 'initiator': 'foo'} + conn_fc = {'host': 'host', 'wwpns': 'bar'} + conn_both = {'host': 'host', 'initiator': 'foo', 'wwpns': 'bar'} + + self.driver._enabled_protocols = set(['iSCSI']) + self.driver.validate_connector(conn_iscsi) + self.driver.validate_connector(conn_both) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.validate_connector, conn_fc) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.validate_connector, conn_neither) + + self.driver._enabled_protocols = set(['FC']) + self.driver.validate_connector(conn_fc) + self.driver.validate_connector(conn_both) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.validate_connector, conn_iscsi) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.validate_connector, conn_neither) + + self.driver._enabled_protocols = set(['iSCSI', 'FC']) + self.driver.validate_connector(conn_iscsi) + self.driver.validate_connector(conn_fc) + self.driver.validate_connector(conn_both) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.validate_connector, conn_neither) + def test_storwize_svc_host_maps(self): # Create two volumes to be used in mappings diff --git a/cinder/volume/drivers/storwize_svc.py b/cinder/volume/drivers/storwize_svc.py index 296feae5f..7618ea15a 100755 --- a/cinder/volume/drivers/storwize_svc.py +++ b/cinder/volume/drivers/storwize_svc.py @@ -660,6 +660,19 @@ class StorwizeSVCDriver(san.SanISCSIDriver): return wwpns + def validate_connector(self, connector): + """Check connector for at least one enabled protocol (iSCSI/FC).""" + valid = False + if 'iSCSI' in self._enabled_protocols and 'initiator' in connector: + valid = True + if 'FC' in self._enabled_protocols and 'wwpns' in connector: + valid = True + if not valid: + err_msg = (_('The connector does not contain the required ' + 'information.')) + LOG.error(err_msg) + raise exception.VolumeBackendAPIException(data=err_msg) + def initialize_connection(self, volume, connector): """Perform the necessary work so that an iSCSI/FC connection can be made. -- 2.45.2