Skip to content

Commit e238cc9

Browse files
committed
Allow deletion of compute service with no compute nodes
Consider the following situation: - Using the Ironic virt driver - Replacing (so removing and re-adding) all baremetal nodes associated with a single nova-compute service The update resources periodic will have destroyed the compute node records because they're no longer being reported by the virt driver. If we then attempt to manually delete the compute service record, the datbase layer will raise an exception, as there are no longer any compute node records for the host. Previously, this exception would get bubbled up as an error 500 in the API. This patch catches it and allows service deletion to complete succefully. Closes bug: 1860312 Change-Id: I2f9ad3df25306e070c8c3538bfed1212d6d8682f (cherry picked from commit 880611d) (cherry picked from commit df5158b)
1 parent 9efdd0b commit e238cc9

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

nova/api/openstack/compute/services.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,25 @@ def delete(self, req, id):
267267
# service delete since we could orphan resource providers and
268268
# break the ability to do things like confirm/revert instances
269269
# in VERIFY_RESIZE status.
270-
compute_nodes = objects.ComputeNodeList.get_all_by_host(
271-
context, service.host)
272-
self._assert_no_in_progress_migrations(
273-
context, id, compute_nodes)
270+
compute_nodes = []
271+
try:
272+
compute_nodes = objects.ComputeNodeList.get_all_by_host(
273+
context, service.host)
274+
self._assert_no_in_progress_migrations(
275+
context, id, compute_nodes)
276+
except exception.ComputeHostNotFound:
277+
# NOTE(artom) Consider the following situation:
278+
# - Using the Ironic virt driver
279+
# - Replacing (so removing and re-adding) all baremetal
280+
# nodes associated with a single nova-compute service
281+
# The update resources periodic will have destroyed the
282+
# compute node records because they're no longer being
283+
# reported by the virt driver. If we then attempt to
284+
# manually delete the compute service record,
285+
# get_all_host() above will raise, as there are no longer
286+
# any compute node records for the host. Catch it here and
287+
# continue to allow compute service deletion.
288+
pass
274289

275290
aggrs = self.aggregate_api.get_aggregates_by_host(context,
276291
service.host)

nova/tests/unit/api/openstack/compute/test_services.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,7 @@ def test_services_delete_compute_host_not_found(
712712
'topic': 'compute',
713713
'report_count': 0})
714714
compute.create()
715-
# FIXME(artom) Until bug 1860312 is fixed, the ComputeHostNotFound
716-
# error will get bubbled up to the API as an error 500.
717-
self.assertRaises(
718-
webob.exc.HTTPInternalServerError,
719-
self.controller.delete, self.req, compute.id)
715+
self.controller.delete(self.req, compute.id)
720716
mock_get_all_by_host.assert_called_with(
721717
self.req.environ['nova.context'], 'fake-compute-host')
722718

0 commit comments

Comments
 (0)