Remove mox in nova/tests/unit/virt/xenapi/stubs.py
Replace mox stubs with stub_out in nova/tests/unit/virt/xenapi/stubs.py. Change-Id: I721fdc8e6cc7d36caf96b6f17150dfbcaa59c209 Implements: blueprint mox-removal
This commit is contained in:
parent
0190590f78
commit
4547dc7dcd
|
@ -33,7 +33,7 @@ class ComputeXenTestCase(stubs.XenAPITestBaseNoDB):
|
|||
connection_password='test_pass',
|
||||
group='xenserver')
|
||||
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.compute = manager.ComputeManager()
|
||||
# execute power syncing synchronously for testing:
|
||||
self.compute._sync_power_pool = eventlet_utils.SyncPool()
|
||||
|
|
|
@ -47,7 +47,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
|
|||
'user', 'project', auth_token='foobar')
|
||||
|
||||
fake.reset()
|
||||
stubs.stubout_session(self.stubs, fake.SessionBase)
|
||||
stubs.stubout_session(self, fake.SessionBase)
|
||||
driver = xenapi_conn.XenAPIDriver(False)
|
||||
self.session = driver._session
|
||||
|
||||
|
|
|
@ -24,133 +24,21 @@ from os_xenapi.client import XenAPI
|
|||
from oslo_serialization import jsonutils
|
||||
|
||||
from nova import test
|
||||
import nova.tests.unit.image.fake
|
||||
from nova.virt.xenapi import fake
|
||||
from nova.virt.xenapi import vm_utils
|
||||
from nova.virt.xenapi import vmops
|
||||
|
||||
|
||||
def stubout_firewall_driver(stubs, conn):
|
||||
|
||||
def fake_none(self, *args):
|
||||
return
|
||||
|
||||
_vmops = conn._vmops
|
||||
stubs.Set(_vmops.firewall_driver, 'prepare_instance_filter', fake_none)
|
||||
stubs.Set(_vmops.firewall_driver, 'instance_filter_exists', fake_none)
|
||||
|
||||
|
||||
def stubout_instance_snapshot(stubs):
|
||||
def fake_fetch_image(context, session, instance, name_label, image, type,
|
||||
image_handler):
|
||||
return {'root': dict(uuid=_make_fake_vdi(), file=None),
|
||||
'kernel': dict(uuid=_make_fake_vdi(), file=None),
|
||||
'ramdisk': dict(uuid=_make_fake_vdi(), file=None)}
|
||||
|
||||
stubs.Set(vm_utils, '_fetch_image', fake_fetch_image)
|
||||
|
||||
def fake_wait_for_vhd_coalesce(*args):
|
||||
# TODO(sirp): Should we actually fake out the data here
|
||||
return "fakeparent", "fakebase"
|
||||
|
||||
stubs.Set(vm_utils, '_wait_for_vhd_coalesce', fake_wait_for_vhd_coalesce)
|
||||
|
||||
|
||||
def stubout_session(stubs, cls, product_version=(5, 6, 2),
|
||||
def stubout_session(test, cls, product_version=(5, 6, 2),
|
||||
product_brand='XenServer', platform_version=(1, 9, 0),
|
||||
**opt_args):
|
||||
"""Stubs out methods from XenAPISession."""
|
||||
stubs.Set(session.XenAPISession, '_create_session',
|
||||
lambda s, url: cls(url, **opt_args))
|
||||
stubs.Set(session.XenAPISession, '_get_product_version_and_brand',
|
||||
lambda s: (product_version, product_brand))
|
||||
stubs.Set(session.XenAPISession, '_get_platform_version',
|
||||
lambda s: platform_version)
|
||||
|
||||
|
||||
def stubout_get_this_vm_uuid(stubs):
|
||||
def f(session):
|
||||
vms = [rec['uuid'] for rec
|
||||
in fake.get_all_records('VM').values()
|
||||
if rec['is_control_domain']]
|
||||
return vms[0]
|
||||
stubs.Set(vm_utils, 'get_this_vm_uuid', f)
|
||||
|
||||
|
||||
def stubout_image_service_download(stubs):
|
||||
def fake_download(*args, **kwargs):
|
||||
pass
|
||||
stubs.Set(nova.tests.unit.image.fake._FakeImageService,
|
||||
'download', fake_download)
|
||||
|
||||
|
||||
def stubout_stream_disk(stubs):
|
||||
def fake_stream_disk(*args, **kwargs):
|
||||
pass
|
||||
stubs.Set(vm_utils, '_stream_disk', fake_stream_disk)
|
||||
|
||||
|
||||
def stubout_determine_is_pv_objectstore(stubs):
|
||||
"""Assumes VMs stu have PV kernels."""
|
||||
|
||||
def f(*args):
|
||||
return False
|
||||
stubs.Set(vm_utils, '_determine_is_pv_objectstore', f)
|
||||
|
||||
|
||||
def stubout_is_snapshot(stubs):
|
||||
"""Always returns true
|
||||
|
||||
xenapi fake driver does not create vmrefs for snapshots.
|
||||
"""
|
||||
|
||||
def f(*args):
|
||||
return True
|
||||
stubs.Set(vm_utils, 'is_snapshot', f)
|
||||
|
||||
|
||||
def stubout_lookup_image(stubs):
|
||||
"""Simulates a failure in lookup image."""
|
||||
def f(_1, _2, _3, _4):
|
||||
raise Exception("Test Exception raised by fake lookup_image")
|
||||
stubs.Set(vm_utils, 'lookup_image', f)
|
||||
|
||||
|
||||
def stubout_fetch_disk_image(stubs, raise_failure=False):
|
||||
"""Simulates a failure in fetch image_glance_disk."""
|
||||
|
||||
def _fake_fetch_disk_image(context, session, instance, name_label, image,
|
||||
image_type):
|
||||
if raise_failure:
|
||||
raise XenAPI.Failure("Test Exception raised by "
|
||||
"fake fetch_image_glance_disk")
|
||||
elif image_type == vm_utils.ImageType.KERNEL:
|
||||
filename = "kernel"
|
||||
elif image_type == vm_utils.ImageType.RAMDISK:
|
||||
filename = "ramdisk"
|
||||
else:
|
||||
filename = "unknown"
|
||||
|
||||
vdi_type = vm_utils.ImageType.to_string(image_type)
|
||||
return {vdi_type: dict(uuid=None, file=filename)}
|
||||
|
||||
stubs.Set(vm_utils, '_fetch_disk_image', _fake_fetch_disk_image)
|
||||
|
||||
|
||||
def stubout_create_vm(stubs):
|
||||
"""Simulates a failure in create_vm."""
|
||||
|
||||
def f(*args):
|
||||
raise XenAPI.Failure("Test Exception raised by fake create_vm")
|
||||
stubs.Set(vm_utils, 'create_vm', f)
|
||||
|
||||
|
||||
def stubout_attach_disks(stubs):
|
||||
"""Simulates a failure in _attach_disks."""
|
||||
|
||||
def f(*args):
|
||||
raise XenAPI.Failure("Test Exception raised by fake _attach_disks")
|
||||
stubs.Set(vmops.VMOps, '_attach_disks', f)
|
||||
test.stub_out('os_xenapi.client.session.XenAPISession._create_session',
|
||||
lambda s, url: cls(url, **opt_args))
|
||||
test.stub_out('os_xenapi.client.session.XenAPISession.'
|
||||
'_get_product_version_and_brand',
|
||||
lambda s: (product_version, product_brand))
|
||||
test.stub_out('os_xenapi.client.session.XenAPISession.'
|
||||
'_get_platform_version',
|
||||
lambda s: platform_version)
|
||||
|
||||
|
||||
def _make_fake_vdi():
|
||||
|
@ -256,25 +144,6 @@ class FakeSessionForFirewallTests(FakeSessionForVMTests):
|
|||
host_call_plugin(_1, _2, plugin, method, args))
|
||||
|
||||
|
||||
def stub_out_vm_methods(stubs):
|
||||
def fake_acquire_bootlock(self, vm):
|
||||
pass
|
||||
|
||||
def fake_release_bootlock(self, vm):
|
||||
pass
|
||||
|
||||
def fake_generate_ephemeral(*args):
|
||||
pass
|
||||
|
||||
def fake_wait_for_device(session, dev, dom0, max_seconds):
|
||||
pass
|
||||
|
||||
stubs.Set(vmops.VMOps, "_acquire_bootlock", fake_acquire_bootlock)
|
||||
stubs.Set(vmops.VMOps, "_release_bootlock", fake_release_bootlock)
|
||||
stubs.Set(vm_utils, 'generate_ephemeral', fake_generate_ephemeral)
|
||||
stubs.Set(vm_utils, '_wait_for_device', fake_wait_for_device)
|
||||
|
||||
|
||||
class ReplaceModule(fixtures.Fixture):
|
||||
"""Replace a module with a fake module."""
|
||||
|
||||
|
@ -321,50 +190,6 @@ class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests):
|
|||
pass
|
||||
|
||||
|
||||
def stub_out_migration_methods(stubs):
|
||||
fakesr = fake.create_sr()
|
||||
|
||||
def fake_import_all_migrated_disks(session, instance, import_root=True):
|
||||
vdi_ref = fake.create_vdi(instance['name'], fakesr)
|
||||
vdi_rec = fake.get_record('VDI', vdi_ref)
|
||||
vdi_rec['other_config']['nova_disk_type'] = 'root'
|
||||
return {"root": {'uuid': vdi_rec['uuid'], 'ref': vdi_ref},
|
||||
"ephemerals": {}}
|
||||
|
||||
def fake_wait_for_instance_to_start(self, *args):
|
||||
pass
|
||||
|
||||
def fake_get_vdi(session, vm_ref, userdevice='0'):
|
||||
vdi_ref_parent = fake.create_vdi('derp-parent', fakesr)
|
||||
vdi_rec_parent = fake.get_record('VDI', vdi_ref_parent)
|
||||
vdi_ref = fake.create_vdi('derp', fakesr,
|
||||
sm_config={'vhd-parent': vdi_rec_parent['uuid']})
|
||||
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
|
||||
return vdi_ref, vdi_rec
|
||||
|
||||
def fake_sr(session, *args):
|
||||
return fakesr
|
||||
|
||||
def fake_get_sr_path(*args):
|
||||
return "fake"
|
||||
|
||||
def fake_destroy(*args, **kwargs):
|
||||
pass
|
||||
|
||||
def fake_generate_ephemeral(*args):
|
||||
pass
|
||||
|
||||
stubs.Set(vmops.VMOps, '_destroy', fake_destroy)
|
||||
stubs.Set(vmops.VMOps, '_wait_for_instance_to_start',
|
||||
fake_wait_for_instance_to_start)
|
||||
stubs.Set(vm_utils, 'import_all_migrated_disks',
|
||||
fake_import_all_migrated_disks)
|
||||
stubs.Set(vm_utils, 'scan_default_sr', fake_sr)
|
||||
stubs.Set(vm_utils, 'get_vdi_for_vm_safely', fake_get_vdi)
|
||||
stubs.Set(vm_utils, 'get_sr_path', fake_get_sr_path)
|
||||
stubs.Set(vm_utils, 'generate_ephemeral', fake_generate_ephemeral)
|
||||
|
||||
|
||||
class FakeSessionForFailedMigrateTests(FakeSessionForVMTests):
|
||||
def VM_assert_can_migrate(self, session, vmref, migrate_data,
|
||||
live, vdi_map, vif_map, options):
|
||||
|
@ -378,20 +203,6 @@ class FakeSessionForFailedMigrateTests(FakeSessionForVMTests):
|
|||
raise XenAPI.Failure("XenAPI VM.migrate_send failed")
|
||||
|
||||
|
||||
def get_fake_session(error=None):
|
||||
fake_session = mock.MagicMock()
|
||||
session.apply_session_helpers(fake_session)
|
||||
|
||||
if error is not None:
|
||||
class FakeException(Exception):
|
||||
details = [error, "a", "b", "c"]
|
||||
|
||||
fake_session.XenAPI.Failure = FakeException
|
||||
fake_session.call_xenapi.side_effect = FakeException
|
||||
|
||||
return fake_session
|
||||
|
||||
|
||||
# FIXME(sirp): XenAPITestBase is deprecated, all tests should be converted
|
||||
# over to use XenAPITestBaseNoDB
|
||||
class XenAPITestBase(test.TestCase):
|
||||
|
@ -404,6 +215,14 @@ class XenAPITestBase(test.TestCase):
|
|||
self.useFixture(ReplaceModule('XenAPI', fake))
|
||||
fake.reset()
|
||||
|
||||
def stubout_get_this_vm_uuid(self):
|
||||
def f(session):
|
||||
vms = [rec['uuid'] for rec
|
||||
in fake.get_all_records('VM').values()
|
||||
if rec['is_control_domain']]
|
||||
return vms[0]
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.get_this_vm_uuid', f)
|
||||
|
||||
|
||||
class XenAPITestBaseNoDB(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
|
@ -414,3 +233,17 @@ class XenAPITestBaseNoDB(test.NoDBTestCase):
|
|||
group='xenserver')
|
||||
self.useFixture(ReplaceModule('XenAPI', fake))
|
||||
fake.reset()
|
||||
|
||||
@staticmethod
|
||||
def get_fake_session(error=None):
|
||||
fake_session = mock.MagicMock()
|
||||
session.apply_session_helpers(fake_session)
|
||||
|
||||
if error is not None:
|
||||
class FakeException(Exception):
|
||||
details = [error, "a", "b", "c"]
|
||||
|
||||
fake_session.XenAPI.Failure = FakeException
|
||||
fake_session.call_xenapi.side_effect = FakeException
|
||||
|
||||
return fake_session
|
||||
|
|
|
@ -34,7 +34,7 @@ class XenAPIDriverTestCase(stubs.XenAPITestBaseNoDB):
|
|||
"""Unit tests for Driver operations."""
|
||||
|
||||
def _get_driver(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.flags(connection_url='http://localhost',
|
||||
connection_password='test_pass', group='xenserver')
|
||||
return xenapi.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
|
|
@ -487,7 +487,7 @@ class GetInstanceForVdisForSrTestCase(VMUtilsTestBase):
|
|||
for vdi_ref in [vdi_1, vdi_2]:
|
||||
fake.create_vbd(vm_ref, vdi_ref)
|
||||
|
||||
stubs.stubout_session(self.stubs, fake.SessionBase)
|
||||
stubs.stubout_session(self, fake.SessionBase)
|
||||
driver = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
result = list(vm_utils.get_instance_vdis_for_sr(
|
||||
|
@ -499,7 +499,7 @@ class GetInstanceForVdisForSrTestCase(VMUtilsTestBase):
|
|||
vm_ref = fake.create_vm("foo", "Running")
|
||||
sr_ref = fake.create_sr()
|
||||
|
||||
stubs.stubout_session(self.stubs, fake.SessionBase)
|
||||
stubs.stubout_session(self, fake.SessionBase)
|
||||
driver = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
result = list(vm_utils.get_instance_vdis_for_sr(
|
||||
|
@ -545,7 +545,7 @@ class VMRefOrRaiseVMNotFoundTestCase(VMUtilsTestBase):
|
|||
class CreateCachedImageTestCase(VMUtilsTestBase):
|
||||
def setUp(self):
|
||||
super(CreateCachedImageTestCase, self).setUp()
|
||||
self.session = stubs.get_fake_session()
|
||||
self.session = self.get_fake_session()
|
||||
|
||||
@mock.patch.object(vm_utils, '_clone_vdi', return_value='new_vdi_ref')
|
||||
def test_cached(self, mock_clone_vdi, mock_safe_find_sr):
|
||||
|
@ -598,7 +598,7 @@ class CreateCachedImageTestCase(VMUtilsTestBase):
|
|||
class DestroyCachedImageTestCase(VMUtilsTestBase):
|
||||
def setUp(self):
|
||||
super(DestroyCachedImageTestCase, self).setUp()
|
||||
self.session = stubs.get_fake_session()
|
||||
self.session = self.get_fake_session()
|
||||
|
||||
@mock.patch.object(vm_utils, '_find_cached_images')
|
||||
@mock.patch.object(vm_utils, 'destroy_vdi')
|
||||
|
@ -791,7 +791,7 @@ class CreateVBDTestCase(VMUtilsTestBase):
|
|||
class UnplugVbdTestCase(VMUtilsTestBase):
|
||||
@mock.patch.object(greenthread, 'sleep')
|
||||
def test_unplug_vbd_works(self, mock_sleep):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
||||
|
@ -801,7 +801,7 @@ class UnplugVbdTestCase(VMUtilsTestBase):
|
|||
self.assertEqual(0, mock_sleep.call_count)
|
||||
|
||||
def test_unplug_vbd_raises_unexpected_error(self):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
session.XenAPI.Failure = fake.Failure
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
@ -813,7 +813,7 @@ class UnplugVbdTestCase(VMUtilsTestBase):
|
|||
|
||||
def test_unplug_vbd_already_detached_works(self):
|
||||
error = "DEVICE_ALREADY_DETACHED"
|
||||
session = stubs.get_fake_session(error)
|
||||
session = self.get_fake_session(error)
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
||||
|
@ -821,7 +821,7 @@ class UnplugVbdTestCase(VMUtilsTestBase):
|
|||
self.assertEqual(1, session.call_xenapi.call_count)
|
||||
|
||||
def test_unplug_vbd_already_raises_unexpected_xenapi_error(self):
|
||||
session = stubs.get_fake_session("")
|
||||
session = self.get_fake_session("")
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
||||
|
@ -830,7 +830,7 @@ class UnplugVbdTestCase(VMUtilsTestBase):
|
|||
self.assertEqual(1, session.call_xenapi.call_count)
|
||||
|
||||
def _test_uplug_vbd_retries(self, mock_sleep, error):
|
||||
session = stubs.get_fake_session(error)
|
||||
session = self.get_fake_session(error)
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
||||
|
@ -841,7 +841,7 @@ class UnplugVbdTestCase(VMUtilsTestBase):
|
|||
self.assertEqual(10, mock_sleep.call_count)
|
||||
|
||||
def _test_uplug_vbd_retries_with_neg_val(self):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
self.flags(num_vbd_unplug_retries=-1, group='xenserver')
|
||||
vbd_ref = "vbd_ref"
|
||||
vm_ref = 'vm_ref'
|
||||
|
@ -971,7 +971,7 @@ class GenerateDiskTestCase(VMUtilsTestBase):
|
|||
mock_create_vdi, mock_findsr,
|
||||
mock_dom0ref, mock_mkfs,
|
||||
mock_attached_here):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
vdi_ref = mock.MagicMock()
|
||||
mock_attached_here.return_value = vdi_ref
|
||||
|
||||
|
@ -998,7 +998,7 @@ class GenerateDiskTestCase(VMUtilsTestBase):
|
|||
mock_create_vdi,
|
||||
mock_findsr, mock_dom0ref, mock_mkfs,
|
||||
mock_attached_here):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
vdi_dev = mock.MagicMock()
|
||||
mock_attached_here.return_value = vdi_dev
|
||||
vdi_dev.__enter__.return_value = 'fakedev'
|
||||
|
@ -1031,7 +1031,7 @@ class GenerateDiskTestCase(VMUtilsTestBase):
|
|||
mock_create_vdi, mock_findsr,
|
||||
mock_dom0ref, mock_mkfs,
|
||||
mock_attached_here):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
vdi_ref = mock.MagicMock()
|
||||
mock_attached_here.return_value = vdi_ref
|
||||
instance = {'uuid': 'fake_uuid'}
|
||||
|
@ -1062,7 +1062,7 @@ class GenerateDiskTestCase(VMUtilsTestBase):
|
|||
mock_dom0ref,
|
||||
mock_create_vdi,
|
||||
mock_findsr):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
instance = {'uuid': 'fake_uuid'}
|
||||
|
||||
self.assertRaises(test.TestingException, vm_utils._generate_disk,
|
||||
|
@ -1081,7 +1081,7 @@ class GenerateDiskTestCase(VMUtilsTestBase):
|
|||
mock_attached_here,
|
||||
mock_create_vdi,
|
||||
mock_findsr):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
vdi_ref = mock.MagicMock()
|
||||
mock_attached_here.return_value = vdi_ref
|
||||
instance = {'uuid': 'fake_uuid'}
|
||||
|
@ -1243,7 +1243,7 @@ class VMUtilsSRPath(VMUtilsTestBase):
|
|||
self.flags(connection_url='http://localhost',
|
||||
connection_password='test_pass',
|
||||
group='xenserver')
|
||||
stubs.stubout_session(self.stubs, fake.SessionBase)
|
||||
stubs.stubout_session(self, fake.SessionBase)
|
||||
driver = xenapi_conn.XenAPIDriver(False)
|
||||
self.session = driver._session
|
||||
self.session.is_local_connection = False
|
||||
|
@ -1447,7 +1447,7 @@ class ScanSrTestCase(VMUtilsTestBase):
|
|||
class CreateVmTestCase(VMUtilsTestBase):
|
||||
def test_vss_provider(self, mock_extract):
|
||||
self.flags(vcpu_pin_set="2,3")
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
instance = objects.Instance(uuid=uuids.nova_uuid,
|
||||
os_type="windows",
|
||||
system_metadata={})
|
||||
|
@ -2113,7 +2113,7 @@ class CreateVmRecordTestCase(VMUtilsTestBase):
|
|||
|
||||
def _test_create_vm_record(self, mock_extract_flavor, instance,
|
||||
is_viridian):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
flavor = {"memory_mb": 1024, "vcpus": 1, "vcpu_weight": 2}
|
||||
mock_extract_flavor.return_value = flavor
|
||||
|
||||
|
@ -2179,7 +2179,7 @@ class CreateVmRecordTestCase(VMUtilsTestBase):
|
|||
fake.create_vm("foo1", "Halted")
|
||||
vm_ref = fake.create_vm("foo2", "Running")
|
||||
|
||||
stubs.stubout_session(self.stubs, fake.SessionBase)
|
||||
stubs.stubout_session(self, fake.SessionBase)
|
||||
driver = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
result = list(vm_utils.list_vms(driver._session))
|
||||
|
|
|
@ -60,7 +60,7 @@ class VMOpsTestBase(stubs.XenAPITestBaseNoDB):
|
|||
self.vms = []
|
||||
|
||||
def _setup_mock_vmops(self, product_brand=None, product_version=None):
|
||||
stubs.stubout_session(self.stubs, xenapi_fake.SessionBase)
|
||||
stubs.stubout_session(self, xenapi_fake.SessionBase)
|
||||
self._session = xenapi_fake.SessionBase(
|
||||
'http://localhost', 'root', 'test_pass')
|
||||
self.vmops = vmops.VMOps(self._session, fake.FakeVirtAPI())
|
||||
|
|
|
@ -347,7 +347,7 @@ class TestStreamToVDI(stubs.XenAPITestBaseNoDB):
|
|||
@mock.patch.object(volume_utils, '_get_vdi_import_path',
|
||||
return_value='vdi_import_path')
|
||||
def test_creates_task_conn(self, mock_import_path, mock_stream):
|
||||
session = stubs.get_fake_session()
|
||||
session = self.get_fake_session()
|
||||
session.custom_task = mock.MagicMock()
|
||||
session.custom_task.return_value.__enter__.return_value = 'task'
|
||||
session.http_connection = mock.MagicMock()
|
||||
|
|
|
@ -253,7 +253,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
def test_attach_volume(self):
|
||||
# This shows how to test Ops classes' methods.
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVolumeTests)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
vm = xenapi_fake.create_vm(self.instance['name'], 'Running')
|
||||
conn_info = self._make_connection_info()
|
||||
|
@ -269,8 +269,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
def test_attach_volume_raise_exception(self):
|
||||
# This shows how to test when exceptions are raised.
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForVolumeFailedTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVolumeFailedTests)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
xenapi_fake.create_vm(self.instance['name'], 'Running')
|
||||
self.assertRaises(exception.VolumeDriverNotFound,
|
||||
|
@ -298,9 +297,9 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
group='xenserver')
|
||||
db_fakes.stub_out_db_instance_api(self)
|
||||
xenapi_fake.create_network('fake', 'fake_br1')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_get_this_vm_uuid(self.stubs)
|
||||
stubs.stub_out_vm_methods(self.stubs)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.stubout_get_this_vm_uuid()
|
||||
self.stub_out_vm_methods()
|
||||
fake_processutils.stub_out_processutils_execute(self)
|
||||
self.user_id = 'fake'
|
||||
self.project_id = fakes.FAKE_PROJECT_ID
|
||||
|
@ -310,8 +309,8 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
|
||||
fake_image.stub_out_image_service(self)
|
||||
set_image_fixtures()
|
||||
stubs.stubout_image_service_download(self.stubs)
|
||||
stubs.stubout_stream_disk(self.stubs)
|
||||
self.stubout_image_service_download()
|
||||
self.stubout_stream_disk()
|
||||
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps._inject_instance_metadata',
|
||||
lambda self, instance, vm: None)
|
||||
|
@ -335,6 +334,86 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
fake_image.FakeImageService_reset()
|
||||
super(XenAPIVMTestCase, self).tearDown()
|
||||
|
||||
def stubout_firewall_driver(self):
|
||||
self.stub_out('nova.virt.firewall.IptablesFirewallDriver.'
|
||||
'prepare_instance_filter', lambda *args: None)
|
||||
self.stub_out('nova.virt.firewall.IptablesFirewallDriver.'
|
||||
'instance_filter_exists', lambda *args: None)
|
||||
|
||||
def stubout_instance_snapshot(self):
|
||||
self.stub_out('nova.virt.xenapi.vm_utils._fetch_image',
|
||||
lambda context, session, instance, name_label,
|
||||
image, type, image_handler: {
|
||||
'root': dict(uuid=stubs._make_fake_vdi(),
|
||||
file=None),
|
||||
'kernel': dict(uuid=stubs._make_fake_vdi(),
|
||||
file=None),
|
||||
'ramdisk': dict(uuid=stubs._make_fake_vdi(),
|
||||
file=None)})
|
||||
self.stub_out('nova.virt.xenapi.vm_utils._wait_for_vhd_coalesce',
|
||||
lambda *args: ("fakeparent", "fakebase"))
|
||||
|
||||
def stubout_image_service_download(self):
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.download',
|
||||
lambda *args, **kwargs: None)
|
||||
|
||||
def stubout_stream_disk(self):
|
||||
self.stub_out('nova.virt.xenapi.vm_utils._stream_disk',
|
||||
lambda *args, **kwargs: None)
|
||||
|
||||
def stubout_is_snapshot(self):
|
||||
"""Always returns true
|
||||
|
||||
xenapi fake driver does not create vmrefs for snapshots.
|
||||
"""
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.is_snapshot',
|
||||
lambda *args: True)
|
||||
|
||||
def stubout_fetch_disk_image(self, raise_failure=False):
|
||||
"""Simulates a failure in fetch image_glance_disk."""
|
||||
|
||||
def _fake_fetch_disk_image(context, session, instance, name_label,
|
||||
image, image_type):
|
||||
if raise_failure:
|
||||
raise XenAPI.Failure("Test Exception raised by "
|
||||
"fake fetch_image_glance_disk")
|
||||
elif image_type == vm_utils.ImageType.KERNEL:
|
||||
filename = "kernel"
|
||||
elif image_type == vm_utils.ImageType.RAMDISK:
|
||||
filename = "ramdisk"
|
||||
else:
|
||||
filename = "unknown"
|
||||
|
||||
vdi_type = vm_utils.ImageType.to_string(image_type)
|
||||
return {vdi_type: dict(uuid=None, file=filename)}
|
||||
|
||||
self.stub_out('nova.virt.xenapi.vm_utils._fetch_disk_image',
|
||||
_fake_fetch_disk_image)
|
||||
|
||||
def stubout_create_vm(self):
|
||||
"""Simulates a failure in create_vm."""
|
||||
|
||||
def f(*args):
|
||||
raise XenAPI.Failure("Test Exception raised by fake create_vm")
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.create_vm', f)
|
||||
|
||||
def stubout_attach_disks(self):
|
||||
"""Simulates a failure in _attach_disks."""
|
||||
|
||||
def f(*args):
|
||||
raise XenAPI.Failure("Test Exception raised by fake _attach_disks")
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps._attach_disks', f)
|
||||
|
||||
def stub_out_vm_methods(self):
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps._acquire_bootlock',
|
||||
lambda self, vm: None)
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps._release_bootlock',
|
||||
lambda self, vm: None)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.generate_ephemeral',
|
||||
lambda *args: None)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils._wait_for_device',
|
||||
lambda session, dev, dom0, max_seconds: None)
|
||||
|
||||
def test_init_host(self):
|
||||
session = get_session()
|
||||
vm = vm_utils._get_this_vm_ref(session)
|
||||
|
@ -530,10 +609,10 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
return vbd_ref
|
||||
|
||||
mock_create_vbd.side_effect = create_bad_vbd
|
||||
stubs.stubout_instance_snapshot(self.stubs)
|
||||
self.stubout_instance_snapshot()
|
||||
# Stubbing out firewall driver as previous stub sets alters
|
||||
# xml rpc result parsing
|
||||
stubs.stubout_firewall_driver(self.stubs, self.conn)
|
||||
self.stubout_firewall_driver()
|
||||
instance = self._create_instance()
|
||||
|
||||
image_id = "my_snapshot_id"
|
||||
|
@ -554,11 +633,11 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
func_call_matcher = matchers.FunctionCallMatcher(expected_calls)
|
||||
image_id = "my_snapshot_id"
|
||||
|
||||
stubs.stubout_instance_snapshot(self.stubs)
|
||||
stubs.stubout_is_snapshot(self.stubs)
|
||||
self.stubout_instance_snapshot()
|
||||
self.stubout_is_snapshot()
|
||||
# Stubbing out firewall driver as previous stub sets alters
|
||||
# xml rpc result parsing
|
||||
stubs.stubout_firewall_driver(self.stubs, self.conn)
|
||||
self.stubout_firewall_driver()
|
||||
|
||||
instance = self._create_instance()
|
||||
|
||||
|
@ -846,7 +925,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
"""
|
||||
vdi_recs_start = self._list_vdis()
|
||||
start_vms = self._list_vms()
|
||||
stubs.stubout_fetch_disk_image(self.stubs, raise_failure=True)
|
||||
self.stubout_fetch_disk_image(raise_failure=True)
|
||||
self.assertRaises(XenAPI.Failure, self._test_spawn,
|
||||
IMAGE_MACHINE, IMAGE_KERNEL, IMAGE_RAMDISK)
|
||||
# No additional VDI should be found.
|
||||
|
@ -863,7 +942,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
"""
|
||||
vdi_recs_start = self._list_vdis()
|
||||
start_vms = self._list_vms()
|
||||
stubs.stubout_create_vm(self.stubs)
|
||||
self.stubout_create_vm()
|
||||
self.assertRaises(XenAPI.Failure, self._test_spawn,
|
||||
IMAGE_MACHINE, IMAGE_KERNEL, IMAGE_RAMDISK)
|
||||
# No additional VDI should be found.
|
||||
|
@ -878,7 +957,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase,
|
|||
|
||||
Verifies that the VM and VDIs created are properly cleaned up.
|
||||
"""
|
||||
stubs.stubout_attach_disks(self.stubs)
|
||||
self.stubout_attach_disks()
|
||||
vdi_recs_start = self._list_vdis()
|
||||
start_vms = self._list_vms()
|
||||
self.assertRaises(XenAPI.Failure, self._test_spawn,
|
||||
|
@ -1593,7 +1672,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
|||
group='xenserver')
|
||||
self.flags(firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
db_fakes.stub_out_db_instance_api(self)
|
||||
xenapi_fake.create_network('fake', 'fake_br1')
|
||||
self.user_id = 'fake'
|
||||
|
@ -1624,8 +1703,8 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
|||
context.get_admin_context(), migration_values)
|
||||
|
||||
fake_processutils.stub_out_processutils_execute(self)
|
||||
stubs.stub_out_migration_methods(self.stubs)
|
||||
stubs.stubout_get_this_vm_uuid(self.stubs)
|
||||
self.stub_out_migration_methods()
|
||||
self.stubout_get_this_vm_uuid()
|
||||
|
||||
def fake_inject_instance_metadata(self, instance, vm):
|
||||
pass
|
||||
|
@ -1637,6 +1716,41 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
|||
self.stub_out('nova.virt.xenapi.vmops.VMOps._unpause_and_wait',
|
||||
fake_unpause_and_wait)
|
||||
|
||||
def stub_out_migration_methods(self):
|
||||
fakesr = xenapi_fake.create_sr()
|
||||
|
||||
def fake_import_all_migrated_disks(session, instance,
|
||||
import_root=True):
|
||||
vdi_ref = xenapi_fake.create_vdi(instance['name'], fakesr)
|
||||
vdi_rec = xenapi_fake.get_record('VDI', vdi_ref)
|
||||
vdi_rec['other_config']['nova_disk_type'] = 'root'
|
||||
return {"root": {'uuid': vdi_rec['uuid'], 'ref': vdi_ref},
|
||||
"ephemerals": {}}
|
||||
|
||||
def fake_get_vdi(session, vm_ref, userdevice='0'):
|
||||
vdi_ref_parent = xenapi_fake.create_vdi('derp-parent', fakesr)
|
||||
vdi_rec_parent = xenapi_fake.get_record('VDI', vdi_ref_parent)
|
||||
vdi_ref = fake.create_vdi('derp', fakesr,
|
||||
sm_config={'vhd-parent': vdi_rec_parent['uuid']})
|
||||
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
|
||||
return vdi_ref, vdi_rec
|
||||
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps._destroy',
|
||||
lambda *args, **kwargs: None)
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps.'
|
||||
'_wait_for_instance_to_start',
|
||||
lambda self, *args: None)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.import_all_migrated_disks',
|
||||
fake_import_all_migrated_disks)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.scan_default_sr',
|
||||
lambda session, *args: fakesr)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.get_vdi_for_vm_safely',
|
||||
fake_get_vdi)
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.get_sr_path',
|
||||
lambda *args: 'fake')
|
||||
self.stub_out('nova.virt.xenapi.vm_utils.generate_ephemeral',
|
||||
lambda *args: None)
|
||||
|
||||
def _create_instance(self, **kw):
|
||||
values = self.instance_values.copy()
|
||||
values.update(kw)
|
||||
|
@ -1747,7 +1861,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
|||
self.stub_out('nova.virt.xenapi.vmops.VMOps._start', fake_vm_start)
|
||||
self.stub_out('nova.virt.xenapi.vmops.VMOps.finish_revert_migration',
|
||||
fake_finish_revert_migration)
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests,
|
||||
product_version=(4, 0, 0),
|
||||
product_brand='XenServer')
|
||||
|
||||
|
@ -1791,7 +1905,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
|
|||
self.stub_out('nova.tests.unit.virt.xenapi.stubs'
|
||||
'.FakeSessionForVMTests.VDI_resize_online',
|
||||
fake_vdi_resize)
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests,
|
||||
product_version=(4, 0, 0),
|
||||
product_brand='XenServer')
|
||||
|
||||
|
@ -2079,7 +2193,7 @@ class XenAPIHostTestCase(stubs.XenAPITestBase):
|
|||
self.flags(connection_url='http://localhost',
|
||||
connection_password='test_pass',
|
||||
group='xenserver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.context = context.get_admin_context()
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.instance = fake_instance.fake_db_instance(name='foo')
|
||||
|
@ -2356,7 +2470,7 @@ class XenAPIAutoDiskConfigTestCase(stubs.XenAPITestBase):
|
|||
group='xenserver')
|
||||
self.flags(firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.user_id = 'fake'
|
||||
|
@ -2469,7 +2583,7 @@ class XenAPIGenerateLocal(stubs.XenAPITestBase):
|
|||
group='xenserver')
|
||||
self.flags(firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
db_fakes.stub_out_db_instance_api(self)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
|
@ -2580,7 +2694,7 @@ class XenAPIBWCountersTestCase(stubs.XenAPITestBaseNoDB):
|
|||
group='xenserver')
|
||||
self.flags(firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def _fake_get_vif_device_map(self, vm_rec):
|
||||
|
@ -2714,7 +2828,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
|
|||
'Dom0IptablesFirewallDriver')
|
||||
self.user_id = 'mappin'
|
||||
self.project_id = 'fake'
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForFirewallTests,
|
||||
stubs.stubout_session(self, stubs.FakeSessionForFirewallTests,
|
||||
test_case=self)
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.network = importutils.import_object(CONF.network_manager)
|
||||
|
@ -2921,7 +3035,7 @@ class XenAPISRSelectionTestCase(stubs.XenAPITestBaseNoDB):
|
|||
def test_safe_find_sr_raise_exception(self):
|
||||
# Ensure StorageRepositoryNotFound is raise when wrong filter.
|
||||
self.flags(sr_matching_filter='yadayadayada', group='xenserver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
session = get_session()
|
||||
self.assertRaises(exception.StorageRepositoryNotFound,
|
||||
vm_utils.safe_find_sr, session)
|
||||
|
@ -2930,7 +3044,7 @@ class XenAPISRSelectionTestCase(stubs.XenAPITestBaseNoDB):
|
|||
# Ensure the default local-storage is found.
|
||||
self.flags(sr_matching_filter='other-config:i18n-key=local-storage',
|
||||
group='xenserver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
session = get_session()
|
||||
# This test is only guaranteed if there is one host in the pool
|
||||
self.assertEqual(len(xenapi_fake.get_all('host')), 1)
|
||||
|
@ -2950,7 +3064,7 @@ class XenAPISRSelectionTestCase(stubs.XenAPITestBaseNoDB):
|
|||
# Ensure the SR is found when using a different filter.
|
||||
self.flags(sr_matching_filter='other-config:my_fake_sr=true',
|
||||
group='xenserver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
session = get_session()
|
||||
host_ref = xenapi_fake.get_all('host')[0]
|
||||
local_sr = xenapi_fake.create_sr(name_label='Fake Storage',
|
||||
|
@ -2964,7 +3078,7 @@ class XenAPISRSelectionTestCase(stubs.XenAPITestBaseNoDB):
|
|||
# Ensure the default SR is found regardless of other-config.
|
||||
self.flags(sr_matching_filter='default-sr:true',
|
||||
group='xenserver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
session = get_session()
|
||||
pool_ref = session.call_xenapi('pool.get_all')[0]
|
||||
expected = vm_utils.safe_find_sr(session)
|
||||
|
@ -3001,7 +3115,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
|||
compute_driver='xenapi.XenAPIDriver',
|
||||
default_availability_zone='avail_zone1')
|
||||
host_ref = xenapi_fake.get_all('host')[0]
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.context = context.get_admin_context()
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.compute = manager.ComputeManager()
|
||||
|
@ -3359,13 +3473,13 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
@mock.patch.object(vmops.VMOps, 'live_migrate')
|
||||
def test_live_migration_calls_vmops(self, mock_live_migrate):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.conn.live_migration(None, None, None, None, None)
|
||||
self.assertTrue(mock_live_migrate.called)
|
||||
|
||||
def test_pre_live_migration(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
with mock.patch.object(self.conn._vmops, "pre_live_migration") as pre:
|
||||
|
@ -3394,7 +3508,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
mock_setup_basic_filtering, mock_prepare_instance_filter,
|
||||
mock_apply_instance_filter):
|
||||
# ensure method is present
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
fake_instance = {"name": "fake-name"}
|
||||
|
@ -3419,7 +3533,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
def test_check_can_live_migrate_destination_with_block_migration(
|
||||
self,
|
||||
mock_same_pool):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
fake_instance = objects.Instance(host="fake_host")
|
||||
|
@ -3449,7 +3563,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
self.assertEqual(expected, result.to_legacy_dict())
|
||||
|
||||
def test_check_live_migrate_destination_verifies_ip(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
fake_instance = objects.Instance(host="fake_host")
|
||||
|
@ -3472,8 +3586,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
fake_instance = objects.Instance(host="fake_host")
|
||||
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertRaises(exception.MigrationError,
|
||||
self.conn.check_can_live_migrate_destination,
|
||||
|
@ -3513,7 +3626,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
fake_generate_vif_map)
|
||||
|
||||
def test_check_can_live_migrate_source_with_block_migrate(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3527,7 +3640,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
self.assertEqual(dest_check_data, result)
|
||||
|
||||
def test_check_can_live_migrate_source_with_block_migrate_iscsi(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3546,7 +3659,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
return_value=False)
|
||||
def test_check_can_live_migrate_source_with_block_iscsi_fails(
|
||||
self, mock_is_xsm_sr_check_relaxed):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3560,8 +3673,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
mock_is_xsm_sr_check_relaxed.assert_called_once_with()
|
||||
|
||||
def test_check_can_live_migrate_source_with_block_migrate_fails(self):
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3580,7 +3692,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
mock_host_in_this_pool):
|
||||
# The dest host is in the same pool with the src host, do no block
|
||||
# live migrate
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
mock_host_in_this_pool.side_effect = [True, True]
|
||||
with mock.patch.object(self.conn._vmops, "_get_host_opaque_ref") as \
|
||||
|
@ -3614,7 +3726,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
def test_check_can_live_migrate_fails(self, mock_host_in_this_pool):
|
||||
# Caller asks for no block live migrate while the dest host is not in
|
||||
# the same pool with the src host, raise exception
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
mock_host_in_this_pool.return_value = False
|
||||
with mock.patch.object(self.conn._vmops, "_get_host_opaque_ref") as \
|
||||
|
@ -3647,7 +3759,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
return_value=('kernel', 'ramdisk'))
|
||||
def test_live_migration(self, mock_lookup_kernel_ramdisk,
|
||||
mock_get_vm_opaque_ref, mock_get_host_opaque_ref):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def post_method(context, instance, destination_hostname,
|
||||
|
@ -3671,7 +3783,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
@mock.patch.object(vmops.VMOps, '_get_vm_opaque_ref',
|
||||
return_value='fake_vm')
|
||||
def test_live_migration_on_failure(self, mock_get_vm_opaque_ref):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def recover_method(context, instance, destination_hostname,
|
||||
|
@ -3694,7 +3806,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
mock_get_vm_opaque_ref.assert_called_once_with(fake_instance)
|
||||
|
||||
def test_live_migration_calls_post_migration(self):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3714,7 +3826,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
@mock.patch.object(volume_utils, 'forget_sr')
|
||||
def test_live_migration_block_cleans_srs(self, mock_forget_sr):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3737,8 +3849,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
self.assertTrue(mock_forget_sr.called, "forget_sr was not called")
|
||||
|
||||
def test_live_migration_with_block_migration_fails_migrate_send(self):
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForFailedMigrateTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForFailedMigrateTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self._add_default_live_migrate_stubs(self.conn)
|
||||
|
@ -3767,7 +3878,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
self.assertEqual({'SOMEDATA': 'SOMEVAL'}, migrate_data)
|
||||
self.assertEqual(fake_vdi_map, vdi_map)
|
||||
|
||||
stubs.stubout_session(self.stubs, Session)
|
||||
stubs.stubout_session(self, Session)
|
||||
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
|
@ -3803,7 +3914,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
self.assertEqual({"live": "true"}, options)
|
||||
raise IOError()
|
||||
|
||||
stubs.stubout_session(self.stubs, Session)
|
||||
stubs.stubout_session(self, Session)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
self._add_default_live_migrate_stubs(conn)
|
||||
|
||||
|
@ -3824,7 +3935,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
@mock.patch.object(vm_utils, 'safe_find_sr')
|
||||
def test_generate_vdi_map(self, mock_safe_find_sr,
|
||||
mock_get_instance_vdis_for_sr):
|
||||
stubs.stubout_session(self.stubs, xenapi_fake.SessionBase)
|
||||
stubs.stubout_session(self, xenapi_fake.SessionBase)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
vm_ref = "fake_vm_ref"
|
||||
|
@ -3842,7 +3953,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
|
|||
|
||||
@mock.patch.object(vmops.VMOps, "_delete_networks_and_bridges")
|
||||
def test_rollback_live_migration_at_destination(self, mock_delete_network):
|
||||
stubs.stubout_session(self.stubs, xenapi_fake.SessionBase)
|
||||
stubs.stubout_session(self, xenapi_fake.SessionBase)
|
||||
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
network_info = ["fake_vif1"]
|
||||
with mock.patch.object(conn, "destroy") as mock_destroy:
|
||||
|
@ -3860,7 +3971,7 @@ class XenAPIInjectMetadataTestCase(stubs.XenAPITestBaseNoDB):
|
|||
group='xenserver')
|
||||
self.flags(firewall_driver='nova.virt.xenapi.firewall.'
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
self.xenstore = dict(persist={}, ephem={})
|
||||
|
|
Loading…
Reference in New Issue