]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Raise exception if invalid IP is specified
authorBob Callaway <bob.callaway@netapp.com>
Tue, 21 Oct 2014 19:23:51 +0000 (15:23 -0400)
committerBob Callaway <bob.callaway@netapp.com>
Mon, 1 Dec 2014 15:58:44 +0000 (15:58 +0000)
This patch ensures that all values specified for the configuration
option netapp_controller_ips are valid, rather than logging and
continuing with only the valid addresses.

Closes-Bug: 1396718

Change-Id: I180dc74e4535bfde19f1741cff975f5ec675dd21

cinder/tests/test_netapp_eseries_iscsi.py
cinder/volume/drivers/netapp/eseries/iscsi.py

index 4aae0d14c2ae5d30de2b9f758c263a09bdff6804..daa4294bf70ad6c07ef9040f993f295adb019a2c 100644 (file)
@@ -996,3 +996,50 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase):
         scheme = url.scheme
         self.assertEqual(446, port)
         self.assertEqual('https', scheme)
+
+    def test_setup_good_controller_ip(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '127.0.0.1'
+        driver = common.NetAppDriver(configuration=configuration)
+        driver._check_mode_get_or_register_storage_system
+
+    def test_setup_good_controller_ips(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '127.0.0.2,127.0.0.1'
+        driver = common.NetAppDriver(configuration=configuration)
+        driver._check_mode_get_or_register_storage_system
+
+    def test_setup_missing_controller_ip(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = None
+        driver = common.NetAppDriver(configuration=configuration)
+        self.assertRaises(exception.InvalidInput,
+                          driver.do_setup, context='context')
+
+    def test_setup_error_invalid_controller_ip(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '987.65.43.21'
+        driver = common.NetAppDriver(configuration=configuration)
+        self.assertRaises(exception.NoValidHost,
+                          driver._check_mode_get_or_register_storage_system)
+
+    def test_setup_error_invalid_first_controller_ip(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '987.65.43.21,127.0.0.1'
+        driver = common.NetAppDriver(configuration=configuration)
+        self.assertRaises(exception.NoValidHost,
+                          driver._check_mode_get_or_register_storage_system)
+
+    def test_setup_error_invalid_second_controller_ip(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '127.0.0.1,987.65.43.21'
+        driver = common.NetAppDriver(configuration=configuration)
+        self.assertRaises(exception.NoValidHost,
+                          driver._check_mode_get_or_register_storage_system)
+
+    def test_setup_error_invalid_both_controller_ips(self):
+        configuration = self._set_config(create_configuration())
+        configuration.netapp_controller_ips = '564.124.1231.1,987.65.43.21'
+        driver = common.NetAppDriver(configuration=configuration)
+        self.assertRaises(exception.NoValidHost,
+                          driver._check_mode_get_or_register_storage_system)
index be26cbbe8813ecf68b4b3a87fe1dec4aee6d713f..031550ecff7913036b3e6e48ecf89c06932c5859 100644 (file)
@@ -145,16 +145,15 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver):
             except socket.gaierror as e:
                 LOG.error(_LE('Error resolving host %(host)s. Error - %(e)s.')
                           % {'host': host, 'e': e})
-                return None
+                raise exception.NoValidHost(
+                    _("Controller IP '%(host)s' could not be resolved: %(e)s.")
+                    % {'host': host, 'e': e})
 
         ips = self.configuration.netapp_controller_ips
         ips = [i.strip() for i in ips.split(",")]
         ips = [x for x in ips if _resolve_host(x)]
         host = na_utils.resolve_hostname(
             self.configuration.netapp_server_hostname)
-        if not ips:
-            msg = _('Controller ips not valid after resolution.')
-            raise exception.NoValidHost(reason=msg)
         if host in ips:
             LOG.info(_LI('Embedded mode detected.'))
             system = self._client.list_storage_systems()[0]