Merge "Grab fresh power state info from the driver"

This commit is contained in:
Zuul
2019-06-27 12:41:06 +00:00
committed by Gerrit Code Review
2 changed files with 18 additions and 3 deletions
+1 -1
View File
@@ -1283,7 +1283,7 @@ class ComputeManager(manager.Manager):
"""Retrieve the power state for the given instance."""
LOG.debug('Checking state', instance=instance)
try:
return self.driver.get_info(instance).state
return self.driver.get_info(instance, use_cache=False).state
except exception.InstanceNotFound:
return power_state.NOSTATE
+17 -2
View File
@@ -1168,8 +1168,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
mock_finish.assert_called_once_with(self.context, instance,
[], [], power_on)
mock_save.assert_called_once_with()
mock_get_info.assert_has_calls([mock.call(instance),
mock.call(instance)])
mock_get_info.assert_has_calls(
[mock.call(instance, use_cache=False),
mock.call(instance, use_cache=False)])
self.assertIsNone(instance.task_state)
def test_init_instance_reverts_crashed_migration_from_active(self):
@@ -1641,6 +1642,20 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
self.compute.stop_instance.assert_has_calls([call])
self.assertIsNone(init_return)
def test_get_power_state(self):
instance = objects.Instance(self.context)
instance.uuid = uuids.instance
instance.id = 1
instance.vm_state = vm_states.STOPPED
instance.task_state = None
instance.host = self.compute.host
with mock.patch.object(self.compute.driver, 'get_info') as mock_info:
mock_info.return_value = hardware.InstanceInfo(
state=power_state.SHUTDOWN)
res = self.compute._get_power_state(self.context, instance)
mock_info.assert_called_once_with(instance, use_cache=False)
self.assertEqual(res, power_state.SHUTDOWN)
@mock.patch('nova.objects.InstanceList.get_by_filters')
def test_get_instances_on_driver(self, mock_instance_list):
driver_instances = []