From: Bob Callaway Date: Tue, 21 Oct 2014 19:23:51 +0000 (-0400) Subject: Raise exception if invalid IP is specified X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6fb9f5c02f557eb419615abb07cda9d044407c90;p=openstack-build%2Fcinder-build.git Raise exception if invalid IP is specified 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 --- diff --git a/cinder/tests/test_netapp_eseries_iscsi.py b/cinder/tests/test_netapp_eseries_iscsi.py index 4aae0d14c..daa4294bf 100644 --- a/cinder/tests/test_netapp_eseries_iscsi.py +++ b/cinder/tests/test_netapp_eseries_iscsi.py @@ -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) diff --git a/cinder/volume/drivers/netapp/eseries/iscsi.py b/cinder/volume/drivers/netapp/eseries/iscsi.py index be26cbbe8..031550ecf 100644 --- a/cinder/volume/drivers/netapp/eseries/iscsi.py +++ b/cinder/volume/drivers/netapp/eseries/iscsi.py @@ -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]