Make reboot work for halted xenapi instances

Fixes bug 1022199

This also will catch exceptions and make sure to reset the task_state,
while still generating an instance fault.

Change-Id: I122a1422b8e5731bc484414736ab44e60d4c9830
This commit is contained in:
Chris Behrens
2012-07-07 21:38:36 -07:00
parent e2ad48bdf8
commit 14df5dfb99

View File

@@ -807,6 +807,33 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
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.reboot(instance, None, "HARD")
def test_reboot_soft(self):
instance = self._create_instance()
conn = xenapi_conn.XenAPIDriver(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)
xenapi_fake.create_vm(instance.name, 'Halted')
conn.reboot(instance, None, "SOFT")
vm_ref = vm_utils.lookup(session, instance.name)
vm = xenapi_fake.get_record('VM', vm_ref)
self.assertEquals(vm['power_state'], 'Running')
def test_reboot_unknown_state(self):
instance = self._create_instance(spawn=False)
conn = xenapi_conn.XenAPIDriver(False)
xenapi_fake.create_vm(instance.name, 'Unknown')
self.assertRaises(xenapi_fake.Failure, conn.reboot, instance,
None, "SOFT")
def _create_instance(self, instance_id=1, spawn=True):
"""Creates and spawns a test instance."""
instance_values = {
@@ -938,6 +965,14 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
conn.migrate_disk_and_power_off(self.context, instance,
'127.0.0.1', instance_type, None)
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')
conn = xenapi_conn.XenAPIDriver(False)
conn.migrate_disk_and_power_off(self.context, instance,
'127.0.0.1', instance_type, None)
def test_migrate_disk_and_power_off_passes_exceptions(self):
instance = db.instance_create(self.context, self.instance_values)
xenapi_fake.create_vm(instance.name, 'Running')