From 86889b91822669c37a6acd6b15ca12362e206637 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 3 Oct 2023 09:53:53 -0700 Subject: [PATCH] Warn if we find compute services in cell0 While debugging a field issue recently, we determined that computes had been pointed at cell0 and created service and node records there. This makes us warn during service list if we find compute services in cell0 to tip off operators that they have a configuration problem. Change-Id: Id95c0d02cc34348623b01997fcd1930628d48ccc --- nova/compute/api.py | 11 +++++++++++ nova/tests/unit/compute/test_host_api.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) 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')