]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Implement validate_connector for Storwize/SVC.
authorAvishay Traeger <avishay@il.ibm.com>
Tue, 16 Jul 2013 09:24:30 +0000 (12:24 +0300)
committerAvishay Traeger <avishay@il.ibm.com>
Wed, 17 Jul 2013 03:48:34 +0000 (06:48 +0300)
Implement the new validate_connector API for the Storwize/SVC driver.

Change-Id: I637f406c2592b158a7941da3657a0517972b0996

cinder/tests/test_storwize_svc.py
cinder/volume/drivers/storwize_svc.py

index ad083a4a2a2660d9316fefc94d7121d17c6b1fa4..4b27c046c82bfba7a9be60ab187a8d456eaa1aab 100644 (file)
@@ -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
 
index 296feae5f1808dbad3628b35034ba8ae738dc2b9..7618ea15a3d6e6d03e38bc5a7e8369c5e7377db3 100755 (executable)
@@ -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.