Skip to content

Commit df5158b

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)
1 parent e6cd23c commit df5158b

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

274289
aggrs = self.aggregate_api.get_aggregates_by_host(context,
275290
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
@@ -711,11 +711,7 @@ def test_services_delete_compute_host_not_found(
711711
'topic': 'compute',
712712
'report_count': 0})
713713
compute.create()
714-
# FIXME(artom) Until bug 1860312 is fixed, the ComputeHostNotFound
715-
# error will get bubbled up to the API as an error 500.
716-
self.assertRaises(
717-
webob.exc.HTTPInternalServerError,
718-
self.controller.delete, self.req, compute.id)
714+
self.controller.delete(self.req, compute.id)
719715
mock_get_all_by_host.assert_called_with(
720716
self.req.environ['nova.context'], 'fake-compute-host')
721717

0 commit comments

Comments
 (0)