Merge "Use openstack.common.importutils."
This commit is contained in:
@@ -40,6 +40,7 @@ from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.network import linux_net
|
||||
from nova.openstack.common import importutils
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
@@ -52,7 +53,7 @@ def add_lease(mac, ip_address):
|
||||
"""Set the IP that was assigned by the DHCP server."""
|
||||
if FLAGS.fake_rabbit:
|
||||
LOG.debug(_("leasing ip"))
|
||||
network_manager = utils.import_object(FLAGS.network_manager)
|
||||
network_manager = importutils.import_object(FLAGS.network_manager)
|
||||
network_manager.lease_fixed_ip(context.get_admin_context(),
|
||||
ip_address)
|
||||
else:
|
||||
@@ -74,7 +75,7 @@ def del_lease(mac, ip_address):
|
||||
"""Called when a lease expires."""
|
||||
if FLAGS.fake_rabbit:
|
||||
LOG.debug(_("releasing ip"))
|
||||
network_manager = utils.import_object(FLAGS.network_manager)
|
||||
network_manager = importutils.import_object(FLAGS.network_manager)
|
||||
network_manager.release_fixed_ip(context.get_admin_context(),
|
||||
ip_address)
|
||||
else:
|
||||
@@ -88,7 +89,7 @@ def init_leases(network_id):
|
||||
"""Get the list of hosts for a network."""
|
||||
ctxt = context.get_admin_context()
|
||||
network_ref = db.network_get(ctxt, network_id)
|
||||
network_manager = utils.import_object(FLAGS.network_manager)
|
||||
network_manager = importutils.import_object(FLAGS.network_manager)
|
||||
return network_manager.get_dhcp_leases(ctxt, network_ref)
|
||||
|
||||
|
||||
|
||||
@@ -76,21 +76,22 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
|
||||
|
||||
gettext.install('nova', unicode=1)
|
||||
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.auth import manager
|
||||
from nova.compat import flagfile
|
||||
from nova.compute import instance_types
|
||||
from nova import context
|
||||
from nova import crypto
|
||||
from nova import db
|
||||
from nova.db import migration
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova import version
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.auth import manager
|
||||
from nova.compute import instance_types
|
||||
from nova.db import migration
|
||||
from nova.volume import volume_types
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -794,7 +795,7 @@ class NetworkCommands(object):
|
||||
fixed_cidr = netaddr.IPNetwork(fixed_cidr)
|
||||
|
||||
# create the network
|
||||
net_manager = utils.import_object(FLAGS.network_manager)
|
||||
net_manager = importutils.import_object(FLAGS.network_manager)
|
||||
net_manager.create_networks(context.get_admin_context(),
|
||||
label=label,
|
||||
cidr=fixed_range_v4,
|
||||
@@ -863,7 +864,7 @@ class NetworkCommands(object):
|
||||
if fixed_range is None and uuid is None:
|
||||
raise Exception("Please specify either fixed_range or uuid")
|
||||
|
||||
net_manager = utils.import_object(FLAGS.network_manager)
|
||||
net_manager = importutils.import_object(FLAGS.network_manager)
|
||||
if "QuantumManager" in FLAGS.network_manager:
|
||||
if uuid is None:
|
||||
raise Exception("UUID is required to delete Quantum Networks")
|
||||
|
||||
@@ -35,6 +35,7 @@ from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova import utils
|
||||
from nova.auth import signer
|
||||
|
||||
@@ -247,9 +248,9 @@ class AuthManager(object):
|
||||
__init__ is run every time AuthManager() is called, so we only
|
||||
reset the driver if it is not set or a new driver is specified.
|
||||
"""
|
||||
self.network_manager = utils.import_object(FLAGS.network_manager)
|
||||
self.network_manager = importutils.import_object(FLAGS.network_manager)
|
||||
if driver or not getattr(self, 'driver', None):
|
||||
self.driver = utils.import_class(driver or FLAGS.auth_driver)
|
||||
self.driver = importutils.import_class(driver or FLAGS.auth_driver)
|
||||
if AuthManager.mc is None:
|
||||
AuthManager.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from nova import flags
|
||||
from nova import utils
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -117,7 +118,7 @@ def notify(publisher_id, event_type, priority, payload):
|
||||
# Ensure everything is JSON serializable.
|
||||
payload = utils.to_primitive(payload, convert_instances=True)
|
||||
|
||||
driver = utils.import_object(FLAGS.notification_driver)
|
||||
driver = importutils.import_module(FLAGS.notification_driver)
|
||||
msg = dict(message_id=str(uuid.uuid4()),
|
||||
publisher_id=publisher_id,
|
||||
event_type=event_type,
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.openstack.common import exception as common_exception
|
||||
from nova.openstack.common import importutils
|
||||
|
||||
|
||||
list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers',
|
||||
@@ -49,8 +49,8 @@ def _get_drivers():
|
||||
drivers = []
|
||||
for notification_driver in FLAGS.list_notifier_drivers:
|
||||
try:
|
||||
drivers.append(utils.import_object(notification_driver))
|
||||
except exception.ClassNotFound as e:
|
||||
drivers.append(importutils.import_module(notification_driver))
|
||||
except ImportError as e:
|
||||
drivers.append(ImportFailureNotifier(e))
|
||||
return drivers
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# under the License.
|
||||
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.openstack.common import importutils
|
||||
|
||||
|
||||
rpc_opts = [
|
||||
@@ -219,5 +219,5 @@ def _get_impl():
|
||||
"""Delay import of rpc_backend until configuration is loaded."""
|
||||
global _RPCIMPL
|
||||
if _RPCIMPL is None:
|
||||
_RPCIMPL = utils.import_object(_CONF.rpc_backend)
|
||||
_RPCIMPL = importutils.import_module(_CONF.rpc_backend)
|
||||
return _RPCIMPL
|
||||
|
||||
@@ -24,6 +24,7 @@ import traceback
|
||||
from nova import exception
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova import utils
|
||||
|
||||
|
||||
@@ -192,8 +193,7 @@ def deserialize_remote_exception(conf, data):
|
||||
return RemoteError(name, failure.get('message'), trace)
|
||||
|
||||
try:
|
||||
__import__(module)
|
||||
mod = sys.modules[module]
|
||||
mod = importutils.import_module(module)
|
||||
klass = getattr(mod, name)
|
||||
if not issubclass(klass, Exception):
|
||||
raise TypeError("Can only deserialize Exceptions")
|
||||
|
||||
@@ -23,8 +23,8 @@ Scheduler that allows routing some calls to one driver and others to another.
|
||||
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova.scheduler import driver
|
||||
from nova import utils
|
||||
|
||||
|
||||
multi_scheduler_opts = [
|
||||
@@ -56,8 +56,10 @@ class MultiScheduler(driver.Scheduler):
|
||||
|
||||
def __init__(self):
|
||||
super(MultiScheduler, self).__init__()
|
||||
compute_driver = utils.import_object(FLAGS.compute_scheduler_driver)
|
||||
volume_driver = utils.import_object(FLAGS.volume_scheduler_driver)
|
||||
compute_driver = importutils.import_object(
|
||||
FLAGS.compute_scheduler_driver)
|
||||
volume_driver = importutils.import_object(
|
||||
FLAGS.volume_scheduler_driver)
|
||||
|
||||
self.drivers = {'compute': compute_driver,
|
||||
'volume': volume_driver}
|
||||
|
||||
@@ -42,6 +42,7 @@ from nova import flags
|
||||
from nova.image import fake as fake_image
|
||||
from nova import log as logging
|
||||
from nova.notifier import test_notifier
|
||||
from nova.openstack.common import importutils
|
||||
import nova.policy
|
||||
from nova import rpc
|
||||
from nova.rpc import common as rpc_common
|
||||
@@ -104,7 +105,7 @@ class BaseTestCase(test.TestCase):
|
||||
stub_network=True,
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager')
|
||||
self.compute = utils.import_object(FLAGS.compute_manager)
|
||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
|
||||
@@ -27,6 +27,7 @@ import nova.image.fake
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import instance_types
|
||||
from nova.notifier import test_notifier
|
||||
from nova.openstack.common import importutils
|
||||
from nova.tests import fake_network
|
||||
|
||||
|
||||
@@ -51,7 +52,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
stub_network=True,
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager')
|
||||
self.compute = utils.import_object(FLAGS.compute_manager)
|
||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
|
||||
@@ -22,8 +22,8 @@ from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DECLARE('console_driver', 'nova.console.manager')
|
||||
@@ -35,7 +35,7 @@ class ConsoleTestCase(test.TestCase):
|
||||
super(ConsoleTestCase, self).setUp()
|
||||
self.flags(console_driver='nova.console.fake.FakeConsoleProxy',
|
||||
stub_compute=True)
|
||||
self.console = utils.import_object(FLAGS.console_manager)
|
||||
self.console = importutils.import_object(FLAGS.console_manager)
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
|
||||
@@ -22,13 +22,14 @@ Tests for Consoleauth Code.
|
||||
|
||||
import time
|
||||
|
||||
from nova.consoleauth import manager
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.consoleauth import manager
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -40,7 +41,7 @@ class ConsoleauthTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ConsoleauthTestCase, self).setUp()
|
||||
self.manager = utils.import_object(FLAGS.consoleauth_manager)
|
||||
self.manager = importutils.import_object(FLAGS.consoleauth_manager)
|
||||
self.context = context.get_admin_context()
|
||||
|
||||
def test_tokens_expire(self):
|
||||
|
||||
@@ -27,18 +27,21 @@ import tempfile
|
||||
from xml.etree import ElementTree
|
||||
from xml.dom import minidom
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.api.ec2 import cloud
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova.tests import fake_network
|
||||
from nova.tests import fake_libvirt_utils
|
||||
from nova import utils
|
||||
from nova.virt import images
|
||||
from nova.virt import driver
|
||||
from nova.virt import firewall as base_firewall
|
||||
@@ -48,8 +51,6 @@ from nova.virt.libvirt import firewall
|
||||
from nova.virt.libvirt import volume
|
||||
from nova.volume import driver as volume_driver
|
||||
from nova.virt.libvirt import utils as libvirt_utils
|
||||
from nova.tests import fake_network
|
||||
from nova.tests import fake_libvirt_utils
|
||||
|
||||
|
||||
try:
|
||||
@@ -693,7 +694,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||
|
||||
# Start test
|
||||
image_service = utils.import_object(FLAGS.image_service)
|
||||
image_service = importutils.import_object(FLAGS.image_service)
|
||||
|
||||
# Assign different image_ref from nova/images/fakes for testing ami
|
||||
test_instance = copy.deepcopy(self.test_instance)
|
||||
@@ -731,7 +732,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||
|
||||
# Start test
|
||||
image_service = utils.import_object(FLAGS.image_service)
|
||||
image_service = importutils.import_object(FLAGS.image_service)
|
||||
|
||||
# Assuming that base image already exists in image_service
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
@@ -766,7 +767,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(snapshot_image_format='qcow2')
|
||||
|
||||
# Start test
|
||||
image_service = utils.import_object(FLAGS.image_service)
|
||||
image_service = importutils.import_object(FLAGS.image_service)
|
||||
|
||||
# Assuming that base image already exists in image_service
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
@@ -800,7 +801,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||
|
||||
# Start test
|
||||
image_service = utils.import_object(FLAGS.image_service)
|
||||
image_service = importutils.import_object(FLAGS.image_service)
|
||||
|
||||
# Assign different image_ref from nova/images/fakes for
|
||||
# testing different base image
|
||||
@@ -838,7 +839,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||
|
||||
# Start test
|
||||
image_service = utils.import_object(FLAGS.image_service)
|
||||
image_service = importutils.import_object(FLAGS.image_service)
|
||||
|
||||
# Assign a non-existent image
|
||||
test_instance = copy.deepcopy(self.test_instance)
|
||||
@@ -1166,8 +1167,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
fake_timer = FakeTime()
|
||||
|
||||
# _fake_network_info must be called before create_fake_libvirt_mock(),
|
||||
# as _fake_network_info calls utils.import_class() and
|
||||
# create_fake_libvirt_mock() mocks utils.import_class().
|
||||
# as _fake_network_info calls importutils.import_class() and
|
||||
# create_fake_libvirt_mock() mocks importutils.import_class().
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
self.create_fake_libvirt_mock()
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
@@ -1201,7 +1202,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def test_live_migration_raises_exception(self):
|
||||
"""Confirms recover method is called when exceptions are raised."""
|
||||
# Preparing data
|
||||
self.compute = utils.import_object(FLAGS.compute_manager)
|
||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||
instance_dict = {'host': 'fake',
|
||||
'power_state': power_state.RUNNING,
|
||||
'vm_state': vm_states.ACTIVE}
|
||||
@@ -1362,8 +1363,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
return
|
||||
|
||||
# _fake_network_info must be called before create_fake_libvirt_mock(),
|
||||
# as _fake_network_info calls utils.import_class() and
|
||||
# create_fake_libvirt_mock() mocks utils.import_class().
|
||||
# as _fake_network_info calls importutils.import_class() and
|
||||
# create_fake_libvirt_mock() mocks importutils.import_class().
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
self.create_fake_libvirt_mock()
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.network import linux_net
|
||||
@@ -211,7 +212,7 @@ class LinuxNetworkTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(LinuxNetworkTestCase, self).setUp()
|
||||
network_driver = FLAGS.network_driver
|
||||
self.driver = utils.import_object(network_driver)
|
||||
self.driver = importutils.import_module(network_driver)
|
||||
self.driver.db = db
|
||||
self.context = context.RequestContext('testuser', 'testproject',
|
||||
is_admin=True)
|
||||
|
||||
@@ -29,10 +29,10 @@ from nova import exception
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
import nova.policy
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
from nova import utils
|
||||
import nova.volume.api
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -44,9 +44,9 @@ class VolumeTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VolumeTestCase, self).setUp()
|
||||
self.compute = utils.import_object(FLAGS.compute_manager)
|
||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||
self.flags(connection_type='fake')
|
||||
self.volume = utils.import_object(FLAGS.volume_manager)
|
||||
self.volume = importutils.import_object(FLAGS.volume_manager)
|
||||
self.context = context.get_admin_context()
|
||||
self.instance_id = db.instance_create(self.context, {})['id']
|
||||
|
||||
@@ -354,7 +354,7 @@ class DriverTestCase(test.TestCase):
|
||||
super(DriverTestCase, self).setUp()
|
||||
self.flags(volume_driver=self.driver_name,
|
||||
logging_default_format_string="%(message)s")
|
||||
self.volume = utils.import_object(FLAGS.volume_manager)
|
||||
self.volume = importutils.import_object(FLAGS.volume_manager)
|
||||
self.context = context.get_admin_context()
|
||||
self.output = ""
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova.tests.db import fakes as db_fakes
|
||||
from nova.tests.xenapi import stubs
|
||||
from nova.tests.glance import stubs as glance_stubs
|
||||
from nova.tests import fake_network
|
||||
from nova.tests import fake_utils
|
||||
from nova import utils
|
||||
from nova.virt.xenapi import connection as xenapi_conn
|
||||
from nova.virt.xenapi import fake as xenapi_fake
|
||||
from nova.virt.xenapi import volume_utils
|
||||
@@ -215,7 +215,7 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
"""Unit tests for VM operations."""
|
||||
def setUp(self):
|
||||
super(XenAPIVMTestCase, self).setUp()
|
||||
self.network = utils.import_object(FLAGS.network_manager)
|
||||
self.network = importutils.import_object(FLAGS.network_manager)
|
||||
self.flags(xenapi_connection_url='test_url',
|
||||
xenapi_connection_password='test_pass',
|
||||
instance_name_template='%d',
|
||||
@@ -1552,7 +1552,7 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForFirewallTests,
|
||||
test_case=self)
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.network = utils.import_object(FLAGS.network_manager)
|
||||
self.network = importutils.import_object(FLAGS.network_manager)
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
self.fw = self.conn._vmops.firewall_driver
|
||||
|
||||
|
||||
Reference in New Issue
Block a user