Use string exception casting everywhere
Instead of the deprecated "message" member access, casting to a string invokes the __str__ method of the exception that is wired to return the message Added a test of the failure cases of IpRouteCommand::delete_gateway because they were missing Running unit and functional tests locally no longer shows the warning reported in the bug. Change-Id: Ia79f526aa973ece1145615d65349f860aa3fd465 Closes-Bug: #1466542
This commit is contained in:
parent
ffb3658d0e
commit
fe6654b250
@ -482,7 +482,7 @@ class IpRouteCommand(IpDeviceCommandBase):
|
|||||||
self._as_root([ip_version], tuple(args))
|
self._as_root([ip_version], tuple(args))
|
||||||
except RuntimeError as rte:
|
except RuntimeError as rte:
|
||||||
with (excutils.save_and_reraise_exception()) as ctx:
|
with (excutils.save_and_reraise_exception()) as ctx:
|
||||||
if "Cannot find device" in rte.message:
|
if "Cannot find device" in str(rte):
|
||||||
ctx.reraise = False
|
ctx.reraise = False
|
||||||
raise exceptions.DeviceNotFoundError(
|
raise exceptions.DeviceNotFoundError(
|
||||||
device_name=self.name)
|
device_name=self.name)
|
||||||
|
@ -182,7 +182,7 @@ def find_child_pids(pid):
|
|||||||
# Unexpected errors are the responsibility of the caller
|
# Unexpected errors are the responsibility of the caller
|
||||||
with excutils.save_and_reraise_exception() as ctxt:
|
with excutils.save_and_reraise_exception() as ctxt:
|
||||||
# Exception has already been logged by execute
|
# Exception has already been logged by execute
|
||||||
no_children_found = 'Exit code: 1' in e.message
|
no_children_found = 'Exit code: 1' in str(e)
|
||||||
if no_children_found:
|
if no_children_found:
|
||||||
ctxt.reraise = False
|
ctxt.reraise = False
|
||||||
return []
|
return []
|
||||||
|
@ -179,7 +179,7 @@ def translate(translatable, locale):
|
|||||||
elif isinstance(translatable, webob.exc.HTTPError):
|
elif isinstance(translatable, webob.exc.HTTPError):
|
||||||
translatable.detail = localize(translatable.detail, locale)
|
translatable.detail = localize(translatable.detail, locale)
|
||||||
elif isinstance(translatable, Exception):
|
elif isinstance(translatable, Exception):
|
||||||
translatable.message = localize(translatable.message, locale)
|
translatable.message = localize(translatable, locale)
|
||||||
else:
|
else:
|
||||||
return localize(translatable, locale)
|
return localize(translatable, locale)
|
||||||
return translatable
|
return translatable
|
||||||
|
@ -174,7 +174,7 @@ def ovsdb_native_supported():
|
|||||||
except ImportError as ex:
|
except ImportError as ex:
|
||||||
LOG.error(_LE("Failed to import required modules. Ensure that the "
|
LOG.error(_LE("Failed to import required modules. Ensure that the "
|
||||||
"python-openvswitch package is installed. Error: %s"),
|
"python-openvswitch package is installed. Error: %s"),
|
||||||
ex.message)
|
ex)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.exception(six.text_type(ex))
|
LOG.exception(six.text_type(ex))
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ class Dispatcher(object):
|
|||||||
h_exc.BrokenInterface, h_exc.DvaCreationFailed,
|
h_exc.BrokenInterface, h_exc.DvaCreationFailed,
|
||||||
h_exc.DvaCreationPending, h_exc.BrokenDva,
|
h_exc.DvaCreationPending, h_exc.BrokenDva,
|
||||||
h_exc.ConfigurationFailed) as ex:
|
h_exc.ConfigurationFailed) as ex:
|
||||||
LOG.warning(p_con.error_map[type(ex)], ex.message)
|
LOG.warning(p_con.error_map[type(ex)], ex)
|
||||||
transient_state = p_con.Status.ERROR
|
transient_state = p_con.Status.ERROR
|
||||||
except h_exc.DvaDeleteFailed as ex:
|
except h_exc.DvaDeleteFailed as ex:
|
||||||
LOG.warning(p_con.error_map[type(ex)], ex.message)
|
LOG.warning(p_con.error_map[type(ex)], ex)
|
||||||
transient_state = p_con.Status.DELETED
|
transient_state = p_con.Status.DELETED
|
||||||
finally:
|
finally:
|
||||||
# if the returned transient state is None, no operations
|
# if the returned transient state is None, no operations
|
||||||
|
@ -60,7 +60,7 @@ def _create_dva_and_assign_address(api, tenant_id, neutron_router,
|
|||||||
neutron_router["admin_state_up"],
|
neutron_router["admin_state_up"],
|
||||||
ip_allocation_info)
|
ip_allocation_info)
|
||||||
except h_exc.PreliminaryOperationsFailed as ex:
|
except h_exc.PreliminaryOperationsFailed as ex:
|
||||||
raise h_exc.BrokenInterface(err_msg=ex.message)
|
raise h_exc.BrokenInterface(err_msg=str(ex))
|
||||||
|
|
||||||
state = api.extract_dva_state(dva)
|
state = api.extract_dva_state(dva)
|
||||||
return state
|
return state
|
||||||
@ -110,7 +110,7 @@ def _grow_dva_iface_and_assign_address(api, tenant_id, neutron_router,
|
|||||||
neutron_router["admin_state_up"],
|
neutron_router["admin_state_up"],
|
||||||
ip_allocation_info)
|
ip_allocation_info)
|
||||||
except h_exc.PreliminaryOperationsFailed as ex:
|
except h_exc.PreliminaryOperationsFailed as ex:
|
||||||
raise h_exc.BrokenInterface(err_msg=ex.message)
|
raise h_exc.BrokenInterface(err_msg=str(ex))
|
||||||
|
|
||||||
state = api.extract_dva_state(dva)
|
state = api.extract_dva_state(dva)
|
||||||
return state
|
return state
|
||||||
@ -127,7 +127,7 @@ def _shrink_dva_iface(api, tenant_id, neutron_router, port_id):
|
|||||||
return (p_con.Status.ACTIVE if neutron_router["admin_state_up"] else
|
return (p_con.Status.ACTIVE if neutron_router["admin_state_up"] else
|
||||||
p_con.Status.READY)
|
p_con.Status.READY)
|
||||||
except h_exc.PreliminaryOperationsFailed as ex:
|
except h_exc.PreliminaryOperationsFailed as ex:
|
||||||
raise h_exc.BrokenInterface(err_msg=ex.message)
|
raise h_exc.BrokenInterface(err_msg=str(ex))
|
||||||
state = api.extract_dva_state(dva)
|
state = api.extract_dva_state(dva)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class NamespaceManagerTestFramework(base.BaseSudoTestCase):
|
|||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
# If the namespace didn't exist when delete was attempted, mission
|
# If the namespace didn't exist when delete was attempted, mission
|
||||||
# accomplished. Otherwise, re-raise the exception
|
# accomplished. Otherwise, re-raise the exception
|
||||||
if 'No such file or directory' not in e.message:
|
if 'No such file or directory' not in str(e):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def _namespace_exists(self, namespace):
|
def _namespace_exists(self, namespace):
|
||||||
|
@ -271,7 +271,7 @@ class NotLockingAccounts(Accounts):
|
|||||||
return getattr(user, cred_arg) != getattr(alt_user, cred_arg)
|
return getattr(user, cred_arg) != getattr(alt_user, cred_arg)
|
||||||
except exceptions.InvalidCredentials as ic:
|
except exceptions.InvalidCredentials as ic:
|
||||||
msg = "At least one of the configured credentials is " \
|
msg = "At least one of the configured credentials is " \
|
||||||
"not valid: %s" % ic.message
|
"not valid: %s" % ic
|
||||||
raise exceptions.InvalidConfiguration(msg)
|
raise exceptions.InvalidConfiguration(msg)
|
||||||
else:
|
else:
|
||||||
# TODO(andreaf) Add a uniqueness check here
|
# TODO(andreaf) Add a uniqueness check here
|
||||||
|
@ -793,7 +793,7 @@ class TestIpRouteCommand(TestIPCmdBase):
|
|||||||
'dev', self.parent.name,
|
'dev', self.parent.name,
|
||||||
'table', self.table))
|
'table', self.table))
|
||||||
|
|
||||||
def test_del_gateway(self):
|
def test_del_gateway_success(self):
|
||||||
self.route_cmd.delete_gateway(self.gateway, table=self.table)
|
self.route_cmd.delete_gateway(self.gateway, table=self.table)
|
||||||
self._assert_sudo([self.ip_version],
|
self._assert_sudo([self.ip_version],
|
||||||
('del', 'default',
|
('del', 'default',
|
||||||
@ -801,6 +801,20 @@ class TestIpRouteCommand(TestIPCmdBase):
|
|||||||
'dev', self.parent.name,
|
'dev', self.parent.name,
|
||||||
'table', self.table))
|
'table', self.table))
|
||||||
|
|
||||||
|
def test_del_gateway_cannot_find_device(self):
|
||||||
|
self.parent._as_root.side_effect = RuntimeError("Cannot find device")
|
||||||
|
|
||||||
|
exc = self.assertRaises(exceptions.DeviceNotFoundError,
|
||||||
|
self.route_cmd.delete_gateway,
|
||||||
|
self.gateway, table=self.table)
|
||||||
|
self.assertIn(self.parent.name, str(exc))
|
||||||
|
|
||||||
|
def test_del_gateway_other_error(self):
|
||||||
|
self.parent._as_root.side_effect = RuntimeError()
|
||||||
|
|
||||||
|
self.assertRaises(RuntimeError, self.route_cmd.delete_gateway,
|
||||||
|
self.gateway, table=self.table)
|
||||||
|
|
||||||
def test_get_gateway(self):
|
def test_get_gateway(self):
|
||||||
for test_case in self.test_cases:
|
for test_case in self.test_cases:
|
||||||
self.parent._run = mock.Mock(return_value=test_case['sample'])
|
self.parent._run = mock.Mock(return_value=test_case['sample'])
|
||||||
|
@ -160,7 +160,7 @@ class ResourceExtensionTest(base.BaseTestCase):
|
|||||||
# Shouldn't be reached
|
# Shouldn't be reached
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
except webtest.AppError as e:
|
except webtest.AppError as e:
|
||||||
self.assertIn('501', e.message)
|
self.assertIn('501', str(e))
|
||||||
|
|
||||||
def test_resource_can_be_added_as_extension(self):
|
def test_resource_can_be_added_as_extension(self):
|
||||||
res_ext = extensions.ResourceExtension(
|
res_ext = extensions.ResourceExtension(
|
||||||
|
@ -77,7 +77,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
|||||||
"DummyServicePlugin"])
|
"DummyServicePlugin"])
|
||||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||||
e = self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
e = self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||||
self.assertIn(constants.DUMMY, e.message)
|
self.assertIn(constants.DUMMY, str(e))
|
||||||
|
|
||||||
def test_multiple_plugins_by_name_specified_for_service_type(self):
|
def test_multiple_plugins_by_name_specified_for_service_type(self):
|
||||||
cfg.CONF.set_override("service_plugins", ["dummy", "dummy"])
|
cfg.CONF.set_override("service_plugins", ["dummy", "dummy"])
|
||||||
@ -99,7 +99,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
|||||||
"neutron.tests.unit.test_manager."
|
"neutron.tests.unit.test_manager."
|
||||||
"MultiServiceCorePlugin")
|
"MultiServiceCorePlugin")
|
||||||
e = self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
e = self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||||
self.assertIn(constants.DUMMY, e.message)
|
self.assertIn(constants.DUMMY, str(e))
|
||||||
|
|
||||||
def test_core_plugin_supports_services(self):
|
def test_core_plugin_supports_services(self):
|
||||||
cfg.CONF.set_override("core_plugin",
|
cfg.CONF.set_override("core_plugin",
|
||||||
|
Loading…
Reference in New Issue
Block a user