From d7a5169a7f0ffe7208f851b554b7b1ed5145a3be Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 3 Nov 2011 13:40:56 -0400 Subject: [PATCH] Gracefully handle Xen resize failure Fixes bug 885723 Change-Id: I8cd04a88f809f49141dc6aa5be7217811e0141e3 --- nova/tests/test_compute.py | 24 ++++++++++++++++++++++++ nova/tests/test_xenapi.py | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 7295c9f1..b235bcad 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -746,6 +746,30 @@ class ComputeTestCase(test.TestCase): self.context, inst_ref['uuid'], 1) self.compute.terminate_instance(self.context, instance_id) + def test_resize_instance_handles_migration_error(self): + """Ensure vm_state is ERROR when MigrationError occurs""" + def raise_migration_failure(*args): + raise exception.MigrationError(reason='test failure') + self.stubs.Set(self.compute.driver, + 'migrate_disk_and_power_off', + raise_migration_failure) + + instance_id = self._create_instance() + context = self.context.elevated() + inst_ref = db.instance_get(context, instance_id) + + self.compute.run_instance(self.context, instance_id) + db.instance_update(self.context, inst_ref['uuid'], {'host': 'foo'}) + self.compute.prep_resize(context, inst_ref['uuid'], 1) + migration_ref = db.migration_get_by_instance_and_status(context, + inst_ref['uuid'], 'pre-migrating') + self.compute.resize_instance(context, + inst_ref['uuid'], + migration_ref['id']) + inst_ref = db.instance_get(context, instance_id) + self.assertEqual(inst_ref['vm_state'], vm_states.ERROR) + self.compute.terminate_instance(context, instance_id) + def test_migrate(self): context = self.context.elevated() instance_id = self._create_instance() diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 08a7686b..6587bedd 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -791,6 +791,19 @@ class XenAPIMigrateInstance(test.TestCase): conn = xenapi_conn.get_connection(False) conn.migrate_disk_and_power_off(self.context, instance, '127.0.0.1') + def test_migrate_disk_and_power_off_passes_exceptions(self): + instance = db.instance_create(self.context, self.instance_values) + stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) + + def fake_raise(*args, **kwargs): + raise exception.MigrationError(reason='test failure') + self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise) + + conn = xenapi_conn.get_connection(False) + self.assertRaises(exception.MigrationError, + conn.migrate_disk_and_power_off, + self.context, instance, '127.0.0.1') + def test_revert_migrate(self): instance = db.instance_create(self.context, self.instance_values) self.called = False