From 6b39b2c95ea7220636341665514a5b25c9455333 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Fri, 13 Apr 2012 21:08:01 +0000 Subject: [PATCH] Test unrescue works as well The only unrescue test that happens right now is that it fails if not already in rescue. This test fills out to test unrescue works as intended. Also, remove unnecessary stub from rescue test. Change-Id: I4451afe5a7d2ada8dfaefad804345b66ac895094 --- nova/tests/test_xenapi.py | 18 ++++++++++++------ nova/tests/xenapi/stubs.py | 10 +--------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index da809123..9921c621 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -703,15 +703,20 @@ class XenAPIVMTestCase(test.TestCase): session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass') vm = vm_utils.VMHelper.lookup(session, instance.name) vbd = xenapi_fake.create_vbd(vm, None) - - def fake_spawn(self, context, inst, network_info, image_meta): - inst._rescue = False - self.stubs.Set(vmops.VMOps, 'spawn', fake_spawn) - conn = xenapi_conn.get_connection(False) - conn.rescue(self.context, instance, [], None) + image_meta = {'id': glance_stubs.FakeGlance.IMAGE_VHD, + 'disk_format': 'vhd'} + conn.rescue(self.context, instance, [], image_meta) def test_unrescue(self): + instance = self._create_instance() + conn = xenapi_conn.get_connection(False) + # Unrescue expects the original instance to be powered off + conn.power_off(instance) + rescue_vm = xenapi_fake.create_vm(instance.name + '-rescue', 'Running') + conn.unrescue(instance, None) + + def test_unrescue_not_in_rescue(self): instance = self._create_instance() conn = xenapi_conn.get_connection(False) # Ensure that it will not unrescue a non-rescued instance. @@ -974,6 +979,7 @@ class XenAPIMigrateInstance(test.TestCase): 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) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index e97568f0..533c1289 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -215,7 +215,7 @@ class FakeSessionForVMTests(fake.SessionBase): vm = fake.get_record('VM', ref) if vm['power_state'] != 'Halted': raise fake.Failure(['VM_BAD_POWER_STATE', ref, 'Halted', - vm['power_state']]) + vm['power_state']]) vm['power_state'] = 'Running' vm['is_a_template'] = False vm['is_control_domain'] = False @@ -302,9 +302,6 @@ class FakeSessionForFirewallTests(FakeSessionForVMTests): def stub_out_vm_methods(stubs): - def fake_shutdown(self, inst, vm, method="clean"): - pass - def fake_acquire_bootlock(self, vm): pass @@ -315,7 +312,6 @@ def stub_out_vm_methods(stubs): def fake_generate_ephemeral(cls, *args): pass - stubs.Set(vmops.VMOps, "_shutdown", fake_shutdown) stubs.Set(vmops.VMOps, "_acquire_bootlock", fake_acquire_bootlock) stubs.Set(vmops.VMOps, "_release_bootlock", fake_release_bootlock) stubs.Set(vm_utils.VMHelper, 'generate_ephemeral', fake_generate_ephemeral) @@ -382,9 +378,6 @@ def stub_out_migration_methods(stubs): vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref) return vdi_ref, {'uuid': vdi_rec['uuid'], } - def fake_shutdown(self, inst, vm, hard=True): - pass - @classmethod def fake_sr(cls, session, *args): pass @@ -410,5 +403,4 @@ def stub_out_migration_methods(stubs): stubs.Set(vm_utils.VMHelper, 'get_vdi_for_vm_safely', fake_get_vdi) stubs.Set(vm_utils.VMHelper, 'get_sr_path', fake_get_sr_path) stubs.Set(vmops.VMOps, 'reset_network', fake_reset_network) - stubs.Set(vmops.VMOps, '_shutdown', fake_shutdown) stubs.Set(vm_utils.VMHelper, 'generate_ephemeral', fake_generate_ephemeral)