Remove generic Exception when using assertRaises

This change fixes errors associated with H202 checks and enables H202
checks.

Change-Id: I28a48d1b58f2f1f6824ee4b45782a0c961fe9fb5
This commit is contained in:
Mark McClain 2013-06-06 20:00:06 -04:00
parent f83931af80
commit 881b629f65
8 changed files with 16 additions and 20 deletions

View File

@ -74,8 +74,9 @@ class Controller(object):
if self._allow_pagination and self._native_pagination: if self._allow_pagination and self._native_pagination:
# Native pagination need native sorting support # Native pagination need native sorting support
if not self._native_sorting: if not self._native_sorting:
raise Exception(_("Native pagination depend on native " raise exceptions.Invalid(
"sorting")) _("Native pagination depend on native sorting")
)
if not self._allow_sorting: if not self._allow_sorting:
LOG.info(_("Allow sorting is enabled because native " LOG.info(_("Allow sorting is enabled because native "
"pagination requires native sorting")) "pagination requires native sorting"))

View File

@ -62,10 +62,6 @@ class PolicyNotAuthorized(NotAuthorized):
message = _("Policy doesn't allow %(action)s to be performed.") 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): class NetworkNotFound(NotFound):
message = _("Network %(net_id)s could not be found") message = _("Network %(net_id)s could not be found")

View File

@ -18,7 +18,6 @@
from oslo.config import cfg from oslo.config import cfg
from quantum.common.exceptions import ClassNotFound
from quantum.openstack.common import importutils from quantum.openstack.common import importutils
from quantum.openstack.common import lockutils from quantum.openstack.common import lockutils
from quantum.openstack.common import log as logging from quantum.openstack.common import log as logging
@ -113,7 +112,7 @@ class QuantumManager(object):
try: try:
LOG.info(_("Loading Plugin: %s"), plugin_provider) LOG.info(_("Loading Plugin: %s"), plugin_provider)
plugin_klass = importutils.import_class(plugin_provider) plugin_klass = importutils.import_class(plugin_provider)
except ClassNotFound: except ImportError:
LOG.exception(_("Error loading plugin")) LOG.exception(_("Error loading plugin"))
raise Exception(_("Plugin not found. You can install a " raise Exception(_("Plugin not found. You can install a "
"plugin with: pip install <plugin-name>\n" "plugin with: pip install <plugin-name>\n"
@ -163,18 +162,18 @@ class QuantumManager(object):
try: try:
LOG.info(_("Loading Plugin: %s"), provider) LOG.info(_("Loading Plugin: %s"), provider)
plugin_class = importutils.import_class(provider) plugin_class = importutils.import_class(provider)
except ClassNotFound: except ImportError:
LOG.exception(_("Error loading plugin")) LOG.exception(_("Error loading plugin"))
raise Exception(_("Plugin not found.")) raise ImportError(_("Plugin not found."))
plugin_inst = plugin_class() plugin_inst = plugin_class()
# only one implementation of svc_type allowed # only one implementation of svc_type allowed
# specifying more than one plugin # specifying more than one plugin
# for the same type is a fatal exception # for the same type is a fatal exception
if plugin_inst.get_plugin_type() in self.service_plugins: if plugin_inst.get_plugin_type() in self.service_plugins:
raise Exception(_("Multiple plugins for service " raise ValueError(_("Multiple plugins for service "
"%s were configured"), "%s were configured"),
plugin_inst.get_plugin_type()) plugin_inst.get_plugin_type())
self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst

View File

@ -84,7 +84,7 @@ class LoadBalancerCallbacks(object):
if (pool.status != constants.ACTIVE if (pool.status != constants.ACTIVE
or pool.vip.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 = {}
retval['pool'] = self.plugin._make_pool_dict(pool) retval['pool'] = self.plugin._make_pool_dict(pool)

View File

@ -19,6 +19,7 @@
import mock import mock
from quantum.common import exceptions
from quantum import context from quantum import context
from quantum.db.loadbalancer import loadbalancer_db as ldb from quantum.db.loadbalancer import loadbalancer_db as ldb
from quantum import manager from quantum import manager
@ -152,7 +153,7 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase):
with self.vip(pool=pool) as vip: with self.vip(pool=pool) as vip:
with self.member(pool_id=vip['vip']['pool_id']): with self.member(pool_id=vip['vip']['pool_id']):
self.assertRaises( self.assertRaises(
Exception, exceptions.Invalid,
self.callbacks.get_logical_device, self.callbacks.get_logical_device,
context.get_admin_context(), context.get_admin_context(),
pool['pool']['id'], pool['pool']['id'],

View File

@ -500,7 +500,7 @@ class APIv2TestCase(APIv2TestBase):
def test_native_pagination_without_native_sorting(self): def test_native_pagination_without_native_sorting(self):
instance = self.plugin.return_value instance = self.plugin.return_value
instance._QuantumPluginBaseV2__native_sorting_support = False 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): def test_native_pagination_without_allow_sorting(self):
cfg.CONF.set_override('allow_sorting', False) cfg.CONF.set_override('allow_sorting', False)

View File

@ -83,7 +83,7 @@ class QuantumManagerTestCase(base.BaseTestCase):
cfg.CONF.set_override("core_plugin", cfg.CONF.set_override("core_plugin",
test_config.get('plugin_name_v2', test_config.get('plugin_name_v2',
DB_PLUGIN_KLASS)) DB_PLUGIN_KLASS))
self.assertRaises(Exception, QuantumManager.get_instance) self.assertRaises(ValueError, QuantumManager.get_instance)
def test_service_plugin_conflicts_with_core_plugin(self): def test_service_plugin_conflicts_with_core_plugin(self):
cfg.CONF.set_override("service_plugins", cfg.CONF.set_override("service_plugins",
@ -92,7 +92,7 @@ class QuantumManagerTestCase(base.BaseTestCase):
cfg.CONF.set_override("core_plugin", cfg.CONF.set_override("core_plugin",
"quantum.tests.unit.test_quantum_manager." "quantum.tests.unit.test_quantum_manager."
"MultiServiceCorePlugin") "MultiServiceCorePlugin")
self.assertRaises(Exception, QuantumManager.get_instance) self.assertRaises(ValueError, QuantumManager.get_instance)
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",

View File

@ -37,8 +37,7 @@ commands = {posargs}
# H302 import only modules # H302 import only modules
# TODO(marun) H404 multi line docstring should start with a summary # TODO(marun) H404 multi line docstring should start with a summary
# TODO(marun) H901,902 use the not operator inline for clarity # 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
ignore = E711,E712,E125,H301,H302,H404,H901,H902,H202
show-source = true show-source = true
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools