Don't delete compute node, when deleting service other than nova-compute

We should not try to delete compute node from compute_nodes table,
when destroying service other than nova-compute.

Change-Id: If5b5945e699ec2e2da51d5fa90616431274849b0
Closes-Bug: #1852993
Signed-off-by: Pavel Glushchak <pglushchak@virtuozzo.com>
(cherry picked from commit cff9ecb208)
(cherry picked from commit 716cde5454)
This commit is contained in:
Pavel Glushchak 2019-11-18 14:53:42 +03:00 committed by Sylvain Bauza
parent a054d03ade
commit e00fa24a18
2 changed files with 16 additions and 6 deletions

View File

@ -410,12 +410,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

View File

@ -3189,6 +3189,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 = {