Bug #694880: nova-compute now depends upon Cheetah even when not using libvirt
Only import Cheetah when needed, as we do already with libvirt and libxml2. This ensures that users of other virt backends don't need Cheetah to run nova-compute. Resubmitted with pep8 violations fixed.
This commit is contained in:
commit
71be236ef4
|
@ -33,6 +33,7 @@ flags.DECLARE('instances_path', 'nova.compute.manager')
|
|||
class LibvirtConnTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(LibvirtConnTestCase, self).setUp()
|
||||
libvirt_conn._late_load_cheetah()
|
||||
self.flags(fake_call=True)
|
||||
self.manager = manager.AuthManager()
|
||||
self.user = self.manager.create_user('fake', 'fake', 'fake',
|
||||
|
|
|
@ -58,10 +58,9 @@ from nova.compute import instance_types
|
|||
from nova.compute import power_state
|
||||
from nova.virt import images
|
||||
|
||||
from Cheetah.Template import Template
|
||||
|
||||
libvirt = None
|
||||
libxml2 = None
|
||||
Template = None
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
@ -88,15 +87,26 @@ flags.DEFINE_bool('allow_project_net_traffic',
|
|||
def get_connection(read_only):
|
||||
# These are loaded late so that there's no need to install these
|
||||
# libraries when not using libvirt.
|
||||
# Cheetah is separate because the unit tests want to load Cheetah,
|
||||
# but not libvirt.
|
||||
global libvirt
|
||||
global libxml2
|
||||
if libvirt is None:
|
||||
libvirt = __import__('libvirt')
|
||||
if libxml2 is None:
|
||||
libxml2 = __import__('libxml2')
|
||||
_late_load_cheetah()
|
||||
return LibvirtConnection(read_only)
|
||||
|
||||
|
||||
def _late_load_cheetah():
|
||||
global Template
|
||||
if Template is None:
|
||||
t = __import__('Cheetah.Template', globals(), locals(), ['Template'],
|
||||
-1)
|
||||
Template = t.Template
|
||||
|
||||
|
||||
def _get_net_and_mask(cidr):
|
||||
net = IPy.IP(cidr)
|
||||
return str(net.net()), str(net.netmask())
|
||||
|
|
Loading…
Reference in New Issue