]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove generic Exception when using assertRaises
authorMark McClain <mark.mcclain@dreamhost.com>
Fri, 7 Jun 2013 00:00:06 +0000 (20:00 -0400)
committerMark McClain <mark.mcclain@dreamhost.com>
Fri, 7 Jun 2013 22:10:10 +0000 (18:10 -0400)
This change fixes errors associated with H202 checks and enables H202
checks.

Change-Id: I28a48d1b58f2f1f6824ee4b45782a0c961fe9fb5

quantum/api/v2/base.py
quantum/common/exceptions.py
quantum/manager.py
quantum/plugins/services/agent_loadbalancer/plugin.py
quantum/tests/unit/services/agent_loadbalancer/test_plugin.py
quantum/tests/unit/test_api_v2.py
quantum/tests/unit/test_quantum_manager.py
tox.ini

index 0a117a0a283baf5144cbae1558c70581fbc47ab6..42b1174a51d1e0ec58847cb9a84fd7d6445c19fa 100644 (file)
@@ -74,8 +74,9 @@ class Controller(object):
         if self._allow_pagination and self._native_pagination:
             # Native pagination need native sorting support
             if not self._native_sorting:
-                raise Exception(_("Native pagination depend on native "
-                                  "sorting"))
+                raise exceptions.Invalid(
+                    _("Native pagination depend on native sorting")
+                )
             if not self._allow_sorting:
                 LOG.info(_("Allow sorting is enabled because native "
                            "pagination requires native sorting"))
index 83f6bae02663e9d27d6b753ad2c716b97d78dace..ffc1c2ccefc6e11b3297b8aadec2a9db8dd1a381 100644 (file)
@@ -62,10 +62,6 @@ class PolicyNotAuthorized(NotAuthorized):
     message = _("Policy doesn't allow %(action)s to be performed.")
 
 
-class ClassNotFound(NotFound):
-    message = _("Class %(class_name)s could not be found")
-
-
 class NetworkNotFound(NotFound):
     message = _("Network %(net_id)s could not be found")
 
index 4c6a9f76c74be7a9fe30768f65761db67325f8d1..408ce0d67fe474530257272f7e9d12422473b86a 100644 (file)
@@ -18,7 +18,6 @@
 
 from oslo.config import cfg
 
-from quantum.common.exceptions import ClassNotFound
 from quantum.openstack.common import importutils
 from quantum.openstack.common import lockutils
 from quantum.openstack.common import log as logging
@@ -113,7 +112,7 @@ class QuantumManager(object):
         try:
             LOG.info(_("Loading Plugin: %s"), plugin_provider)
             plugin_klass = importutils.import_class(plugin_provider)
-        except ClassNotFound:
+        except ImportError:
             LOG.exception(_("Error loading plugin"))
             raise Exception(_("Plugin not found.  You can install a "
                             "plugin with: pip install <plugin-name>\n"
@@ -163,18 +162,18 @@ class QuantumManager(object):
             try:
                 LOG.info(_("Loading Plugin: %s"), provider)
                 plugin_class = importutils.import_class(provider)
-            except ClassNotFound:
+            except ImportError:
                 LOG.exception(_("Error loading plugin"))
-                raise Exception(_("Plugin not found."))
+                raise ImportError(_("Plugin not found."))
             plugin_inst = plugin_class()
 
             # only one implementation of svc_type allowed
             # specifying more than one plugin
             # for the same type is a fatal exception
             if plugin_inst.get_plugin_type() in self.service_plugins:
-                raise Exception(_("Multiple plugins for service "
-                                "%s were configured"),
-                                plugin_inst.get_plugin_type())
+                raise ValueError(_("Multiple plugins for service "
+                                   "%s were configured"),
+                                 plugin_inst.get_plugin_type())
 
             self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst
 
index b29f1e771eb5f076af641ca966cbf2420415d141..ba6112178c894728cde3660533966d6d06e93063 100644 (file)
@@ -84,7 +84,7 @@ class LoadBalancerCallbacks(object):
 
             if (pool.status != constants.ACTIVE
                 or pool.vip.status != constants.ACTIVE):
-                raise Exception(_('Expected active pool and vip'))
+                raise q_exc.Invalid(_('Expected active pool and vip'))
 
             retval = {}
             retval['pool'] = self.plugin._make_pool_dict(pool)
index e15f5b0ca567f264b564a0e185cb9e56e3e27552..77b295bf83708d232e1a3bb713c3fdc0a3a365ed 100644 (file)
@@ -19,6 +19,7 @@
 
 import mock
 
+from quantum.common import exceptions
 from quantum import context
 from quantum.db.loadbalancer import loadbalancer_db as ldb
 from quantum import manager
@@ -152,7 +153,7 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase):
             with self.vip(pool=pool) as vip:
                 with self.member(pool_id=vip['vip']['pool_id']):
                     self.assertRaises(
-                        Exception,
+                        exceptions.Invalid,
                         self.callbacks.get_logical_device,
                         context.get_admin_context(),
                         pool['pool']['id'],
index b5c250317188af036715843ce3d74afb46e66358..ee9540157c1e4607a5d1dcb64959326eeaff3037 100644 (file)
@@ -500,7 +500,7 @@ class APIv2TestCase(APIv2TestBase):
     def test_native_pagination_without_native_sorting(self):
         instance = self.plugin.return_value
         instance._QuantumPluginBaseV2__native_sorting_support = False
-        self.assertRaises(Exception, router.APIRouter)
+        self.assertRaises(q_exc.Invalid, router.APIRouter)
 
     def test_native_pagination_without_allow_sorting(self):
         cfg.CONF.set_override('allow_sorting', False)
index e5458a040f0ad0b46b60978e08d6404c78307aa7..419e3d17870c2223d7652360c7b505b58869647d 100644 (file)
@@ -83,7 +83,7 @@ class QuantumManagerTestCase(base.BaseTestCase):
         cfg.CONF.set_override("core_plugin",
                               test_config.get('plugin_name_v2',
                                               DB_PLUGIN_KLASS))
-        self.assertRaises(Exception, QuantumManager.get_instance)
+        self.assertRaises(ValueError, QuantumManager.get_instance)
 
     def test_service_plugin_conflicts_with_core_plugin(self):
         cfg.CONF.set_override("service_plugins",
@@ -92,7 +92,7 @@ class QuantumManagerTestCase(base.BaseTestCase):
         cfg.CONF.set_override("core_plugin",
                               "quantum.tests.unit.test_quantum_manager."
                               "MultiServiceCorePlugin")
-        self.assertRaises(Exception, QuantumManager.get_instance)
+        self.assertRaises(ValueError, QuantumManager.get_instance)
 
     def test_core_plugin_supports_services(self):
         cfg.CONF.set_override("core_plugin",
diff --git a/tox.ini b/tox.ini
index 7b01ff5a2559e619284f6d2d1cc03a35b98b83cb..51489953408982dd699d54e4e7d307860a599732 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -37,8 +37,7 @@ commands = {posargs}
 # H302 import only modules
 # TODO(marun) H404 multi line docstring should start with a summary
 # TODO(marun) H901,902 use the not operator inline for clarity
-# TODO(markmcclain) H202 assertRaises Exception too broad
-ignore = E711,E712,E125,H301,H302,H404,H901,H902,H202
+ignore = E711,E712,E125,H301,H302,H404,H901,H902
 show-source = true
 builtins = _
 exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools