Merge "Ignore VirtDriverNotReady in _sync_power_states periodic task"

This commit is contained in:
Zuul 2018-09-26 20:51:53 +00:00 committed by Gerrit Code Review
commit 9254df870b
2 changed files with 22 additions and 1 deletions

View File

@ -7465,7 +7465,14 @@ class ComputeManager(manager.Manager):
expected_attrs=[],
use_slave=True)
num_vm_instances = self.driver.get_num_instances()
try:
num_vm_instances = self.driver.get_num_instances()
except exception.VirtDriverNotReady as e:
# If the virt driver is not ready, like ironic-api not being up
# yet in the case of ironic, just log it and exit.
LOG.info('Skipping _sync_power_states periodic task due to: %s', e)
return
num_db_instances = len(db_instances)
if num_vm_instances != num_db_instances:

View File

@ -1790,6 +1790,20 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
use_slave=True)
mock_spawn.assert_called_once_with(mock.ANY, instance)
@mock.patch('nova.objects.InstanceList.get_by_host', new=mock.Mock())
@mock.patch('nova.compute.manager.ComputeManager.'
'_query_driver_power_state_and_sync',
new_callable=mock.NonCallableMock)
def test_sync_power_states_virt_driver_not_ready(self, _mock_sync):
""""Tests that the periodic task exits early if the driver raises
VirtDriverNotReady.
"""
with mock.patch.object(
self.compute.driver, 'get_num_instances',
side_effect=exception.VirtDriverNotReady) as gni:
self.compute._sync_power_states(mock.sentinel.context)
gni.assert_called_once_with()
def _get_sync_instance(self, power_state, vm_state, task_state=None,
shutdown_terminate=False):
instance = objects.Instance()