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
This commit is contained in:
zhangbailin
2018-07-03 11:08:04 +08:00
committed by Matt Riedemann
parent 7d2223e4ec
commit b26df4fa6c
2 changed files with 13 additions and 2 deletions
+5 -1
View File
@@ -17,6 +17,7 @@
import contextlib
import copy
import functools
import sys
from oslo_config import cfg
from oslo_log import log as logging
@@ -739,7 +740,7 @@ class ComputeTaskManager(base.Base):
context, 'get_image_info', self.host, 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()
@@ -747,6 +748,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)
+8 -1
View File
@@ -1047,10 +1047,11 @@ class _BaseTaskTestCase(object):
do_test()
@mock.patch('nova.compute.utils.add_instance_fault_from_exc')
@mock.patch.object(image_api.API, 'get',
side_effect=exc.ImageNotFound(image_id=uuids.image))
def test_unshelve_offloaded_instance_glance_image_not_found(
self, mock_get):
self, mock_get, add_instance_fault_from_exc):
instance = self._create_fake_instance_obj()
instance.vm_state = vm_states.SHELVED_OFFLOADED
instance.task_state = task_states.UNSHELVING
@@ -1061,10 +1062,16 @@ class _BaseTaskTestCase(object):
system_metadata['shelved_host'] = 'fake-mini'
system_metadata['shelved_image_id'] = uuids.image
reason = ('Unshelve attempted but the image %s '
'cannot be found.') % uuids.image
self.assertRaises(
exc.UnshelveException,
self.conductor_manager.unshelve_instance,
self.context, instance)
add_instance_fault_from_exc.assert_called_once_with(
self.context, instance, mock_get.side_effect, mock.ANY,
fault_message=reason)
self.assertEqual(instance.vm_state, vm_states.ERROR)
mock_get.assert_called_once_with(self.context, uuids.image,
show_deleted=False)