when unshelve a vm, if this vm has been offloaded, the process would involve re-scheduling.
in nova/conductor/manager.py def unshelve_instance(self, context, instance):
elif instance.vm_state == vm_states.SHELVED_OFFLOADED:
try:
with compute_utils.EventReporter(context, self.db,
'get_image_info', instance.uuid):
image = self._get_image(context,
sys_meta['shelved_image_id'])
except exception.ImageNotFound:
with excutils.save_and_reraise_exception():
LOG.error(_('Unshelve attempted but vm_state not SHELVED '
'or SHELVED_OFFLOADED'), instance=instance)
instance.vm_state = vm_states.ERROR
instance.save()
filter_properties = {}
hosts = self._schedule_instances(context, image,
filter_properties,instance) <<<<<this re-scheduling would cause exception,when it occurs,the
<<<<<<instance will be stuck in task_state: unshelving forever
host = hosts.pop(0)['host']
self.compute_rpcapi.unshelve_instance(context, instance, host,
image)
I try to fix it by "try-except-else" like below:
elif instance.vm_state == vm_states. SHELVED_ OFFLOADED:
with compute_ utils.EventRepo rter(context, self.db,
'get_ image_info' , instance.uuid):
image = self._get_ image(context,
sys_meta[ 'shelved_ image_id' ]) ImageNotFound:
with excutils. save_and_ reraise_ exception( ):
LOG. error(_ ('Unshelve attempted but vm_state not SHELVED '
'or SHELVED_ OFFLOADED' ), instance=instance)
instance. vm_state = vm_states.ERROR
instance. save()
try:
except exception.
try:
filter_ properties = {}
hosts = self._schedule_ instances( context, image,
filter_ properties, instance)
host = hosts.pop( 0)['host' ]
instance. task_state = None
instance. save()
return
self. compute_ rpcapi. unshelve_ instance( context, instance, host,
image)
except:
else: