summaryrefslogtreecommitdiff
path: root/nova/tests/unit/conductor
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2019-10-11 09:53:01 -0700
committerDan Smith <dansmith@redhat.com>2019-10-29 07:05:51 -0700
commit7ecd502f6df01efe8ed829cd0513df1d7bf9f9da (patch)
tree4128143a2660a7835865a6c0124eaff8f7a8e50b /nova/tests/unit/conductor
parent9742a64403c0a0ae5e0b37df5b0bf3ba14ac4626 (diff)
downloadnova-7ecd502f6df01efe8ed829cd0513df1d7bf9f9da.tar.gz
Log some stats for image pre-cache
This attempts to log some statistics about a precache operation so that, barring something more complicated on the operator side, there is some useful information in the logs about what is going on. Related to blueprint image-precache-support Change-Id: I550afc344eca30c366ba0e5342966bcbaac96bfe
Diffstat (limited to 'nova/tests/unit/conductor')
-rw-r--r--nova/tests/unit/conductor/test_conductor.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/nova/tests/unit/conductor/test_conductor.py b/nova/tests/unit/conductor/test_conductor.py
index 6ab271de03..a2f4e64502 100644
--- a/nova/tests/unit/conductor/test_conductor.py
+++ b/nova/tests/unit/conductor/test_conductor.py
@@ -3661,3 +3661,47 @@ class ConductorTaskAPITestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
mock_cache.assert_not_called()
_test()
+
+ @mock.patch('nova.objects.HostMapping.get_by_host')
+ @mock.patch('nova.context.target_cell')
+ @mock.patch('nova.objects.Service.get_by_compute_host')
+ def test_cache_images_failed_compute(self, mock_service, mock_target,
+ mock_gbh):
+ """Test the edge cases for cache_images(), specifically the
+ error, skip, and down situations.
+ """
+
+ fake_service = objects.Service(disabled=False, forced_down=False,
+ last_seen_up=timeutils.utcnow())
+ fake_down_service = objects.Service(disabled=False, forced_down=True,
+ last_seen_up=None)
+ mock_service.side_effect = [fake_service, fake_service,
+ fake_down_service]
+ mock_target.__return_value.__enter__.return_value = self.context
+ fake_cell = objects.CellMapping(uuid=uuids.cell,
+ database_connection='',
+ transport_url='')
+ fake_mapping = objects.HostMapping(cell_mapping=fake_cell)
+ mock_gbh.return_value = fake_mapping
+ fake_agg = objects.Aggregate(name='agg', uuid=uuids.agg,
+ hosts=['host1', 'host2', 'host3'])
+
+ @mock.patch.object(self.conductor_manager.compute_rpcapi,
+ 'cache_images')
+ def _test(mock_cache):
+ mock_cache.side_effect = [
+ {'image1': 'unsupported'},
+ {'image1': 'error'},
+ ]
+ self.conductor_manager.cache_images(self.context,
+ fake_agg,
+ ['image1'])
+
+ _test()
+
+ logtext = self.stdlog.logger.output
+ self.assertIn(
+ '0 cached, 0 existing, 1 errors, 1 unsupported, 1 skipped',
+ logtext)
+ self.assertIn('host3\' because it is not up', logtext)
+ self.assertIn('image1 failed 1 times', logtext)