Reset the mapped field of nodes at service deletion

Make sure that the 'mapped' field of compute nodes is reset
to 0 at nova-compute service deletion.

To let nova-manage create the missing host mapping in nova_api
database.

Closes-Bug: #2085135
Change-Id: I774d4312d7e94af94d960f7269717a00fa08c583
Signed-off-by: Julien Le Jeune <julien.le-jeune@ovhcloud.com>
This commit is contained in:
Julien Le Jeune
2024-10-22 17:15:57 +02:00
parent 4073297ae3
commit c04c94ecfb
3 changed files with 24 additions and 3 deletions
+8 -1
View File
@@ -383,11 +383,18 @@ def service_destroy(context, service_id):
if service.binary == 'nova-compute':
# TODO(sbauza): Remove the service_id filter in a later release
# once we are sure that all compute nodes report the host field
# NOTE(jlejeune): Make sure that the mapped field of the
# relevant compute nodes is set to 0
# See https://bugs.launchpad.net/nova/+bug/2085135.
model_query(context, models.ComputeNode).\
filter(sql.or_(
models.ComputeNode.service_id == service_id,
models.ComputeNode.host == service['host'])).\
soft_delete(synchronize_session=False)
update({'deleted': models.ComputeNode.id,
'updated_at': models.ComputeNode.updated_at,
'deleted_at': timeutils.utcnow(),
'mapped': 0},
synchronize_session=False)
@pick_context_manager_reader
@@ -69,7 +69,7 @@ class HostMappingDiscoveryTestFail(test.TestCase):
self.assertEqual(node['uuid'], node_uuid)
# Bug #2085135: node should be unmapped and be discoverable
self.assertEqual(node['mapped'], 1)
self.assertEqual(node['mapped'], 0)
mappings = host_mapping.discover_hosts(
self.ctxt, status_fn=lambda m: None)
self.assertEqual(0, len(mappings))
self.assertEqual(1, len(mappings))
+14
View File
@@ -2941,6 +2941,20 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
# make sure ComputeHostNotFound is not raised
db.compute_node_get(self.ctxt, compute_node['id'])
def test_service_destroy_and_reset_mapped_field(self):
# Test added for bug #2085135, this test tests that mapped
# field of deleted compute node is reset to 0
service = self._create_service({'binary': 'nova-compute',
'host': 'host1'})
compute_node_dict = _make_compute_node('host1', 'node1', 'kvm', None)
compute_node = db.compute_node_create(self.ctxt, compute_node_dict)
db.service_destroy(self.ctxt, service['id'])
# check that compute_node's mapped filed is reset to 0
self.ctxt.read_deleted = "yes"
cn = db.compute_node_get(self.ctxt, compute_node['id'])
self.assertEqual(cn['mapped'], 0)
def test_service_update(self):
service = self._create_service({})
new_values = {