Merge "Introduce VirtAPI to nova/virt"
This commit is contained in:
commit
a77c0c5016
@ -73,6 +73,7 @@ from nova import quota
|
||||
from nova.scheduler import rpcapi as scheduler_rpcapi
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
from nova.virt import virtapi
|
||||
from nova import volume
|
||||
|
||||
|
||||
@ -209,6 +210,17 @@ def _get_image_meta(context, image_ref):
|
||||
return image_service.show(context, image_id)
|
||||
|
||||
|
||||
class ComputeVirtAPI(virtapi.VirtAPI):
|
||||
def __init__(self, compute):
|
||||
super(ComputeVirtAPI, self).__init__()
|
||||
self._compute = compute
|
||||
|
||||
def instance_update(self, context, instance_uuid, updates):
|
||||
return self._compute.db.instance_update_and_get_original(context,
|
||||
instance_uuid,
|
||||
updates)
|
||||
|
||||
|
||||
class ComputeManager(manager.SchedulerDependentManager):
|
||||
"""Manages the running instances from creation to destruction."""
|
||||
|
||||
@ -225,10 +237,13 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
LOG.error(_("Compute driver option required, but not specified"))
|
||||
sys.exit(1)
|
||||
|
||||
self.virtapi = ComputeVirtAPI(self)
|
||||
|
||||
LOG.info(_("Loading compute driver '%s'") % compute_driver)
|
||||
try:
|
||||
self.driver = utils.check_isinstance(
|
||||
importutils.import_object_ns('nova.virt', compute_driver),
|
||||
importutils.import_object_ns('nova.virt', compute_driver,
|
||||
self.virtapi),
|
||||
driver.ComputeDriver)
|
||||
except ImportError as e:
|
||||
LOG.error(_("Unable to load the virtualization driver: %s") % (e))
|
||||
|
@ -257,7 +257,7 @@ class BareMetalTestCase(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# Code under test
|
||||
conn = driver.BareMetalDriver(True)
|
||||
conn = driver.BareMetalDriver(None, True)
|
||||
# TODO(mikalstill): this is not a very good fake instance
|
||||
info = conn.get_info({'name': 'instance-00000001'})
|
||||
|
||||
|
@ -42,7 +42,7 @@ class UnsupportedVirtDriver(driver.ComputeDriver):
|
||||
|
||||
class FakeVirtDriver(driver.ComputeDriver):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, virtapi):
|
||||
self.memory_mb = 5
|
||||
self.local_gb = 6
|
||||
self.vcpus = 1
|
||||
@ -148,9 +148,9 @@ class BaseTestCase(test.TestCase):
|
||||
host = "fakehost"
|
||||
|
||||
if unsupported:
|
||||
driver = UnsupportedVirtDriver()
|
||||
driver = UnsupportedVirtDriver(None)
|
||||
else:
|
||||
driver = FakeVirtDriver()
|
||||
driver = FakeVirtDriver(None)
|
||||
|
||||
tracker = resource_tracker.ResourceTracker(host, driver)
|
||||
return tracker
|
||||
@ -293,12 +293,12 @@ class ResourceTestCase(BaseTestCase):
|
||||
self.assertEqual(1, self.tracker.compute_node['current_workload'])
|
||||
|
||||
def testFreeRamResourceValue(self):
|
||||
driver = FakeVirtDriver()
|
||||
driver = FakeVirtDriver(None)
|
||||
mem_free = driver.memory_mb - driver.memory_mb_used
|
||||
self.assertEqual(mem_free, self.tracker.compute_node['free_ram_mb'])
|
||||
|
||||
def testFreeDiskResourceValue(self):
|
||||
driver = FakeVirtDriver()
|
||||
driver = FakeVirtDriver(None)
|
||||
mem_free = driver.local_gb - driver.local_gb_used
|
||||
self.assertEqual(mem_free, self.tracker.compute_node['free_disk_gb'])
|
||||
|
||||
|
@ -66,7 +66,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase):
|
||||
vswitch_name='external')
|
||||
|
||||
self._hypervutils = hypervutils.HyperVUtils()
|
||||
self._conn = driver_hyperv.HyperVDriver()
|
||||
self._conn = driver_hyperv.HyperVDriver(None)
|
||||
|
||||
def _setup_stubs(self):
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
|
@ -48,6 +48,7 @@ import nova.tests.image.fake
|
||||
from nova import utils
|
||||
from nova.virt.disk import api as disk
|
||||
from nova.virt import driver
|
||||
from nova.virt import fake
|
||||
from nova.virt import firewall as base_firewall
|
||||
from nova.virt import images
|
||||
from nova.virt.libvirt import config
|
||||
@ -147,7 +148,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
||||
def get_all_block_devices(self):
|
||||
return []
|
||||
|
||||
self.fake_conn = FakeLibvirtDriver()
|
||||
self.fake_conn = FakeLibvirtDriver(fake.FakeVirtAPI())
|
||||
self.connr = {
|
||||
'ip': '127.0.0.1',
|
||||
'initiator': 'fake_initiator',
|
||||
@ -619,7 +620,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(my_ip=ip)
|
||||
self.flags(host=host)
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
expected = {
|
||||
'ip': ip,
|
||||
'initiator': initiator,
|
||||
@ -632,7 +633,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.assertDictMatch(expected, result)
|
||||
|
||||
def test_get_guest_config(self):
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
cfg = conn.get_guest_config(instance_ref,
|
||||
@ -676,7 +677,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"catchup")
|
||||
|
||||
def test_get_guest_config_with_two_nics(self):
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
cfg = conn.get_guest_config(instance_ref,
|
||||
@ -708,7 +709,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
def test_get_guest_config_with_root_device_name(self):
|
||||
self.flags(libvirt_type='uml')
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
cfg = conn.get_guest_config(instance_ref, [], None, None,
|
||||
@ -728,7 +729,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
config.LibvirtConfigGuestConsole)
|
||||
|
||||
def test_get_guest_config_with_block_device(self):
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
conn_info = {'driver_volume_type': 'fake'}
|
||||
@ -746,7 +747,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
def test_get_guest_cpu_config_none(self):
|
||||
self.flags(libvirt_cpu_mode="none")
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
@ -764,7 +765,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
@ -779,7 +780,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(libvirt_type="uml",
|
||||
libvirt_cpu_mode=None)
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
@ -791,7 +792,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(libvirt_type="lxc",
|
||||
libvirt_cpu_mode=None)
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
@ -806,7 +807,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="host-passthrough")
|
||||
@ -825,7 +826,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="host-model")
|
||||
@ -844,7 +845,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="custom")
|
||||
@ -863,7 +864,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.stubs.Set(libvirt.virConnect, "getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="host-passthrough")
|
||||
@ -894,7 +895,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt_driver.LibvirtDriver,
|
||||
"get_host_capabilities",
|
||||
get_host_capabilities_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="host-model")
|
||||
@ -914,7 +915,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
self.flags(libvirt_cpu_mode="custom")
|
||||
@ -1038,7 +1039,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._conn.listDomainsID = lambda: [0, 1]
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
instances = conn.list_instances()
|
||||
# Only one should be listed, since domain with ID 0 must be skiped
|
||||
self.assertEquals(len(instances), 1)
|
||||
@ -1054,7 +1055,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._conn.listDomainsID = lambda: [0, 1]
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
instances = conn.list_instances()
|
||||
# None should be listed, since we fake deleted the last one
|
||||
self.assertEquals(len(instances), 0)
|
||||
@ -1107,7 +1108,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByID = fake_lookup
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
devices = conn.get_all_block_devices()
|
||||
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
||||
|
||||
@ -1168,7 +1169,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
devices = conn.get_disks(conn.list_instances()[0])
|
||||
self.assertEqual(devices, ['vda', 'vdb'])
|
||||
|
||||
@ -1201,7 +1202,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1240,7 +1241,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1279,7 +1280,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1319,7 +1320,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1354,7 +1355,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1390,7 +1391,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1428,7 +1429,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1466,7 +1467,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1499,7 +1500,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -1545,7 +1546,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.create_fake_libvirt_mock()
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertRaises(exception.VolumeDriverNotFound,
|
||||
conn.attach_volume,
|
||||
{"driver_volume_type": "badtype"},
|
||||
@ -1555,7 +1556,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def test_multi_nic(self):
|
||||
instance_data = dict(self.test_instance)
|
||||
network_info = _fake_network_info(self.stubs, 2)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = db.instance_create(self.context, instance_data)
|
||||
xml = conn.to_xml(instance_ref, network_info, None, False)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -1572,7 +1573,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, instance)
|
||||
|
||||
self.flags(libvirt_type='lxc')
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
self.assertEquals(conn.uri, 'lxc:///')
|
||||
|
||||
@ -1615,7 +1616,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
for (libvirt_type, checks) in type_disk_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
xml = conn.to_xml(instance_ref, network_info)
|
||||
@ -1651,9 +1652,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
|
||||
xml = libvirt_driver.LibvirtDriver(True).to_xml(instance_ref,
|
||||
network_info,
|
||||
image_meta)
|
||||
xml = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True).to_xml(
|
||||
instance_ref, network_info, image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
disks = tree.findall('./devices/disk/driver')
|
||||
for disk in disks:
|
||||
@ -1663,9 +1663,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
# The O_DIRECT availability is cached on first use in
|
||||
# LibvirtDriver, hence we re-create it here
|
||||
xml = libvirt_driver.LibvirtDriver(True).to_xml(instance_ref,
|
||||
network_info,
|
||||
image_meta)
|
||||
xml = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True).to_xml(
|
||||
instance_ref, network_info, image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
disks = tree.findall('./devices/disk/driver')
|
||||
for disk in disks:
|
||||
@ -1677,7 +1676,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
|
||||
xml = libvirt_driver.LibvirtDriver(True).to_xml(
|
||||
xml = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True).to_xml(
|
||||
instance_ref,
|
||||
network_info,
|
||||
image_meta,
|
||||
@ -1704,9 +1703,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
|
||||
xml = libvirt_driver.LibvirtDriver(True).to_xml(instance_ref,
|
||||
network_info,
|
||||
image_meta)
|
||||
xml = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True).to_xml(
|
||||
instance_ref, network_info, image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
self.assertEqual(tree.find('./uuid').text,
|
||||
instance_ref['uuid'])
|
||||
@ -1818,7 +1816,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
self.assertEquals(conn.uri, expected_uri)
|
||||
|
||||
@ -1847,7 +1845,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(libvirt_uri=testuri)
|
||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
self.assertEquals(conn.uri, testuri)
|
||||
db.instance_destroy(user_context, instance_ref['uuid'])
|
||||
|
||||
@ -1879,7 +1877,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
# Start test
|
||||
self.mox.ReplayAll()
|
||||
try:
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn.firewall_driver,
|
||||
'setup_basic_filtering',
|
||||
fake_none)
|
||||
@ -1907,7 +1905,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
dest = "fake_host_2"
|
||||
src = instance_ref['host']
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
compute_info = {'disk_available_least': 400,
|
||||
'cpu_info': 'asdf',
|
||||
}
|
||||
@ -1935,7 +1933,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
dest = "fake_host_2"
|
||||
src = instance_ref['host']
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
compute_info = {'cpu_info': 'asdf'}
|
||||
filename = "file"
|
||||
|
||||
@ -1961,7 +1959,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
dest = "fake_host_2"
|
||||
src = instance_ref['host']
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
compute_info = {'cpu_info': 'asdf'}
|
||||
|
||||
self.mox.StubOutWithMock(conn, '_compare_cpu')
|
||||
@ -1980,7 +1978,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"block_migration": True,
|
||||
"disk_over_commit": False,
|
||||
"disk_available_mb": 1024}
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, '_cleanup_shared_storage_test_file')
|
||||
conn._cleanup_shared_storage_test_file("file")
|
||||
@ -1995,7 +1993,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"block_migration": True,
|
||||
"disk_over_commit": False,
|
||||
"disk_available_mb": 1024}
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_check_shared_storage_test_file")
|
||||
conn._check_shared_storage_test_file("file").AndReturn(False)
|
||||
@ -2015,7 +2013,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"block_migration": True,
|
||||
"disk_over_commit": False,
|
||||
'disk_available_mb': 1024}
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_check_shared_storage_test_file")
|
||||
conn._check_shared_storage_test_file("file").AndReturn(True)
|
||||
@ -2031,7 +2029,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"block_migration": False,
|
||||
"disk_over_commit": False,
|
||||
'disk_available_mb': 1024}
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_check_shared_storage_test_file")
|
||||
conn._check_shared_storage_test_file("file").AndReturn(False)
|
||||
@ -2045,7 +2043,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
dest = "fake_host_2"
|
||||
src = instance_ref['host']
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_check_shared_storage_test_file")
|
||||
conn._check_shared_storage_test_file("file").AndReturn(False)
|
||||
@ -2100,7 +2098,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
#start test
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertRaises(libvirt.libvirtError,
|
||||
conn._live_migration,
|
||||
self.context, instance_ref, 'dest', False,
|
||||
@ -2120,7 +2118,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
vol = {'block_device_mapping': [
|
||||
{'connection_info': 'dummy', 'mount_device': '/dev/sda'},
|
||||
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}]}
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
class FakeNetworkInfo():
|
||||
def fixed_ips(self):
|
||||
@ -2174,7 +2172,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
user_id=None).AndReturn(None)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
conn.pre_block_migration(self.context, instance_ref,
|
||||
dummyjson)
|
||||
|
||||
@ -2227,7 +2225,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
'/test/disk.local').AndReturn((ret, ''))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
info = conn.get_instance_disk_info(instance_ref.name)
|
||||
info = jsonutils.loads(info)
|
||||
self.assertEquals(info[0]['type'], 'raw')
|
||||
@ -2284,7 +2282,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
# Start test
|
||||
self.mox.ReplayAll()
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn.firewall_driver,
|
||||
'setup_basic_filtering',
|
||||
fake_none)
|
||||
@ -2343,7 +2341,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup
|
||||
libvirt_driver.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
output = conn.get_console_output(instance)
|
||||
self.assertEquals("foo", output)
|
||||
|
||||
@ -2388,12 +2386,12 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
libvirt_driver.LibvirtDriver._flush_libvirt_console = _fake_flush
|
||||
libvirt_driver.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
output = conn.get_console_output(instance)
|
||||
self.assertEquals("foo", output)
|
||||
|
||||
def test_get_host_ip_addr(self):
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
ip = conn.get_host_ip_addr()
|
||||
self.assertEquals(ip, FLAGS.my_ip)
|
||||
|
||||
@ -2402,7 +2400,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_REMOTE),
|
||||
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_RPC)):
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_wrapped_conn")
|
||||
self.mox.StubOutWithMock(conn._wrapped_conn, "getCapabilities")
|
||||
@ -2422,7 +2420,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def test_volume_in_mapping(self):
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
swap = {'device_name': '/dev/sdb',
|
||||
'swap_size': 1}
|
||||
ephemerals = [{'num': 0,
|
||||
@ -2461,7 +2459,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_lookup_by_name(instance_name):
|
||||
raise exception.InstanceNotFound()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
|
||||
instance = db.instance_create(self.context, self.test_instance)
|
||||
@ -2480,7 +2478,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_get_info(instance_name):
|
||||
return {'state': power_state.SHUTDOWN}
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
@ -2501,7 +2499,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_get_info(instance_name):
|
||||
return {'state': power_state.SHUTDOWN}
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
@ -2524,7 +2522,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_get_info(instance_name):
|
||||
return {'state': power_state.SHUTDOWN}
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
@ -2546,7 +2544,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_get_info(instance_name):
|
||||
return {'state': power_state.SHUTDOWN}
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
@ -2564,7 +2562,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_get_info(instance_name):
|
||||
raise exception.InstanceNotFound()
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
@ -2574,7 +2572,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
def test_available_least_handles_missing(self):
|
||||
"""Ensure destroy calls managedSaveRemove for saved instance"""
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def list_instances():
|
||||
return ['fake']
|
||||
@ -2589,7 +2587,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.assertEqual(result, space / 1024 ** 3)
|
||||
|
||||
def test_cpu_info(self):
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
def get_host_capabilities_stub(self):
|
||||
cpu = config.LibvirtConfigCPU()
|
||||
@ -2681,7 +2679,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
actual = conn.get_diagnostics({"name": "testvirt"})
|
||||
expect = {'vda_read': 688640L,
|
||||
'vda_read_req': 169L,
|
||||
@ -2761,7 +2759,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
actual = conn.get_diagnostics({"name": "testvirt"})
|
||||
expect = {'cpu0_time': 15340000000L,
|
||||
'cpu1_time': 1640000000L,
|
||||
@ -2835,7 +2833,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
actual = conn.get_diagnostics({"name": "testvirt"})
|
||||
expect = {'cpu0_time': 15340000000L,
|
||||
'cpu1_time': 1640000000L,
|
||||
@ -2911,7 +2909,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
actual = conn.get_diagnostics({"name": "testvirt"})
|
||||
expect = {'cpu0_time': 15340000000L,
|
||||
'cpu1_time': 1640000000L,
|
||||
@ -2993,7 +2991,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(False)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
actual = conn.get_diagnostics({"name": "testvirt"})
|
||||
expect = {'cpu0_time': 15340000000L,
|
||||
'cpu1_time': 1640000000L,
|
||||
@ -3024,7 +3022,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.assertEqual(actual, expect)
|
||||
|
||||
def test_get_instance_capabilities(self):
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
def get_host_capabilities_stub(self):
|
||||
caps = config.LibvirtConfigCaps()
|
||||
@ -3107,11 +3105,13 @@ class HostStateTestCase(test.TestCase):
|
||||
return HostStateTestCase.instance_caps
|
||||
|
||||
def test_update_status(self):
|
||||
virtapi = fake.FakeVirtAPI()
|
||||
self.mox.StubOutWithMock(libvirt_driver, 'LibvirtDriver')
|
||||
libvirt_driver.LibvirtDriver(True).AndReturn(self.FakeConnection())
|
||||
libvirt_driver.LibvirtDriver(virtapi, True).AndReturn(
|
||||
self.FakeConnection())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
hs = libvirt_driver.HostState(True)
|
||||
hs = libvirt_driver.HostState(virtapi, True)
|
||||
stats = hs._stats
|
||||
self.assertEquals(stats["vcpus"], 1)
|
||||
self.assertEquals(stats["vcpus_used"], 0)
|
||||
@ -3891,7 +3891,8 @@ class LibvirtDriverTestCase(test.TestCase):
|
||||
"""Test for nova.virt.libvirt.libvirt_driver.LibvirtDriver."""
|
||||
def setUp(self):
|
||||
super(LibvirtDriverTestCase, self).setUp()
|
||||
self.libvirtconnection = libvirt_driver.LibvirtDriver(read_only=True)
|
||||
self.libvirtconnection = libvirt_driver.LibvirtDriver(
|
||||
fake.FakeVirtAPI(), read_only=True)
|
||||
|
||||
def _create_instance(self, params=None):
|
||||
"""Create a test instance"""
|
||||
|
@ -117,7 +117,7 @@ class PowerVMDriverTestCase(test.TestCase):
|
||||
super(PowerVMDriverTestCase, self).setUp()
|
||||
self.stubs.Set(operator, 'get_powervm_operator',
|
||||
fake_get_powervm_operator)
|
||||
self.powervm_connection = powervm_driver.PowerVMDriver()
|
||||
self.powervm_connection = powervm_driver.PowerVMDriver(None)
|
||||
self.instance = self._create_instance()
|
||||
|
||||
def _create_instance(self):
|
||||
|
@ -20,12 +20,14 @@ import sys
|
||||
import traceback
|
||||
|
||||
from nova.compute.manager import ComputeManager
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import log as logging
|
||||
from nova import test
|
||||
from nova.tests.image import fake as fake_image
|
||||
from nova.tests import utils as test_utils
|
||||
from nova.virt import fake
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -171,7 +173,8 @@ class VirtDriverLoaderTestCase(_FakeDriverBackendTestCase):
|
||||
class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||
def setUp(self):
|
||||
super(_VirtDriverTestCase, self).setUp()
|
||||
self.connection = importutils.import_object(self.driver_module, '')
|
||||
self.connection = importutils.import_object(self.driver_module,
|
||||
fake.FakeVirtAPI())
|
||||
self.ctxt = test_utils.get_test_admin_context()
|
||||
self.image_service = fake_image.FakeImageService()
|
||||
|
||||
@ -507,17 +510,7 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||
|
||||
class AbstractDriverTestCase(_VirtDriverTestCase):
|
||||
def setUp(self):
|
||||
from nova.virt.driver import ComputeDriver
|
||||
|
||||
self.driver_module = "nova.virt.driver.ComputeDriver"
|
||||
|
||||
# TODO(sdague): the abstract driver doesn't have a constructor,
|
||||
# add one now that the loader loads classes directly
|
||||
def __new_init__(self, read_only=False):
|
||||
super(ComputeDriver, self).__init__()
|
||||
|
||||
ComputeDriver.__init__ = __new_init__
|
||||
|
||||
super(AbstractDriverTestCase, self).setUp()
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ class VMWareAPIVMTestCase(test.TestCase):
|
||||
vmwareapi_fake.reset()
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
stubs.set_stubs(self.stubs)
|
||||
self.conn = driver.VMWareESXDriver(False)
|
||||
self.conn = driver.VMWareESXDriver(None, False)
|
||||
# NOTE(vish): none of the network plugging code is actually
|
||||
# being tested
|
||||
self.network_info = [({'bridge': 'fa0',
|
||||
|
@ -40,6 +40,7 @@ from nova.tests import fake_network
|
||||
from nova.tests import fake_utils
|
||||
import nova.tests.image.fake as fake_image
|
||||
from nova.tests.xenapi import stubs
|
||||
from nova.virt import fake
|
||||
from nova.virt.xenapi import agent
|
||||
from nova.virt.xenapi import driver as xenapi_conn
|
||||
from nova.virt.xenapi import fake as xenapi_fake
|
||||
@ -231,7 +232,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase):
|
||||
def test_attach_volume(self):
|
||||
"""This shows how to test Ops classes' methods."""
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
volume = self._create_volume()
|
||||
instance = db.instance_create(self.context, self.instance_values)
|
||||
vm = xenapi_fake.create_vm(instance.name, 'Running')
|
||||
@ -249,7 +250,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase):
|
||||
"""This shows how to test when exceptions are raised."""
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForVolumeFailedTests)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
volume = self._create_volume()
|
||||
instance = db.instance_create(self.context, self.instance_values)
|
||||
xenapi_fake.create_vm(instance.name, 'Running')
|
||||
@ -283,7 +284,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
fake_image.stub_out_image_service(self.stubs)
|
||||
set_image_fixtures()
|
||||
@ -822,7 +823,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
xenapi_fake.create_vbd(vm_ref, swap_vdi_ref, userdevice=1)
|
||||
xenapi_fake.create_vbd(vm_ref, root_vdi_ref, userdevice=0)
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
image_meta = {'id': IMAGE_VHD,
|
||||
'disk_format': 'vhd'}
|
||||
conn.rescue(self.context, instance, [], image_meta, '')
|
||||
@ -839,7 +840,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_unrescue(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
# Unrescue expects the original instance to be powered off
|
||||
conn.power_off(instance)
|
||||
rescue_vm = xenapi_fake.create_vm(instance.name + '-rescue', 'Running')
|
||||
@ -847,7 +848,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_unrescue_not_in_rescue(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
# Ensure that it will not unrescue a non-rescued instance.
|
||||
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
|
||||
instance, None)
|
||||
@ -863,25 +864,25 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
def finish_revert_migration(self, instance):
|
||||
self.finish_revert_migration_called = True
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
conn._vmops = VMOpsMock()
|
||||
conn.finish_revert_migration(instance, None)
|
||||
self.assertTrue(conn._vmops.finish_revert_migration_called)
|
||||
|
||||
def test_reboot_hard(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
conn.reboot(instance, None, "HARD")
|
||||
|
||||
def test_reboot_soft(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
conn.reboot(instance, None, "SOFT")
|
||||
|
||||
def test_reboot_halted(self):
|
||||
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
|
||||
instance = self._create_instance(spawn=False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
xenapi_fake.create_vm(instance.name, 'Halted')
|
||||
conn.reboot(instance, None, "SOFT")
|
||||
vm_ref = vm_utils.lookup(session, instance.name)
|
||||
@ -890,7 +891,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_reboot_unknown_state(self):
|
||||
instance = self._create_instance(spawn=False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
xenapi_fake.create_vm(instance.name, 'Unknown')
|
||||
self.assertRaises(xenapi_fake.Failure, conn.reboot, instance,
|
||||
None, "SOFT")
|
||||
@ -1019,7 +1020,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||
product_version=(6, 0, 0),
|
||||
product_brand='XenServer')
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
vdi_ref = xenapi_fake.create_vdi('hurr', 'fake')
|
||||
vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid']
|
||||
conn._vmops._resize_instance(instance,
|
||||
@ -1038,7 +1039,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||
product_version=(1, 4, 99),
|
||||
product_brand='XCP')
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
vdi_ref = xenapi_fake.create_vdi('hurr', 'fake')
|
||||
vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid']
|
||||
conn._vmops._resize_instance(instance,
|
||||
@ -1049,7 +1050,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
instance = db.instance_create(self.context, self.instance_values)
|
||||
xenapi_fake.create_vm(instance.name, 'Running')
|
||||
instance_type = db.instance_type_get_by_name(self.context, 'm1.large')
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
conn.migrate_disk_and_power_off(self.context, instance,
|
||||
'127.0.0.1', instance_type, None)
|
||||
|
||||
@ -1062,7 +1063,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
raise exception.MigrationError(reason='test failure')
|
||||
self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise)
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertRaises(exception.MigrationError,
|
||||
conn.migrate_disk_and_power_off,
|
||||
self.context, instance,
|
||||
@ -1092,7 +1093,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
product_version=(4, 0, 0),
|
||||
product_brand='XenServer')
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -1127,7 +1128,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
product_version=(4, 0, 0),
|
||||
product_brand='XenServer')
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -1149,7 +1150,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
|
||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||
"VDI_resize_online", fake_vdi_resize)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -1165,7 +1166,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
||||
|
||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||
"VDI_resize_online", fake_vdi_resize)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
# Resize instance would be determined by the compute call
|
||||
@ -1256,7 +1257,7 @@ class XenAPIHostTestCase(stubs.XenAPITestBase):
|
||||
xenapi_connection_password='test_pass')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
xenapi_fake.create_local_srs()
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def test_host_state(self):
|
||||
stats = self.conn.get_host_stats()
|
||||
@ -1347,7 +1348,7 @@ class XenAPIAutoDiskConfigTestCase(stubs.XenAPITestBase):
|
||||
firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
@ -1440,7 +1441,7 @@ class XenAPIGenerateLocal(stubs.XenAPITestBase):
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
@ -1528,7 +1529,7 @@ class XenAPIBWCountersTestCase(stubs.XenAPITestBase):
|
||||
firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def _fake_get_vif_device_map(vm_rec):
|
||||
return vm_rec['_vifmap']
|
||||
@ -1661,7 +1662,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
|
||||
test_case=self)
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.network = importutils.import_object(FLAGS.network_manager)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.fw = self.conn._vmops.firewall_driver
|
||||
|
||||
def _create_instance_ref(self):
|
||||
@ -1987,7 +1988,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
||||
host_ref = xenapi_fake.get_all('host')[0]
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.context = context.get_admin_context()
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||
self.api = compute_api.AggregateAPI()
|
||||
values = {'name': 'test_aggr',
|
||||
@ -2392,7 +2393,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_live_migration_calls_vmops(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_live_migrate(context, instance_ref, dest, post_method,
|
||||
recover_method, block_migration, migrate_data):
|
||||
@ -2406,18 +2407,18 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
def test_pre_live_migration(self):
|
||||
# ensure method is present
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.conn.pre_live_migration(None, None, None, None)
|
||||
|
||||
def test_post_live_migration_at_destination(self):
|
||||
# ensure method is present
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.conn.post_live_migration_at_destination(None, None, None, None)
|
||||
|
||||
def test_check_can_live_migrate_destination_with_block_migration(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.stubs.Set(vm_utils, "safe_find_sr", lambda _x: "asdf")
|
||||
|
||||
@ -2436,7 +2437,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
def test_check_can_live_migrate_destination_block_migration_fails(self):
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertRaises(exception.MigrationError,
|
||||
self.conn.check_can_live_migrate_destination,
|
||||
self.context, {'host': 'host'},
|
||||
@ -2445,7 +2446,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_check_can_live_migrate_source_with_block_migrate(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_generate_vdi_map(destination_sr_ref, _vm_ref):
|
||||
pass
|
||||
@ -2470,7 +2471,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
def test_check_can_live_migrate_source_with_block_migrate_fails(self):
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_generate_vdi_map(destination_sr_ref, _vm_ref):
|
||||
pass
|
||||
@ -2497,7 +2498,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_check_can_live_migrate_works(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
class fake_aggregate:
|
||||
def __init__(self):
|
||||
@ -2514,7 +2515,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_check_can_live_migrate_fails(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
class fake_aggregate:
|
||||
def __init__(self):
|
||||
@ -2532,7 +2533,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_live_migration(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_get_vm_opaque_ref(instance):
|
||||
return "fake_vm"
|
||||
@ -2554,7 +2555,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_live_migration_on_failure(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_get_vm_opaque_ref(instance):
|
||||
return "fake_vm"
|
||||
@ -2581,7 +2582,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_live_migration_calls_post_migration(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_generate_vdi_map(destination_sr_ref, _vm_ref):
|
||||
pass
|
||||
@ -2608,7 +2609,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_live_migration_with_block_migration_raises_invalid_param(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_get_vm_opaque_ref(instance):
|
||||
return "fake_vm"
|
||||
@ -2627,7 +2628,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
def test_live_migration_with_block_migration_fails_migrate_send(self):
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_get_vm_opaque_ref(instance):
|
||||
return "fake_vm"
|
||||
@ -2661,7 +2662,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
stubs.stubout_session(self.stubs, Session)
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def fake_get_vm_opaque_ref(instance):
|
||||
return "fake_vm"
|
||||
@ -2687,7 +2688,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def test_generate_vdi_map(self):
|
||||
stubs.stubout_session(self.stubs, xenapi_fake.SessionBase)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
vm_ref = "fake_vm_ref"
|
||||
|
||||
@ -2719,7 +2720,7 @@ class XenAPIInjectMetadataTestCase(stubs.XenAPITestBase):
|
||||
firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.xenstore = dict(persist={}, ephem={})
|
||||
|
||||
@ -2890,7 +2891,7 @@ class VMOpsTestCase(test.TestCase):
|
||||
|
||||
def test_check_resize_func_name_defaults_to_VDI_resize(self):
|
||||
session = self._get_mock_session(None, None)
|
||||
ops = vmops.VMOps(session)
|
||||
ops = vmops.VMOps(session, fake.FakeVirtAPI())
|
||||
|
||||
self.assertEquals(
|
||||
'VDI.resize',
|
||||
|
@ -37,7 +37,6 @@ from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import vm_states
|
||||
from nova import context as nova_context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import notifications
|
||||
@ -78,11 +77,11 @@ def _late_load_cheetah():
|
||||
|
||||
class BareMetalDriver(driver.ComputeDriver):
|
||||
|
||||
def __init__(self, read_only):
|
||||
def __init__(self, virtapi, read_only):
|
||||
_late_load_cheetah()
|
||||
# Note that baremetal doesn't have a read-only connection
|
||||
# mode, so the read_only parameter is ignored
|
||||
super(BareMetalDriver, self).__init__()
|
||||
super(BareMetalDriver, self).__init__(virtapi)
|
||||
self.baremetal_nodes = nodes.get_baremetal_nodes()
|
||||
self._wrapped_conn = None
|
||||
self._host_state = None
|
||||
@ -230,7 +229,7 @@ class BareMetalDriver(driver.ComputeDriver):
|
||||
try:
|
||||
LOG.debug(_("Key is injected but instance is not running yet"),
|
||||
instance=instance)
|
||||
(old_ref, new_ref) = db.instance_update_and_get_original(
|
||||
(old_ref, new_ref) = self.virtapi.instance_update(
|
||||
context, instance['uuid'],
|
||||
{'vm_state': vm_states.BUILDING})
|
||||
notifications.send_update(context, old_ref, new_ref)
|
||||
@ -239,7 +238,7 @@ class BareMetalDriver(driver.ComputeDriver):
|
||||
if state == power_state.RUNNING:
|
||||
LOG.debug(_('instance %s: booted'), instance['name'],
|
||||
instance=instance)
|
||||
(old_ref, new_ref) = db.instance_update_and_get_original(
|
||||
(old_ref, new_ref) = self.virtapi.instance_update(
|
||||
context, instance['uuid'],
|
||||
{'vm_state': vm_states.ACTIVE})
|
||||
notifications.send_update(context, old_ref, new_ref)
|
||||
@ -254,7 +253,7 @@ class BareMetalDriver(driver.ComputeDriver):
|
||||
except Exception:
|
||||
LOG.exception(_("Baremetal assignment is overcommitted."),
|
||||
instance=instance)
|
||||
(old_ref, new_ref) = db.instance_update_and_get_original(
|
||||
(old_ref, new_ref) = self.virtapi.instance_update(
|
||||
context, instance['uuid'],
|
||||
{'vm_state': vm_states.ERROR,
|
||||
'power_state': power_state.FAILED})
|
||||
|
@ -92,6 +92,9 @@ class ComputeDriver(object):
|
||||
"has_imagecache": False,
|
||||
}
|
||||
|
||||
def __init__(self, virtapi):
|
||||
self.virtapi = virtapi
|
||||
|
||||
def init_host(self, host):
|
||||
"""Initialize anything that is necessary for the driver to function,
|
||||
including catching up with currently running VM's on the given host."""
|
||||
|
@ -30,6 +30,7 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt import driver
|
||||
from nova.virt import virtapi
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -52,7 +53,8 @@ class FakeDriver(driver.ComputeDriver):
|
||||
|
||||
"""Fake hypervisor driver"""
|
||||
|
||||
def __init__(self, read_only=False):
|
||||
def __init__(self, virtapi, read_only=False):
|
||||
super(FakeDriver, self).__init__(virtapi)
|
||||
self.instances = {}
|
||||
self.host_status = {
|
||||
'host_name-description': 'Fake Host',
|
||||
@ -329,3 +331,10 @@ class FakeDriver(driver.ComputeDriver):
|
||||
|
||||
def get_volume_connector(self, instance):
|
||||
return {'ip': '127.0.0.1', 'initiator': 'fake', 'host': 'fakehost'}
|
||||
|
||||
|
||||
class FakeVirtAPI(virtapi.VirtAPI):
|
||||
def instance_update(self, context, instance_uuid, updates):
|
||||
return db.instance_update_and_get_original(context,
|
||||
instance_uuid,
|
||||
updates)
|
||||
|
@ -73,8 +73,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HyperVDriver(driver.ComputeDriver):
|
||||
def __init__(self):
|
||||
super(HyperVDriver, self).__init__()
|
||||
def __init__(self, virtapi):
|
||||
super(HyperVDriver, self).__init__(virtapi)
|
||||
|
||||
self._hostops = hostops.HostOps()
|
||||
self._volumeops = volumeops.VolumeOps()
|
||||
|
@ -61,7 +61,6 @@ from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import vm_mode
|
||||
from nova import context as nova_context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.image import glance
|
||||
@ -257,8 +256,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
"has_imagecache": True,
|
||||
}
|
||||
|
||||
def __init__(self, read_only=False):
|
||||
super(LibvirtDriver, self).__init__()
|
||||
def __init__(self, virtapi, read_only=False):
|
||||
super(LibvirtDriver, self).__init__(virtapi)
|
||||
|
||||
global libvirt
|
||||
if libvirt is None:
|
||||
@ -311,7 +310,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
@property
|
||||
def host_state(self):
|
||||
if not self._host_state:
|
||||
self._host_state = HostState(self.read_only)
|
||||
self._host_state = HostState(self.virtapi, self.read_only)
|
||||
return self._host_state
|
||||
|
||||
def has_min_version(self, ver):
|
||||
@ -1621,7 +1620,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
if ephemeral_device is not None:
|
||||
swap_device = self.default_third_device
|
||||
db.instance_update(
|
||||
self.virtapi.instance_update(
|
||||
nova_context.get_admin_context(), instance['uuid'],
|
||||
{'default_ephemeral_device':
|
||||
'/dev/' + self.default_second_device})
|
||||
@ -1646,7 +1645,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
block_device_info)):
|
||||
diskswap = disk_info('disk.swap', swap_device)
|
||||
devices.append(diskswap)
|
||||
db.instance_update(
|
||||
self.virtapi.instance_update(
|
||||
nova_context.get_admin_context(), instance['uuid'],
|
||||
{'default_swap_device': '/dev/' + swap_device})
|
||||
|
||||
@ -1700,7 +1699,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
# NOTE(yamahata):
|
||||
# for nova.api.ec2.cloud.CloudController.get_metadata()
|
||||
root_device = self.default_root_device
|
||||
db.instance_update(
|
||||
self.virtapi.instance_update(
|
||||
nova_context.get_admin_context(), instance['uuid'],
|
||||
{'root_device_name': '/dev/' + self.default_root_device})
|
||||
|
||||
@ -3008,11 +3007,12 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
class HostState(object):
|
||||
"""Manages information about the compute node through libvirt"""
|
||||
def __init__(self, read_only):
|
||||
def __init__(self, virtapi, read_only):
|
||||
super(HostState, self).__init__()
|
||||
self.read_only = read_only
|
||||
self._stats = {}
|
||||
self.connection = None
|
||||
self.virtapi = virtapi
|
||||
self.update_status()
|
||||
|
||||
def get_host_stats(self, refresh=False):
|
||||
@ -3027,7 +3027,7 @@ class HostState(object):
|
||||
"""Retrieve status info from libvirt."""
|
||||
LOG.debug(_("Updating host stats"))
|
||||
if self.connection is None:
|
||||
self.connection = LibvirtDriver(self.read_only)
|
||||
self.connection = LibvirtDriver(self.virtapi, self.read_only)
|
||||
data = {}
|
||||
data["vcpus"] = self.connection.get_vcpu_total()
|
||||
data["vcpus_used"] = self.connection.get_vcpu_used()
|
||||
|
@ -18,7 +18,6 @@ from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
|
||||
from nova import context as nova_context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
|
||||
from nova.openstack.common import cfg
|
||||
@ -59,8 +58,8 @@ class PowerVMDriver(driver.ComputeDriver):
|
||||
|
||||
"""PowerVM Implementation of Compute Driver."""
|
||||
|
||||
def __init__(self):
|
||||
super(PowerVMDriver, self).__init__()
|
||||
def __init__(self, virtapi):
|
||||
super(PowerVMDriver, self).__init__(virtapi)
|
||||
self._powervm = operator.PowerVMOperator()
|
||||
|
||||
@property
|
||||
|
30
nova/virt/virtapi.py
Normal file
30
nova/virt/virtapi.py
Normal file
@ -0,0 +1,30 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
from nova import db
|
||||
|
||||
|
||||
class VirtAPI(object):
|
||||
def instance_update(self, context, instance_uuid, updates):
|
||||
"""Perform an instance update operation on behalf of a virt driver
|
||||
:param context: security context
|
||||
:param instance_uuid: uuid of the instance to be updated
|
||||
:param updates: dict of attribute=value pairs to change
|
||||
|
||||
Returns: orig_instance, new_instance
|
||||
"""
|
||||
raise NotImplementedError()
|
@ -100,8 +100,8 @@ class Failure(Exception):
|
||||
class VMWareESXDriver(driver.ComputeDriver):
|
||||
"""The ESX host connection object."""
|
||||
|
||||
def __init__(self, read_only=False, scheme="https"):
|
||||
super(VMWareESXDriver, self).__init__()
|
||||
def __init__(self, virtapi, read_only=False, scheme="https"):
|
||||
super(VMWareESXDriver, self).__init__(virtapi)
|
||||
|
||||
host_ip = FLAGS.vmwareapi_host_ip
|
||||
host_username = FLAGS.vmwareapi_host_username
|
||||
|
@ -125,8 +125,8 @@ FLAGS.register_opts(xenapi_opts)
|
||||
class XenAPIDriver(driver.ComputeDriver):
|
||||
"""A connection to XenServer or Xen Cloud Platform"""
|
||||
|
||||
def __init__(self, read_only=False):
|
||||
super(XenAPIDriver, self).__init__()
|
||||
def __init__(self, virtapi, read_only=False):
|
||||
super(XenAPIDriver, self).__init__(virtapi)
|
||||
|
||||
url = FLAGS.xenapi_connection_url
|
||||
username = FLAGS.xenapi_connection_username
|
||||
@ -141,7 +141,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
self._volumeops = volumeops.VolumeOps(self._session)
|
||||
self._host_state = None
|
||||
self._host = host.Host(self._session)
|
||||
self._vmops = vmops.VMOps(self._session)
|
||||
self._vmops = vmops.VMOps(self._session, self.virtapi)
|
||||
self._initiator = None
|
||||
self._hypervisor_hostname = None
|
||||
self._pool = pool.ResourcePool(self._session)
|
||||
|
@ -93,7 +93,7 @@ def cmp_version(a, b):
|
||||
return len(a) - len(b)
|
||||
|
||||
|
||||
def make_step_decorator(context, instance):
|
||||
def make_step_decorator(context, instance, instance_update):
|
||||
"""Factory to create a decorator that records instance progress as a series
|
||||
of discrete steps.
|
||||
|
||||
@ -125,7 +125,7 @@ def make_step_decorator(context, instance):
|
||||
step_info['total'] * 100)
|
||||
LOG.debug(_("Updating progress to %(progress)d"), locals(),
|
||||
instance=instance)
|
||||
db.instance_update(context, instance['uuid'], {'progress': progress})
|
||||
instance_update(context, instance['uuid'], {'progress': progress})
|
||||
|
||||
def step_decorator(f):
|
||||
step_info['total'] += 1
|
||||
@ -145,9 +145,10 @@ class VMOps(object):
|
||||
"""
|
||||
Management class for VM-related tasks
|
||||
"""
|
||||
def __init__(self, session):
|
||||
def __init__(self, session, virtapi):
|
||||
self.compute_api = compute.API()
|
||||
self._session = session
|
||||
self._virtapi = virtapi
|
||||
self.poll_rescue_last_ran = None
|
||||
self.firewall_driver = firewall.load_driver(
|
||||
default=DEFAULT_FIREWALL_DRIVER,
|
||||
@ -254,7 +255,8 @@ class VMOps(object):
|
||||
if name_label is None:
|
||||
name_label = instance['name']
|
||||
|
||||
step = make_step_decorator(context, instance)
|
||||
step = make_step_decorator(context, instance,
|
||||
self._virtapi.instance_update)
|
||||
|
||||
@step
|
||||
def determine_disk_image_type_step(undo_mgr):
|
||||
@ -454,7 +456,8 @@ class VMOps(object):
|
||||
|
||||
if instance['vm_mode'] != mode:
|
||||
# Update database with normalized (or determined) value
|
||||
db.instance_update(context, instance['uuid'], {'vm_mode': mode})
|
||||
self._virtapi.instance_update(context,
|
||||
instance['uuid'], {'vm_mode': mode})
|
||||
|
||||
vm_ref = vm_utils.create_vm(self._session, instance, name_label,
|
||||
kernel_file, ramdisk_file, use_pv_kernel)
|
||||
@ -661,7 +664,8 @@ class VMOps(object):
|
||||
progress = round(float(step) / total_steps * 100)
|
||||
LOG.debug(_("Updating progress to %(progress)d"), locals(),
|
||||
instance=instance)
|
||||
db.instance_update(context, instance['uuid'], {'progress': progress})
|
||||
self._virtapi.instance_update(context, instance['uuid'],
|
||||
{'progress': progress})
|
||||
|
||||
def _migrate_disk_resizing_down(self, context, instance, dest,
|
||||
instance_type, vm_ref, sr_path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user