diff --git a/nova/compute/api.py b/nova/compute/api.py index d64432327e..7f0e96ea47 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -6223,6 +6223,17 @@ class HostAPI: services = [] service_dict = nova_context.scatter_gather_all_cells(context, objects.ServiceList.get_all, disabled, set_zones=set_zones) + + cell0_computes = [ + x for x in + service_dict.get(objects.CellMapping.CELL0_UUID, []) + if x.binary == 'nova-compute'] + for cn in cell0_computes: + LOG.warning( + 'Found compute service %(service)s in cell0; ' + 'This should never happen!', + {'service': cn.host}) + for cell_uuid, service in service_dict.items(): if not nova_context.is_cell_failure_sentinel(service): services.extend(service) diff --git a/nova/tests/unit/compute/test_host_api.py b/nova/tests/unit/compute/test_host_api.py index 7f9e862057..e586ce7555 100644 --- a/nova/tests/unit/compute/test_host_api.py +++ b/nova/tests/unit/compute/test_host_api.py @@ -194,6 +194,20 @@ class ComputeHostAPITestCase(test.TestCase): self.assertEqual(['host-%s' % uuids.cell1], [svc.host for svc in services]) + @mock.patch('nova.context.scatter_gather_cells') + def test_service_get_all_cell0_computes(self, mock_sg): + service = objects.Service(binary='nova-compute', host='rogue') + mock_sg.return_value = { + objects.CellMapping.CELL0_UUID: [service], + } + with mock.patch.object(compute, 'LOG') as mock_log: + services = self.host_api.service_get_all(self.ctxt, all_cells=True) + mock_log.warning.assert_called_once_with( + 'Found compute service %(service)s in cell0; ' + 'This should never happen!', + {'service': 'rogue'}) + self.assertEqual([service], services) + @mock.patch('nova.objects.CellMappingList.get_all') @mock.patch.object(objects.HostMappingList, 'get_by_cell_id') @mock.patch('nova.context.scatter_gather_all_cells')