diff --git a/nova/db/main/api.py b/nova/db/main/api.py index b1edb80c7e..13b84c544d 100644 --- a/nova/db/main/api.py +++ b/nova/db/main/api.py @@ -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 diff --git a/nova/tests/functional/regressions/test_bug_2085135.py b/nova/tests/functional/regressions/test_bug_2085135.py index 3fbb5eb71c..f5d5821436 100644 --- a/nova/tests/functional/regressions/test_bug_2085135.py +++ b/nova/tests/functional/regressions/test_bug_2085135.py @@ -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)) diff --git a/nova/tests/unit/db/main/test_api.py b/nova/tests/unit/db/main/test_api.py index c544952506..f02a3208bc 100644 --- a/nova/tests/unit/db/main/test_api.py +++ b/nova/tests/unit/db/main/test_api.py @@ -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 = {