Ensures API v2 router does not load plugin twice
Fixes bug 1020024 The router will simply use the QuantumManager which stores the instance of the plugin being used by the Quantum server. Changes to unit tests are for ensuring plugin instances are recycled across tests. Change-Id: I339a40ee6fef74d938245e9c50c7ed695d866e3b
This commit is contained in:
parent
ffac2b42e5
commit
eded5bba4e
@ -125,9 +125,7 @@ class APIRouter(wsgi.Router):
|
||||
|
||||
def __init__(self, **local_config):
|
||||
mapper = routes_mapper.Mapper()
|
||||
plugin_provider = cfg.CONF.core_plugin
|
||||
LOG.debug("Plugin location:%s", plugin_provider)
|
||||
plugin = manager.get_plugin(plugin_provider)
|
||||
plugin = manager.QuantumManager.get_plugin()
|
||||
|
||||
col_kwargs = dict(collection_actions=COLLECTION_ACTIONS,
|
||||
member_actions=MEMBER_ACTIONS)
|
||||
|
@ -33,19 +33,6 @@ from quantum.openstack.common import importutils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_plugin(plugin_provider):
|
||||
# If the plugin can't be found let them know gracefully
|
||||
try:
|
||||
LOG.info("Loading Plugin: %s" % plugin_provider)
|
||||
plugin_klass = importutils.import_class(plugin_provider)
|
||||
except ClassNotFound:
|
||||
LOG.exception("Error loading plugin")
|
||||
raise Exception("Plugin not found. You can install a "
|
||||
"plugin with: pip install <plugin-name>\n"
|
||||
"Example: pip install quantum-sample-plugin")
|
||||
return plugin_klass()
|
||||
|
||||
|
||||
class QuantumManager(object):
|
||||
|
||||
_instance = None
|
||||
@ -61,7 +48,16 @@ class QuantumManager(object):
|
||||
# for performance metrics.
|
||||
plugin_provider = cfg.CONF.core_plugin
|
||||
LOG.debug("Plugin location:%s", plugin_provider)
|
||||
self.plugin = get_plugin(plugin_provider)
|
||||
# If the plugin can't be found let them know gracefully
|
||||
try:
|
||||
LOG.info("Loading Plugin: %s" % plugin_provider)
|
||||
plugin_klass = importutils.import_class(plugin_provider)
|
||||
except ClassNotFound:
|
||||
LOG.exception("Error loading plugin")
|
||||
raise Exception("Plugin not found. You can install a "
|
||||
"plugin with: pip install <plugin-name>\n"
|
||||
"Example: pip install quantum-sample-plugin")
|
||||
self.plugin = plugin_klass()
|
||||
|
||||
@classmethod
|
||||
def get_plugin(cls):
|
||||
|
@ -28,6 +28,7 @@ from quantum.api.v2 import views
|
||||
from quantum.common import config
|
||||
from quantum.common import exceptions as q_exc
|
||||
from quantum import context
|
||||
from quantum.manager import QuantumManager
|
||||
from quantum.openstack.common import cfg
|
||||
|
||||
|
||||
@ -133,6 +134,8 @@ class APIv2TestCase(unittest.TestCase):
|
||||
# will get around this.
|
||||
def setUp(self):
|
||||
plugin = 'quantum.quantum_plugin_base_v2.QuantumPluginBaseV2'
|
||||
# Ensure 'stale' patched copies of the plugin are never returned
|
||||
QuantumManager._instance = None
|
||||
# Create the default configurations
|
||||
args = ['--config-file', etcdir('quantum.conf.test')]
|
||||
config.parse(args=args)
|
||||
|
@ -27,6 +27,7 @@ from quantum.common import config
|
||||
from quantum.common import exceptions as q_exc
|
||||
from quantum import context
|
||||
from quantum.db import api as db
|
||||
from quantum.manager import QuantumManager
|
||||
from quantum.openstack.common import cfg
|
||||
from quantum.tests.unit.testlib_api import create_request
|
||||
from quantum.wsgi import Serializer, JSONDeserializer
|
||||
@ -50,6 +51,8 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
||||
# doesn't like when the plugin changes ;)
|
||||
db._ENGINE = None
|
||||
db._MAKER = None
|
||||
# Make sure at each test a new instance of the plugin is returned
|
||||
QuantumManager._instance = None
|
||||
|
||||
self._tenant_id = 'test-tenant'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user