summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-04-13 21:08:01 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-04-13 21:28:36 +0000
commit8413e60b8e8d91ec2d1656bb3c16eafa3ee832b5 (patch)
tree444a476d31e9c9a297a8223c9e4b4898174a5292 /nova
parent042a4d0d96b33ab2c86ef4e5e46560fef16d011f (diff)
downloadnova-8413e60b8e8d91ec2d1656bb3c16eafa3ee832b5.tar.gz
nova-8413e60b8e8d91ec2d1656bb3c16eafa3ee832b5.tar.xz
nova-8413e60b8e8d91ec2d1656bb3c16eafa3ee832b5.zip
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
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_xenapi.py18
-rw-r--r--nova/tests/xenapi/stubs.py10
-rw-r--r--nova/virt/xenapi/fake.py40
3 files changed, 35 insertions, 33 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index da8091233..9921c621a 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -703,17 +703,22 @@ 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.
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
instance, None)
@@ -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 e97568f03..533c12896 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)
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py
index 232828e48..130d9fb08 100644
--- a/nova/virt/xenapi/fake.py
+++ b/nova/virt/xenapi/fake.py
@@ -85,7 +85,7 @@ def reset():
'Running',
is_a_template=False,
is_control_domain=True,
- host_ref=host)
+ resident_on=host)
def reset_table(table):
@@ -112,16 +112,15 @@ def create_network(name_label, bridge):
'bridge': bridge})
-def create_vm(name_label, status,
- is_a_template=False, is_control_domain=False, host_ref=None):
+def create_vm(name_label, status, **kwargs):
domid = status == 'Running' and random.randrange(1, 1 << 16) or -1
- return _create_object('VM',
- {'name_label': name_label,
- 'domid': domid,
- 'power-state': status,
- 'is_a_template': is_a_template,
- 'is_control_domain': is_control_domain,
- 'resident_on': host_ref})
+ vm_rec = kwargs.copy()
+ vm_rec.update({'name_label': name_label,
+ 'domid': domid,
+ 'power_state': status})
+ vm_ref = _create_object('VM', vm_rec)
+ after_VM_create(vm_ref, vm_rec)
+ return vm_ref
def destroy_vm(vm_ref):
@@ -176,10 +175,7 @@ def after_VBD_create(vbd_ref, vbd_rec):
vbd_rec['device'] = ''
vm_ref = vbd_rec['VM']
vm_rec = _db_content['VM'][vm_ref]
- if vm_rec.get('VBDs', None):
- vm_rec['VBDs'].append(vbd_ref)
- else:
- vm_rec['VBDs'] = [vbd_ref]
+ vm_rec['VBDs'].append(vbd_ref)
vm_name_label = _db_content['VM'][vm_ref]['name_label']
vbd_rec['vm_name_label'] = vm_name_label
@@ -187,8 +183,11 @@ def after_VBD_create(vbd_ref, vbd_rec):
def after_VM_create(vm_ref, vm_rec):
"""Create read-only fields in the VM record."""
- if 'is_control_domain' not in vm_rec:
- vm_rec['is_control_domain'] = False
+ vm_rec.setdefault('is_control_domain', False)
+ vm_rec.setdefault('memory_static_max', str(8 * 1024 * 1024 * 1024))
+ vm_rec.setdefault('memory_dynamic_max', str(8 * 1024 * 1024 * 1024))
+ vm_rec.setdefault('VCPUs_max', str(4))
+ vm_rec.setdefault('VBDs', [])
def create_pbd(config, host_ref, sr_ref, attached):
@@ -524,8 +523,13 @@ class SessionBase(object):
VDI_resize = VDI_resize_online
- def VM_clean_reboot(self, *args):
- return 'burp'
+ def VM_clean_reboot(self, session, vm_ref):
+ pass
+
+ def VM_hard_shutdown(self, session, vm_ref):
+ db_ref = _db_content['VM'][vm_ref]
+ db_ref['power_state'] = 'Halted'
+ VM_clean_shutdown = VM_hard_shutdown
def pool_eject(self, session, host_ref):
pass