]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Implement validate_connector in FibreChannelDriver
authorMark Sturdevant <mark.sturdevant@hp.com>
Fri, 25 Apr 2014 17:58:42 +0000 (10:58 -0700)
committerMark Sturdevant <mark.sturdevant@hp.com>
Thu, 1 May 2014 18:35:51 +0000 (11:35 -0700)
The base FibreChannelDriver didn't implement the
validate_connector() method. It fell back to the
parent class which simply does a pass.  Now the
FCDriver checks to ensure that the connector has
wwnns and wwpns and raises an exception if either
one is empty or not set.

Closes-Bug: #1294812

Change-Id: I1e63c4718d24bdb3ead78de871971cdc498f6b01

cinder/tests/test_volume.py
cinder/volume/driver.py

index 9d37fcfd6f1bf0827b200dc8906df844e0f3c4d4..7569e4e60728186087ab06dc71f78bbf1177a0c1 100644 (file)
@@ -3190,12 +3190,51 @@ class FibreChannelTestCase(DriverTestCase):
     """Test Case for FibreChannelDriver."""
     driver_name = "cinder.volume.driver.FibreChannelDriver"
 
-    def test_initialize_connection(self):
+    def setUp(self):
+        super(FibreChannelTestCase, self).setUp()
         self.driver = driver.FibreChannelDriver()
         self.driver.do_setup(None)
+
+    def test_initialize_connection(self):
         self.assertRaises(NotImplementedError,
                           self.driver.initialize_connection, {}, {})
 
+    def test_validate_connector(self):
+        """validate_connector() successful use case.
+
+        validate_connector() does not throw an exception when
+        wwpns and wwnns are both set and both are not empty.
+        """
+        connector = {'wwpns': ["not empty"],
+                     'wwnns': ["not empty"]}
+        self.driver.validate_connector(connector)
+
+    def test_validate_connector_no_wwpns(self):
+        """validate_connector() throws exception when it has no wwpns."""
+        connector = {'wwnns': ["not empty"]}
+        self.assertRaises(exception.VolumeDriverException,
+                          self.driver.validate_connector, connector)
+
+    def test_validate_connector_empty_wwpns(self):
+        """validate_connector() throws exception when it has empty wwpns."""
+        connector = {'wwpns': [],
+                     'wwnns': ["not empty"]}
+        self.assertRaises(exception.VolumeDriverException,
+                          self.driver.validate_connector, connector)
+
+    def test_validate_connector_no_wwnns(self):
+        """validate_connector() throws exception when it has no wwnns."""
+        connector = {'wwpns': ["not empty"]}
+        self.assertRaises(exception.VolumeDriverException,
+                          self.driver.validate_connector, connector)
+
+    def test_validate_connector_empty_wwnns(self):
+        """validate_connector() throws exception when it has empty wwnns."""
+        connector = {'wwnns': [],
+                     'wwpns': ["not empty"]}
+        self.assertRaises(exception.VolumeDriverException,
+                          self.driver.validate_connector, connector)
+
 
 class VolumePolicyTestCase(test.TestCase):
 
index 526a32c8814db9bc70fb77dc0d38a20322b0b5ff..64da738e1c870683838efc181fe4a275fff1e042 100644 (file)
@@ -1022,3 +1022,21 @@ class FibreChannelDriver(VolumeDriver):
         """
         msg = _("Driver must implement initialize_connection")
         raise NotImplementedError(msg)
+
+    def validate_connector(self, connector):
+        """Fail if connector doesn't contain all the data needed by driver.
+
+        Do a check on the connector and ensure that it has wwnns, wwpns.
+        """
+        self.validate_connector_has_setting(connector, 'wwpns')
+        self.validate_connector_has_setting(connector, 'wwnns')
+
+    @staticmethod
+    def validate_connector_has_setting(connector, setting):
+        """Test for non-empty setting in connector."""
+        if setting not in connector or not connector[setting]:
+            msg = (_(
+                "FibreChannelDriver validate_connector failed. "
+                "No '%s'. Make sure HBA state is Online.") % setting)
+            LOG.error(msg)
+            raise exception.VolumeDriverException(message=msg)