From ec73ff1f78714eb62686d0f39fc4e79ffdf559af Mon Sep 17 00:00:00 2001 From: Pierre-Samuel Le Stang Date: Mon, 6 Sep 2021 08:44:37 +0000 Subject: [PATCH] Reproducer unit test for bug 1934094 Related bug: #1934094 Signed-off-by: Pierre-Samuel Le Stang Change-Id: I8f7f26e10519c87e06de47bd4d9845151f889129 (cherry picked from commit 78e10f5f14a018fd1d96ea242923631459acb62c) --- nova/tests/unit/compute/test_shelve.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index 3f3f470fa532..725f21bf35b0 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -677,6 +677,30 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): self.context, self.compute.reportclient, [], {uuids.port_1: [uuids.rp1]}) + def test_unshelve_spawn_fails_cleanup_instance_image_ref(self): + """Tests error handling when a instance fails to unshelve and makes + sure to revert instance.image_ref to the initial value instead of + keeping the one of shelved image + https://bugs.launchpad.net/nova/+bug/1934094 + """ + instance = self._create_fake_instance_obj() + # TODO(pslestang) to uncomment when bug 1934094 is fixed + # initial_image_ref = instance.image_ref + + fake_spec = objects.RequestSpec() + shelved_image = {'id': uuids.image_id} + + with mock.patch.object(self.compute.driver, 'spawn', + side_effect=test.TestingException('Spawn Failed')): + self.assertRaises(test.TestingException, + self.compute.unshelve_instance, self.context, instance, + image=shelved_image, filter_properties={}, + node='fake-node', request_spec=fake_spec, accel_uuids=[]) + # FIXME(pslestang) Until bug 1934094 is fixed + # The instance.image_ref is set to shelved_image.id but should be + # equal to initial_image_ref + self.assertEqual(instance.image_ref, shelved_image['id']) + @mock.patch.object(objects.InstanceList, 'get_by_filters') def test_shelved_poll_none_offloaded(self, mock_get_by_filters): # Test instances are not offloaded when shelved_offload_time is -1