diff options
| -rw-r--r-- | nova/tests/test_xenapi.py | 36 | ||||
| -rw-r--r-- | nova/tests/xenapi/stubs.py | 26 | ||||
| -rw-r--r-- | nova/virt/xenapi/fake.py | 4 |
3 files changed, 25 insertions, 41 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index eef60dd94..1da117b02 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -748,8 +748,6 @@ class XenAPIVMTestCase(test.TestCase): def finish_revert_migration(self, instance): self.finish_revert_migration_called = True - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) - conn = xenapi_conn.get_connection(False) conn._vmops = VMOpsMock() conn.finish_revert_migration(instance, None) @@ -846,6 +844,7 @@ class XenAPIMigrateInstance(test.TestCase): xenapi_connection_password='test_pass', firewall_driver='nova.virt.xenapi.firewall.' 'Dom0IptablesFirewallDriver') + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) db_fakes.stub_out_db_instance_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() @@ -885,8 +884,6 @@ class XenAPIMigrateInstance(test.TestCase): """Test all migrations are checked despite errors when autoconfirming resizes. """ - stubs.stubout_session(self.stubs, - stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) self.mox.StubOutWithMock(context, 'get_admin_context') @@ -982,21 +979,21 @@ class XenAPIMigrateInstance(test.TestCase): def fake_vdi_resize(*args, **kwargs): called['resize'] = True - self.stubs.Set(stubs.FakeSessionForMigrationTests, + self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize", fake_vdi_resize) - stubs.stubout_session(self.stubs, - stubs.FakeSessionForMigrationTests, + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests, product_version=(6, 0, 0)) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) - conn._vmops._resize_instance(instance, '') + vdi_ref = xenapi_fake.create_vdi('hurr', 'fake') + vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid'] + conn._vmops._resize_instance(instance, vdi_uuid) self.assertEqual(called['resize'], True) def test_migrate_disk_and_power_off(self): 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') - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn.migrate_disk_and_power_off(self.context, instance, '127.0.0.1', instance_type, None) @@ -1005,7 +1002,6 @@ class XenAPIMigrateInstance(test.TestCase): 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') - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) def fake_raise(*args, **kwargs): raise exception.MigrationError(reason='test failure') @@ -1032,13 +1028,12 @@ class XenAPIMigrateInstance(test.TestCase): def fake_finish_revert_migration(*args, **kwargs): self.fake_finish_revert_migration_called = True - self.stubs.Set(stubs.FakeSessionForMigrationTests, + self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) self.stubs.Set(vmops.VMOps, 'finish_revert_migration', fake_finish_revert_migration) - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, @@ -1056,8 +1051,12 @@ class XenAPIMigrateInstance(test.TestCase): 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'} + base = xenapi_fake.create_vdi('hurr', 'fake') + base_uuid = xenapi_fake.get_record('VDI', base)['uuid'] + cow = xenapi_fake.create_vdi('durr', 'fake') + cow_uuid = xenapi_fake.get_record('VDI', cow)['uuid'] conn.finish_migration(self.context, self.migration, instance, - dict(base_copy='hurr', cow='durr'), + dict(base_copy=base_uuid, cow=cow_uuid), network_info, image_meta, resize_instance=True) self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, True) @@ -1077,10 +1076,9 @@ class XenAPIMigrateInstance(test.TestCase): self.called = True self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) - self.stubs.Set(stubs.FakeSessionForMigrationTests, + self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize_online", fake_vdi_resize) - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, @@ -1114,9 +1112,8 @@ class XenAPIMigrateInstance(test.TestCase): def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") - self.stubs.Set(stubs.FakeSessionForMigrationTests, + self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize_online", fake_vdi_resize) - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, @@ -1144,9 +1141,8 @@ class XenAPIMigrateInstance(test.TestCase): def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") - self.stubs.Set(stubs.FakeSessionForMigrationTests, - "VDI_resize_online", fake_vdi_resize) - stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) + self.stubs.Set(stubs.FakeSessionForVMTests, + "VDI_resize_online", fake_vdi_resize) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 7c58fbec7..10c8661b6 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -246,12 +246,6 @@ class FakeSessionForVMTests(fake.SessionBase): def SR_scan(self, session_ref, sr_ref): pass - def VDI_set_name_label(self, session_ref, vdi_ref, name_label): - pass - - def VDI_set_name_description(self, session_ref, vdi_ref, name_description): - pass - class FakeSessionForFirewallTests(FakeSessionForVMTests): """ Stubs out a XenApi Session for doing IPTable Firewall tests """ @@ -355,25 +349,14 @@ class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests): pass -class FakeSessionForMigrationTests(FakeSessionForVMTests): - """Stubs out a XenAPISession for Migration tests""" - def __init__(self, uri): - super(FakeSessionForMigrationTests, self).__init__(uri) - - def VDI_get_by_uuid(self, *args): - return 'hurr' - - def VM_set_name_label(self, *args): - pass - - def VDI_set_name_label(self, session_ref, vdi_ref, name_label): - pass - - def stub_out_migration_methods(stubs): def fake_create_snapshot(self, instance): return 'vm_ref', dict(image='foo', snap='bar') + def fake_move_disks(self, instance, disk_info): + vdi_ref = fake.create_vdi('new', 'fake') + return fake.get_record('VDI', vdi_ref)['uuid'] + @classmethod def fake_get_vdi(cls, session, vm_ref): vdi_ref = fake.create_vdi('derp', 'herp') @@ -396,6 +379,7 @@ def stub_out_migration_methods(stubs): pass stubs.Set(vmops.VMOps, '_destroy', fake_destroy) + stubs.Set(vmops.VMOps, '_move_disks', fake_move_disks) stubs.Set(vm_utils.VMHelper, 'scan_default_sr', fake_sr) stubs.Set(vm_utils.VMHelper, 'scan_sr', fake_sr) stubs.Set(vmops.VMOps, '_create_snapshot', fake_create_snapshot) diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index 1d07f209c..26f1c0847 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -610,6 +610,9 @@ class SessionBase(object): if self._is_gettersetter(name, True): LOG.debug(_('Calling getter %s'), name) return lambda *params: self._getter(name, params) + elif self._is_gettersetter(name, False): + LOG.debug(_('Calling setter %s'), name) + return lambda *params: self._setter(name, params) elif self._is_create(name): return lambda *params: self._create(name, params) elif self._is_destroy(name): @@ -683,6 +686,7 @@ class SessionBase(object): if (ref in _db_content[cls] and field in _db_content[cls][ref]): _db_content[cls][ref][field] = val + return LOG.debug(_('Raising NotImplemented')) raise NotImplementedError( |
