Don't swallow ImportError from load_class_by_alias_or_classname

Before the patch, we were silently swallowing the original ImportError
raised by load_class_by_alias_or_classname that could contain valuable
details about the reason of failure.

This patch reraises the original exception instead of replacing it with
the one with no context. It still logs an error before doing it to make
sure the operator will see it irrespective of what the caller will do
with the exception.

Also, a note to fellow reviewer: No, I don't think it needs a unit test
case. Do you?

Change-Id: Ib47b67da1e7e4b749abb8b1b93888e23d00da00a
This commit is contained in:
Ihar Hrachyshka 2016-09-26 08:55:13 +00:00
parent b6fb169242
commit 83ef231052
1 changed files with 4 additions and 2 deletions

View File

@ -20,10 +20,11 @@ from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
from oslo_service import periodic_task
from oslo_utils import excutils
from osprofiler import profiler
import six
from neutron._i18n import _, _LI
from neutron._i18n import _, _LE, _LI
from neutron.common import utils
from neutron.plugins.common import constants
@ -153,7 +154,8 @@ class NeutronManager(object):
return utils.load_class_by_alias_or_classname(namespace,
plugin_provider)
except ImportError:
raise ImportError(_("Plugin '%s' not found.") % plugin_provider)
with excutils.save_and_reraise_exception():
LOG.error(_LE("Plugin '%s' not found."), plugin_provider)
def _get_plugin_instance(self, namespace, plugin_provider):
plugin_class = self.load_class_for_provider(namespace, plugin_provider)