From: Mark Sturdevant Date: Fri, 25 Apr 2014 17:58:42 +0000 (-0700) Subject: Implement validate_connector in FibreChannelDriver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=bdfc450f59a6b73c1548734e0a5cca5a9e6256ab;p=openstack-build%2Fcinder-build.git Implement validate_connector in FibreChannelDriver 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 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 9d37fcfd6..7569e4e60 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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): diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 526a32c88..64da738e1 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -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)