]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use string exception casting everywhere
authorMartin Roy <mroy@iweb.com>
Thu, 18 Jun 2015 17:45:02 +0000 (13:45 -0400)
committerMartin Roy <mroy@iweb.com>
Mon, 22 Jun 2015 13:13:56 +0000 (09:13 -0400)
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

neutron/agent/linux/ip_lib.py
neutron/agent/linux/utils.py
neutron/api/v2/resource.py
neutron/cmd/sanity/checks.py
neutron/plugins/embrane/agent/dispatcher.py
neutron/plugins/embrane/agent/operations/router_operations.py
neutron/tests/functional/agent/l3/test_namespace_manager.py
neutron/tests/tempest/common/accounts.py
neutron/tests/unit/agent/linux/test_ip_lib.py
neutron/tests/unit/api/test_extensions.py
neutron/tests/unit/test_manager.py

index 6e317947af4a0caa4c8f90ab4892736d6e7a2668..feb5f6b400c2070791c3a4383c614ead8c365d6a 100644 (file)
@@ -482,7 +482,7 @@ class IpRouteCommand(IpDeviceCommandBase):
             self._as_root([ip_version], tuple(args))
         except RuntimeError as rte:
             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
                     raise exceptions.DeviceNotFoundError(
                         device_name=self.name)
index dc22a0e069bc9c777442e0b67945eb1dc67a20b2..6b2d6af70618b50b9bf2607fe090b79910e9783a 100644 (file)
@@ -182,7 +182,7 @@ def find_child_pids(pid):
         # Unexpected errors are the responsibility of the caller
         with excutils.save_and_reraise_exception() as ctxt:
             # 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:
                 ctxt.reraise = False
                 return []
index dec23b00a2e3bc438b12bc2731b3b3e13d7ac202..2fd66d1a4e92a7fcedb01398fba70dbfae9ceec0 100644 (file)
@@ -179,7 +179,7 @@ def translate(translatable, locale):
     elif isinstance(translatable, webob.exc.HTTPError):
         translatable.detail = localize(translatable.detail, locale)
     elif isinstance(translatable, Exception):
-        translatable.message = localize(translatable.message, locale)
+        translatable.message = localize(translatable, locale)
     else:
         return localize(translatable, locale)
     return translatable
index c31f5777dd0c8346fdb3f6ffea597fa3715d0524..d04f3a98a40f2a20e681f14d06dc91d77cb96a93 100644 (file)
@@ -174,7 +174,7 @@ def ovsdb_native_supported():
     except ImportError as ex:
         LOG.error(_LE("Failed to import required modules. Ensure that the "
                       "python-openvswitch package is installed. Error: %s"),
-                  ex.message)
+                  ex)
     except Exception as ex:
         LOG.exception(six.text_type(ex))
 
index fb5101f88e7c2598447455442839bcc0bef7dcef..8cee30ebb47d33c1c4e682b5921ac053f3fe7a61 100644 (file)
@@ -108,10 +108,10 @@ class Dispatcher(object):
                         h_exc.BrokenInterface, h_exc.DvaCreationFailed,
                         h_exc.DvaCreationPending, h_exc.BrokenDva,
                         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
                 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
                 finally:
                     # if the returned transient state is None, no operations
index 47d13a654594af677446567c88fde9baae2bf08f..932e03c20aa6e57d056a0dd39501b23a25e7f13c 100644 (file)
@@ -60,7 +60,7 @@ def _create_dva_and_assign_address(api, tenant_id, neutron_router,
                                        neutron_router["admin_state_up"],
                                        ip_allocation_info)
     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)
     return state
@@ -110,7 +110,7 @@ def _grow_dva_iface_and_assign_address(api, tenant_id, neutron_router,
                                        neutron_router["admin_state_up"],
                                        ip_allocation_info)
     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)
     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
                 p_con.Status.READY)
     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)
     return state
 
index b85e03ba7adf3f230f32da33e20d5ad5f1ddfd21..335796dc89640305b832d9a2114d0cb6d3c56bf6 100755 (executable)
@@ -49,7 +49,7 @@ class NamespaceManagerTestFramework(base.BaseSudoTestCase):
         except RuntimeError as e:
             # If the namespace didn't exist when delete was attempted, mission
             # 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
 
     def _namespace_exists(self, namespace):
index 1fcef11881f3e164bde93735a02d6f33c03330b0..1a50e3caf8ea5c3e820ca0f2c7d36b8ff11a7f87 100644 (file)
@@ -271,7 +271,7 @@ class NotLockingAccounts(Accounts):
                 return getattr(user, cred_arg) != getattr(alt_user, cred_arg)
             except exceptions.InvalidCredentials as ic:
                 msg = "At least one of the configured credentials is " \
-                      "not valid: %s" % ic.message
+                      "not valid: %s" % ic
                 raise exceptions.InvalidConfiguration(msg)
         else:
             # TODO(andreaf) Add a uniqueness check here
index 51ac34cfe95ef3bff2bf65e1eff62b5d55ae02d3..ea77ae5c914470373bc700d0a4f512f09dfa40fc 100644 (file)
@@ -793,7 +793,7 @@ class TestIpRouteCommand(TestIPCmdBase):
                            'dev', self.parent.name,
                            '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._assert_sudo([self.ip_version],
                           ('del', 'default',
@@ -801,6 +801,20 @@ class TestIpRouteCommand(TestIPCmdBase):
                            'dev', self.parent.name,
                            '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):
         for test_case in self.test_cases:
             self.parent._run = mock.Mock(return_value=test_case['sample'])
index 9a32e865f941d8ccb20db6cbfeab404e683f3d92..fdf35a294374873dd26e9a150e5f473361de706c 100644 (file)
@@ -160,7 +160,7 @@ class ResourceExtensionTest(base.BaseTestCase):
             # Shouldn't be reached
             self.assertTrue(False)
         except webtest.AppError as e:
-            self.assertIn('501', e.message)
+            self.assertIn('501', str(e))
 
     def test_resource_can_be_added_as_extension(self):
         res_ext = extensions.ResourceExtension(
index a29a9d63b46a69fcf0f3db2cf94cd91c1c852e8a..59ecb58a88e3aa610d5f205cfd2697e8e3a52663 100644 (file)
@@ -77,7 +77,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
                                "DummyServicePlugin"])
         cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
         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):
         cfg.CONF.set_override("service_plugins", ["dummy", "dummy"])
@@ -99,7 +99,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
                               "neutron.tests.unit.test_manager."
                               "MultiServiceCorePlugin")
         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):
         cfg.CONF.set_override("core_plugin",