From 3b3e325ee59505d75f1142181c2ee25b440b3c63 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 29 Jun 2012 10:56:59 -0400 Subject: use import_object_ns for compute_driver loading Part of bp:virt-driver-cleanup Convert to using import_object_ns which allows us to import specific virt drivers as 'libvirt.LibvirtDriver' instead of 'nova.virt.libvirt.libvirtDriver'. Update testing to ensure this works with both short names and long names (which need not be in the nova.virt namespace). Change-Id: I5eee3389c7719d5f361532b0eddaa249233283a5 --- nova/compute/manager.py | 2 +- nova/tests/test_virt_drivers.py | 6 +++++- nova/virt/connection.py | 13 +++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 3cdf35266..98552d641 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -239,7 +239,7 @@ class ComputeManager(manager.SchedulerDependentManager): try: self.driver = utils.check_isinstance( - importutils.import_object(compute_driver), + importutils.import_object_ns('nova.virt', compute_driver), driver.ComputeDriver) except ImportError as e: LOG.error(_("Unable to load the virtualization driver: %s") % (e)) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 6443c6721..91845dce7 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -117,9 +117,13 @@ class VirtDriverLoaderTestCase(_FakeDriverBackendTestCase): final class""" # if your driver supports being tested in a fake way, it can go here + # + # both long form and short form drivers are supported new_drivers = { 'nova.virt.fake.FakeDriver': 'FakeDriver', - 'nova.virt.libvirt.LibvirtDriver': 'LibvirtDriver' + 'nova.virt.libvirt.LibvirtDriver': 'LibvirtDriver', + 'fake.FakeDriver': 'FakeDriver', + 'libvirt.LibvirtDriver': 'LibvirtDriver' } # NOTE(sdague): remove after Folsom release when connection_type diff --git a/nova/virt/connection.py b/nova/virt/connection.py index 079675da3..e47079b80 100644 --- a/nova/virt/connection.py +++ b/nova/virt/connection.py @@ -33,11 +33,11 @@ LOG = logging.getLogger(__name__) FLAGS = flags.FLAGS known_drivers = { - 'baremetal': 'nova.virt.baremetal.proxy.ProxyConnection', - 'fake': 'nova.virt.fake.FakeDriver', - 'libvirt': 'nova.virt.libvirt.LibvirtDriver', - 'vmwareapi': 'nova.virt.vmwareapi_conn.VMWareESXDriver', - 'xenapi': 'nova.virt.xenapi.connection.XenAPIDriver' + 'baremetal': 'baremetal.proxy.ProxyConnection', + 'fake': 'fake.FakeDriver', + 'libvirt': 'libvirt.LibvirtDriver', + 'vmwareapi': 'vmwareapi_conn.VMWareESXDriver', + 'xenapi': 'xenapi.connection.XenAPIDriver' } @@ -75,7 +75,8 @@ def get_connection(read_only=False): if driver_name is None: raise exception.VirtDriverNotFound(name=FLAGS.connection_type) - conn = importutils.import_object(driver_name, read_only=read_only) + conn = importutils.import_object_ns('nova.virt', driver_name, + read_only=read_only) if conn is None: LOG.error(_('Failed to open connection to underlying virt platform')) -- cgit