Skip to content

Commit 5b1c9dd

Browse files
committed
Grab fresh power state info from the driver
In drivers that use a cache to store the node info (presently only ironic since [1]), the "_get_power_state" function called during instance actions like start or stop grabs the information from the node cache and saves it in the nova database instead of getting fresh information from the driver. This leads to inconsistency between the vm_state and power_state for an instance in the nova database (which remains until a power_sync happens between nova and ironic). This can be confusing for a user when doing "nova list" where the power_state might still be shutdown when the vm_state has already become active. On a default environment this inconsistency lasts for about ten minutes which is the default value for the sync_power_state_interval interval. This patch changes the "use_cache" to False in the compute manager when triggering an action on an instance like start/stop/reboot. [1] I907b69eb689cf6c169a4869cfc7889308ca419d5 Change-Id: I8bca5d84c37d02331d2f9968a674f3398c1a8f5b Closes-Bug: #1832720
1 parent a628d2f commit 5b1c9dd

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

nova/compute/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ def _get_power_state(self, context, instance):
12811281
"""Retrieve the power state for the given instance."""
12821282
LOG.debug('Checking state', instance=instance)
12831283
try:
1284-
return self.driver.get_info(instance).state
1284+
return self.driver.get_info(instance, use_cache=False).state
12851285
except exception.InstanceNotFound:
12861286
return power_state.NOSTATE
12871287

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,9 @@ def _test_init_instance_reverts_crashed_migrations(self,
11681168
mock_finish.assert_called_once_with(self.context, instance,
11691169
[], [], power_on)
11701170
mock_save.assert_called_once_with()
1171-
mock_get_info.assert_has_calls([mock.call(instance),
1172-
mock.call(instance)])
1171+
mock_get_info.assert_has_calls(
1172+
[mock.call(instance, use_cache=False),
1173+
mock.call(instance, use_cache=False)])
11731174
self.assertIsNone(instance.task_state)
11741175

11751176
def test_init_instance_reverts_crashed_migration_from_active(self):
@@ -1641,6 +1642,20 @@ def test_init_instance_retries_power_off_silent_exception(self):
16411642
self.compute.stop_instance.assert_has_calls([call])
16421643
self.assertIsNone(init_return)
16431644

1645+
def test_get_power_state(self):
1646+
instance = objects.Instance(self.context)
1647+
instance.uuid = uuids.instance
1648+
instance.id = 1
1649+
instance.vm_state = vm_states.STOPPED
1650+
instance.task_state = None
1651+
instance.host = self.compute.host
1652+
with mock.patch.object(self.compute.driver, 'get_info') as mock_info:
1653+
mock_info.return_value = hardware.InstanceInfo(
1654+
state=power_state.SHUTDOWN)
1655+
res = self.compute._get_power_state(self.context, instance)
1656+
mock_info.assert_called_once_with(instance, use_cache=False)
1657+
self.assertEqual(res, power_state.SHUTDOWN)
1658+
16441659
@mock.patch('nova.objects.InstanceList.get_by_filters')
16451660
def test_get_instances_on_driver(self, mock_instance_list):
16461661
driver_instances = []

0 commit comments

Comments
 (0)