Handle MessagingException in unshelving instance

Add Handling MessagingException in nova-conductor
when unshelving instance

Change-Id: I4dd95ee08e9618b8fd51f043c0f89f4ddcf1cb35
Closes-Bug: #1367186
This commit is contained in:
Takashi NATSUME 2015-02-13 14:33:11 +09:00
parent 93a38ef4ff
commit a84be486c8
2 changed files with 31 additions and 0 deletions

View File

@ -766,6 +766,12 @@ class ComputeTaskManager(base.Base):
LOG.warning(_LW("No valid host found for unshelve instance"), LOG.warning(_LW("No valid host found for unshelve instance"),
instance=instance) instance=instance)
return return
except Exception:
with excutils.save_and_reraise_exception():
instance.task_state = None
instance.save()
LOG.error(_LE("Unshelve attempted but an error "
"has occurred"), instance=instance)
else: else:
LOG.error(_LE('Unshelve attempted but vm_state not SHELVED or ' LOG.error(_LE('Unshelve attempted but vm_state not SHELVED or '
'SHELVED_OFFLOADED'), instance=instance) 'SHELVED_OFFLOADED'), instance=instance)

View File

@ -40,6 +40,7 @@ from nova import context
from nova import db from nova import db
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import exception as exc from nova import exception as exc
from nova.image import api as image_api
from nova import notifications from nova import notifications
from nova import objects from nova import objects
from nova.objects import base as obj_base from nova.objects import base as obj_base
@ -1545,6 +1546,30 @@ class _BaseTaskTestCase(object):
show_deleted=False)]) show_deleted=False)])
self.assertEqual(vm_states.SHELVED_OFFLOADED, instance.vm_state) self.assertEqual(vm_states.SHELVED_OFFLOADED, instance.vm_state)
@mock.patch.object(conductor_manager.ComputeTaskManager,
'_schedule_instances',
side_effect=messaging.MessagingTimeout())
@mock.patch.object(image_api.API, 'get', return_value='fake_image')
def test_unshelve_instance_schedule_and_rebuild_messaging_exception(
self, mock_get_image, mock_schedule_instances):
instance = self._create_fake_instance_obj()
instance.vm_state = vm_states.SHELVED_OFFLOADED
instance.task_state = task_states.UNSHELVING
instance.save()
system_metadata = instance.system_metadata
system_metadata['shelved_at'] = timeutils.utcnow()
system_metadata['shelved_image_id'] = 'fake_image_id'
system_metadata['shelved_host'] = 'fake-mini'
self.assertRaises(messaging.MessagingTimeout,
self.conductor_manager.unshelve_instance,
self.context, instance)
mock_get_image.assert_has_calls([mock.call(self.context,
system_metadata['shelved_image_id'],
show_deleted=False)])
self.assertEqual(vm_states.SHELVED_OFFLOADED, instance.vm_state)
self.assertIsNone(instance.task_state)
def test_unshelve_instance_schedule_and_rebuild_volume_backed(self): def test_unshelve_instance_schedule_and_rebuild_volume_backed(self):
instance = self._create_fake_instance_obj() instance = self._create_fake_instance_obj()
instance.vm_state = vm_states.SHELVED_OFFLOADED instance.vm_state = vm_states.SHELVED_OFFLOADED