Browse Source

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)
(cherry picked from commit e00fa24a18)
tags/18.3.0
Pavel Glushchak Sylvain Bauza 6 months ago
parent
commit
af668d395d
2 changed files with 16 additions and 6 deletions
  1. +7
    -6
      nova/db/sqlalchemy/api.py
  2. +9
    -0
      nova/tests/unit/db/test_db_api.py

+ 7
- 6
nova/db/sqlalchemy/api.py View File

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


+ 9
- 0
nova/tests/unit/db/test_db_api.py View File

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


Loading…
Cancel
Save