From 38d1b141705f7118fbb519ac9c56bf1f425ad3fd Mon Sep 17 00:00:00 2001 From: Julien Le Jeune Date: Mon, 6 Oct 2025 09:40:12 +0200 Subject: [PATCH] Update start_service() function in test Update the 'mapped' field of the created node to be coherent with what it's done in _check_and_create_node_host_mappings function [1]. [1] https://opendev.org/openstack/nova/src/commit/cc742602bcdeff185ff120452e4f301398f6aa7b/nova/objects/host_mapping.py#L209 Related-Bug: #2085135 Change-Id: I9965932adc521756e4583d1bcfc75c83cc630626 Signed-off-by: Julien Le Jeune --- nova/test.py | 17 +++++++++++++++-- nova/tests/functional/test_service.py | 2 -- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/nova/test.py b/nova/test.py index 335bb759dd45..eca3e2c151f0 100644 --- a/nova/test.py +++ b/nova/test.py @@ -468,6 +468,8 @@ class TestCase(base.BaseTestCase): ctxt = context.get_context() cell_name = cell_name or CELL1_NAME cell = self.cell_mappings[cell_name] + svc = self.useFixture( + nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs)) if (host or name) not in self.host_mappings: # NOTE(gibi): If the HostMapping does not exists then this is # the first start of the service so we create the mapping. @@ -476,8 +478,19 @@ class TestCase(base.BaseTestCase): cell_mapping=cell) hm.create() self.host_mappings[hm.host] = hm - svc = self.useFixture( - nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs)) + + # NOTE(jlejeune): update the compute node's mapped field + # like it's done in _check_and_create_node_host_mappings() + # function. + with context.target_cell(ctxt, cell) as cctxt: + node = objects.ComputeNode.get_by_service_id( + context=cctxt, + service_id=svc.service.service_ref.id) + node.mapped = 1 + node.save() + else: + svc = self.useFixture( + nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs)) # Keep track of how many instances of this service are running. self._service_fixture_count[name] += 1 diff --git a/nova/tests/functional/test_service.py b/nova/tests/functional/test_service.py index 9ffab96da3fd..a3cdbee5d99f 100644 --- a/nova/tests/functional/test_service.py +++ b/nova/tests/functional/test_service.py @@ -51,7 +51,6 @@ class ServiceTestCase(test.TestCase, """Tests that the cell cache for database transaction context managers is cleared after a service reset (example scenario: SIGHUP). """ - self.assertFalse(nova_context.CELL_CACHE) server_req = self._build_server() server = self.api.post_server({'server': server_req}) self._wait_for_state_change(server, 'ACTIVE') @@ -66,7 +65,6 @@ class ServiceTestCase(test.TestCase, is cleared upon a service start (example scenario: service start after a SIGTERM and the parent process forks child process workers). """ - self.assertFalse(nova_context.CELL_CACHE) server_req = self._build_server() server = self.api.post_server({'server': server_req}) self._wait_for_state_change(server, 'ACTIVE')