diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index efda6754b092..03362d70908c 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -397,12 +397,13 @@ def service_destroy(context, service_id): filter_by(id=service_id).\ soft_delete(synchronize_session=False) - # TODO(sbauza): Remove the service_id filter in a later release - # once we are sure that all compute nodes report the host field - model_query(context, models.ComputeNode).\ - filter(or_(models.ComputeNode.service_id == service_id, - models.ComputeNode.host == service['host'])).\ - soft_delete(synchronize_session=False) + 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 + model_query(context, models.ComputeNode).\ + filter(or_(models.ComputeNode.service_id == service_id, + models.ComputeNode.host == service['host'])).\ + soft_delete(synchronize_session=False) @pick_context_manager_reader diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 586a186e7905..3ae6b6c83247 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -3471,6 +3471,15 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin): self._assertEqualObjects(db.service_get(self.ctxt, service2['id']), service2, ignored_keys=['compute_node']) + def test_service_destroy_not_nova_compute(self): + service = self._create_service({'binary': 'nova-consoleauth', + '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']) + # make sure ComputeHostNotFound is not raised + db.compute_node_get(self.ctxt, compute_node['id']) + def test_service_update(self): service = self._create_service({}) new_values = {