Merge "Quantum should use openstack.common.importutils"
This commit is contained in:
commit
1cc89804a3
@ -1,7 +1,7 @@
|
||||
[DEFAULT]
|
||||
|
||||
# The list of modules to copy from openstack-common
|
||||
modules=cfg,iniparser,setup
|
||||
modules=cfg,importutils,iniparser,setup
|
||||
|
||||
# The base module to hold the copy of openstack.common
|
||||
base=quantum
|
||||
|
@ -36,27 +36,6 @@ from quantum.common.exceptions import ProcessExecutionError
|
||||
from quantum.common import flags
|
||||
|
||||
|
||||
def import_class(import_str):
|
||||
"""Returns a class from a string including module and class."""
|
||||
mod_str, _sep, class_str = import_str.rpartition('.')
|
||||
try:
|
||||
__import__(mod_str)
|
||||
return getattr(sys.modules[mod_str], class_str)
|
||||
except (ImportError, ValueError, AttributeError), exc:
|
||||
print(('Inner Exception: %s'), exc)
|
||||
raise exception.ClassNotFound(class_name=class_str)
|
||||
|
||||
|
||||
def import_object(import_str):
|
||||
"""Returns an object including a module or module and class."""
|
||||
try:
|
||||
__import__(import_str)
|
||||
return sys.modules[import_str]
|
||||
except ImportError:
|
||||
cls = import_class(import_str)
|
||||
return cls()
|
||||
|
||||
|
||||
# NOTE(jkoelker) Since to_primitive isn't used anywhere can we just drop it
|
||||
def to_primitive(value):
|
||||
if isinstance(value, (list, tuple)):
|
||||
|
@ -29,6 +29,7 @@ import os
|
||||
from quantum.common import utils
|
||||
from quantum.common.config import find_config_file
|
||||
from quantum.common.exceptions import ClassNotFound
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.quantum_plugin_base import QuantumPluginBase
|
||||
|
||||
|
||||
@ -66,7 +67,7 @@ class QuantumManager(object):
|
||||
|
||||
# If the plugin can't be found let them know gracefully
|
||||
try:
|
||||
plugin_klass = utils.import_class(options['plugin_provider'])
|
||||
plugin_klass = importutils.import_class(options['plugin_provider'])
|
||||
except ClassNotFound:
|
||||
raise Exception("Plugin not found. You can install a "
|
||||
"plugin with: pip install <plugin-name>\n"
|
||||
|
44
quantum/openstack/common/importutils.py
Normal file
44
quantum/openstack/common/importutils.py
Normal file
@ -0,0 +1,44 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Import related utilities and helper functions.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def import_class(import_str):
|
||||
"""Returns a class from a string including module and class"""
|
||||
mod_str, _sep, class_str = import_str.rpartition('.')
|
||||
try:
|
||||
__import__(mod_str)
|
||||
return getattr(sys.modules[mod_str], class_str)
|
||||
except (ImportError, ValueError, AttributeError), exc:
|
||||
raise ImportError('Class %s cannot be found (%s)' %
|
||||
(class_str, str(exc)))
|
||||
|
||||
|
||||
def import_object(import_str, *args, **kwargs):
|
||||
"""Import a class and return an instance of it."""
|
||||
return import_class(import_str)(*args, **kwargs)
|
||||
|
||||
|
||||
def import_module(import_str):
|
||||
"""Import a module."""
|
||||
__import__(import_str)
|
||||
return sys.modules[import_str]
|
@ -21,7 +21,7 @@ import logging
|
||||
import re
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.quantum_plugin_base import QuantumPluginBase
|
||||
from quantum.plugins.cisco import l2network_plugin_configuration as conf
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
@ -44,8 +44,8 @@ class L2Network(QuantumPluginBase):
|
||||
def __init__(self):
|
||||
cdb.initialize()
|
||||
cred.Store.initialize()
|
||||
self._model = utils.import_object(conf.MODEL_CLASS)
|
||||
self._vlan_mgr = utils.import_object(conf.MANAGER_CLASS)
|
||||
self._model = importutils.import_object(conf.MODEL_CLASS)
|
||||
self._vlan_mgr = importutils.import_object(conf.MANAGER_CLASS)
|
||||
LOG.debug("L2Network plugin initialization done successfully\n")
|
||||
|
||||
"""
|
||||
|
@ -22,7 +22,7 @@ import logging
|
||||
import platform
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase
|
||||
from quantum.plugins.cisco import l2network_plugin_configuration as conf
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
@ -45,13 +45,13 @@ class L2NetworkMultiBlade(L2NetworkModelBase):
|
||||
|
||||
def __init__(self):
|
||||
for key in conf.PLUGINS[const.PLUGINS].keys():
|
||||
self._plugins[key] = utils.import_object(
|
||||
conf.PLUGINS[const.PLUGINS][key])
|
||||
plugin_obj = conf.PLUGINS[const.PLUGINS][key]
|
||||
self._plugins[key] = importutils.import_object(plugin_obj)
|
||||
LOG.debug("Loaded device plugin %s\n" %
|
||||
conf.PLUGINS[const.PLUGINS][key])
|
||||
if key in conf.PLUGINS[const.INVENTORY].keys():
|
||||
self._inventory[key] = utils.import_object(
|
||||
conf.PLUGINS[const.INVENTORY][key])
|
||||
inventory_obj = conf.PLUGINS[const.INVENTORY][key]
|
||||
self._inventory[key] = importutils.import_object(inventory_obj)
|
||||
LOG.debug("Loaded device inventory %s\n" %
|
||||
conf.PLUGINS[const.INVENTORY][key])
|
||||
|
||||
|
@ -22,7 +22,7 @@ import logging
|
||||
import platform
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase
|
||||
from quantum.plugins.cisco import l2network_plugin_configuration as conf
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
@ -42,13 +42,13 @@ class L2NetworkSingleBlade(L2NetworkModelBase):
|
||||
|
||||
def __init__(self):
|
||||
for key in conf.PLUGINS[const.PLUGINS].keys():
|
||||
self._plugins[key] = utils.import_object(
|
||||
conf.PLUGINS[const.PLUGINS][key])
|
||||
plugin_obj = conf.PLUGINS[const.PLUGINS][key]
|
||||
self._plugins[key] = importutils.import_object(plugin_obj)
|
||||
LOG.debug("Loaded device plugin %s\n" %
|
||||
conf.PLUGINS[const.PLUGINS][key])
|
||||
if key in conf.PLUGINS[const.INVENTORY].keys():
|
||||
self._inventory[key] = utils.import_object(
|
||||
conf.PLUGINS[const.INVENTORY][key])
|
||||
inventory_obj = conf.PLUGINS[const.INVENTORY][key]
|
||||
self._inventory[key] = importutils.import_object(inventory_obj)
|
||||
LOG.debug("Loaded device inventory %s\n" %
|
||||
conf.PLUGINS[const.INVENTORY][key])
|
||||
|
||||
|
@ -23,7 +23,7 @@ PlugIn for Nexus OS driver
|
||||
import logging
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
from quantum.plugins.cisco.common import cisco_credentials as cred
|
||||
from quantum.plugins.cisco.db import api as db
|
||||
@ -46,7 +46,7 @@ class NexusPlugin(L2DevicePluginBase):
|
||||
"""
|
||||
Extracts the configuration parameters from the configuration file
|
||||
"""
|
||||
self._client = utils.import_object(conf.NEXUS_DRIVER)
|
||||
self._client = importutils.import_object(conf.NEXUS_DRIVER)
|
||||
LOG.debug("Loaded driver %s\n" % conf.NEXUS_DRIVER)
|
||||
self._nexus_ip = conf.NEXUS_IP_ADDRESS
|
||||
self._nexus_username = cred.Store.getUsername(conf.NEXUS_IP_ADDRESS)
|
||||
|
@ -24,7 +24,7 @@ import subprocess
|
||||
import re
|
||||
import time
|
||||
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco import l2network_plugin_configuration as conf
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
from quantum.plugins.cisco.db import services_db as sdb
|
||||
@ -106,8 +106,8 @@ class ServicesLogistics():
|
||||
"""
|
||||
_plugins = {}
|
||||
for key in conf.PLUGINS[const.PLUGINS].keys():
|
||||
_plugins[key] = (
|
||||
utils.import_object(conf.PLUGINS[const.PLUGINS][key]))
|
||||
plugin_obj = conf.PLUGINS[const.PLUGINS][key]
|
||||
_plugins[key] = importutils.import_object(plugin_obj)
|
||||
if not plugin_key in _plugins.keys():
|
||||
LOG.debug("No %s Plugin loaded" % plugin_key)
|
||||
return False
|
||||
|
@ -23,7 +23,7 @@ import logging
|
||||
import unittest
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
from quantum.plugins.cisco.common import cisco_credentials as creds
|
||||
from quantum.plugins.cisco.db import api as db
|
||||
@ -78,8 +78,8 @@ class TestMultiBlade(unittest.TestCase):
|
||||
# Get UCS inventory to make sure all UCSs are affected by tests
|
||||
for key in conf.PLUGINS[const.PLUGINS].keys():
|
||||
if key in conf.PLUGINS[const.INVENTORY].keys():
|
||||
self._inventory[key] = utils.import_object(
|
||||
conf.PLUGINS[const.INVENTORY][key])
|
||||
plugin_obj = conf.PLUGINS[const.INVENTORY][key]
|
||||
self._inventory[key] = importutils.import_object(plugin_obj)
|
||||
|
||||
self.ucs_count = self._inventory['ucs_plugin']._inventory.__len__()
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
import logging
|
||||
|
||||
from quantum.common import exceptions as exc
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import importutils
|
||||
from quantum.plugins.cisco.common import cisco_constants as const
|
||||
from quantum.plugins.cisco.common import cisco_credentials as cred
|
||||
from quantum.plugins.cisco.common import cisco_exceptions as cexc
|
||||
@ -39,7 +39,7 @@ class UCSVICPlugin(L2DevicePluginBase):
|
||||
"""UCS Device Plugin"""
|
||||
|
||||
def __init__(self):
|
||||
self._driver = utils.import_object(conf.UCSM_DRIVER)
|
||||
self._driver = importutils.import_object(conf.UCSM_DRIVER)
|
||||
LOG.debug("Loaded driver %s\n" % conf.UCSM_DRIVER)
|
||||
# TODO (Sumit) Make the counter per UCSM
|
||||
self._port_profile_counter = 0
|
||||
|
@ -25,8 +25,8 @@ import mock
|
||||
from quantum.api.api_common import APIFaultWrapper
|
||||
from quantum.api.networks import Controller
|
||||
from quantum.common.test_lib import test_config
|
||||
from quantum.common import utils
|
||||
from quantum.db import api as db
|
||||
from quantum.openstack.common import importutils
|
||||
import quantum.tests.unit.testlib_api as testlib
|
||||
from quantum.wsgi import XMLDeserializer, JSONDeserializer
|
||||
|
||||
@ -107,7 +107,7 @@ class AbstractAPITest(unittest.TestCase):
|
||||
def setUp(self, api_router_klass, xml_metadata_dict):
|
||||
options = {}
|
||||
options['plugin_provider'] = test_config['plugin_name']
|
||||
api_router_cls = utils.import_class(api_router_klass)
|
||||
api_router_cls = importutils.import_class(api_router_klass)
|
||||
self.api = api_router_cls(options)
|
||||
self.tenant_id = "test_tenant"
|
||||
self.network_name = "test_network"
|
||||
|
Loading…
Reference in New Issue
Block a user