Skip to content

Commit

Permalink
fix VM power state to be NOSTATE when instance not found
Browse files Browse the repository at this point in the history
* nova/compute/manager.py (_sync_power_states): Revert what looks
like an inadvertent change that was part of commit 95e7770.
Also log the condition.

Fixes bug: 1085771
Change-Id: Ic6eeb9207323f05b93f0b613bd1bddd681ad8ce5
  • Loading branch information
Pádraig Brady committed Feb 9, 2013
1 parent ba708ea commit ad101ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion nova/compute/manager.py
Expand Up @@ -3371,7 +3371,7 @@ def _sync_power_states(self, context):
vm_instance = self.driver.get_info(db_instance)
vm_power_state = vm_instance['state']
except exception.InstanceNotFound:
vm_power_state = power_state.SHUTDOWN
vm_power_state = power_state.NOSTATE
# Note(maoy): the above get_info call might take a long time,
# for example, because of a broken libvirt driver.
# We re-query the DB to get the latest instance info to minimize
Expand Down Expand Up @@ -3458,6 +3458,12 @@ def _sync_power_states(self, context):
# instrumentation is done. See bug 1097806 for details.
LOG.warn(_("Instance is paused unexpectedly. Ignore."),
instance=db_instance)
elif vm_power_state == power_state.NOSTATE:
# Occasionally, depending on the status of the hypervisor,
# which could be restarting for example, an instance may
# not be found. Therefore just log the condidtion.
LOG.warn(_("Instance is unexpectedly not found. Ignore."),
instance=db_instance)
elif vm_state == vm_states.STOPPED:
if vm_power_state not in (power_state.NOSTATE,
power_state.SHUTDOWN,
Expand Down
2 changes: 1 addition & 1 deletion nova/tests/compute/test_compute.py
Expand Up @@ -2776,7 +2776,7 @@ def test_run_kill_vm(self):
instances = db.instance_get_all(self.context)
LOG.info(_("After force-killing instances: %s"), instances)
self.assertEqual(len(instances), 1)
self.assertEqual(task_states.POWERING_OFF, instances[0]['task_state'])
self.assertEqual(instances[0]['task_state'], None)

def test_add_instance_fault(self):
instance = self._create_fake_instance()
Expand Down

0 comments on commit ad101ce

Please sign in to comment.