From 1316e08c85456ca69bc55bf9a90a24e341884952 Mon Sep 17 00:00:00 2001 From: zhangbailin Date: Tue, 3 Jul 2018 11:08:04 +0800 Subject: Add unshelve instance error info to fault table When the image of the SHELVED_OFFLOADED instance is deleted, the unshelve instance will report an error, but the fault info not added into instance fault table. Closes-bug: #1779826 Change-Id: I365fcc148b27959acad1d3c4f8bb45c1ed790318 (cherry picked from commit b26df4fa6cd78a9b60de79750d4e9a58980d13ca) (cherry picked from commit d543ddda02311986d5318a14dd21a3393df37c3e) --- nova/conductor/manager.py | 5 ++++- nova/tests/unit/conductor/test_conductor.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 230d0aa430..06c1eead65 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -661,7 +661,7 @@ class ComputeTaskManager(base.Base): context, 'get_image_info', instance.uuid): try: image = safe_image_show(context, image_id) - except exception.ImageNotFound: + except exception.ImageNotFound as error: instance.vm_state = vm_states.ERROR instance.save() @@ -669,6 +669,9 @@ class ComputeTaskManager(base.Base): 'cannot be found.') % image_id LOG.error(reason, instance=instance) + compute_utils.add_instance_fault_from_exc( + context, instance, error, sys.exc_info(), + fault_message=reason) raise exception.UnshelveException( instance_id=instance.uuid, reason=reason) diff --git a/nova/tests/unit/conductor/test_conductor.py b/nova/tests/unit/conductor/test_conductor.py index 8adaa21826..459fccf7f3 100644 --- a/nova/tests/unit/conductor/test_conductor.py +++ b/nova/tests/unit/conductor/test_conductor.py @@ -972,7 +972,9 @@ class _BaseTaskTestCase(object): do_test() - def test_unshelve_offloaded_instance_glance_image_not_found(self): + @mock.patch('nova.compute.utils.add_instance_fault_from_exc') + def test_unshelve_offloaded_instance_glance_image_not_found(self, + add_instance_fault_from_exc): shelved_image_id = "image_not_found" instance = self._create_fake_instance_obj() @@ -992,10 +994,15 @@ class _BaseTaskTestCase(object): system_metadata['shelved_host'] = 'fake-mini' system_metadata['shelved_image_id'] = shelved_image_id + reason = ('Unshelve attempted but the image image_not_found ' + 'cannot be found.') + self.assertRaises( exc.UnshelveException, self.conductor_manager.unshelve_instance, self.context, instance) + add_instance_fault_from_exc.assert_called_once_with( + self.context, instance, e, mock.ANY, fault_message=reason) self.assertEqual(instance.vm_state, vm_states.ERROR) def test_unshelve_offloaded_instance_image_id_is_none(self): -- cgit v1.2.1