diff options
author | Artom Lifshitz <alifshit@redhat.com> | 2021-07-19 12:58:29 +0200 |
---|---|---|
committer | Artom Lifshitz <alifshit@redhat.com> | 2021-07-29 10:47:54 +0200 |
commit | e238cc9cd6ee7ba9d556c0c29f6f69dc3e3a7af9 (patch) | |
tree | 60979bd351ec9a97c242c52db09505bcae286d31 | |
parent | 9efdd0b085733a0a4c4192aab8fc870c8aadf316 (diff) | |
download | nova-e238cc9cd6ee7ba9d556c0c29f6f69dc3e3a7af9.tar.gz |
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 880611df0b6b967adabd3f08886e385d0a100c5c)
(cherry picked from commit df5158bf3f80fd4362725dc280de67b88ece9952)
-rw-r--r-- | nova/api/openstack/compute/services.py | 23 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/compute/test_services.py | 6 |
2 files changed, 20 insertions, 9 deletions
diff --git a/nova/api/openstack/compute/services.py b/nova/api/openstack/compute/services.py index b462b1a9d9..be35f62ee3 100644 --- a/nova/api/openstack/compute/services.py +++ b/nova/api/openstack/compute/services.py @@ -267,10 +267,25 @@ class ServiceController(wsgi.Controller): # service delete since we could orphan resource providers and # break the ability to do things like confirm/revert instances # in VERIFY_RESIZE status. - compute_nodes = objects.ComputeNodeList.get_all_by_host( - context, service.host) - self._assert_no_in_progress_migrations( - context, id, compute_nodes) + compute_nodes = [] + try: + compute_nodes = objects.ComputeNodeList.get_all_by_host( + context, service.host) + self._assert_no_in_progress_migrations( + context, id, compute_nodes) + except exception.ComputeHostNotFound: + # NOTE(artom) 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, + # get_all_host() above will raise, as there are no longer + # any compute node records for the host. Catch it here and + # continue to allow compute service deletion. + pass aggrs = self.aggregate_api.get_aggregates_by_host(context, service.host) diff --git a/nova/tests/unit/api/openstack/compute/test_services.py b/nova/tests/unit/api/openstack/compute/test_services.py index 07acbaab16..94263833c7 100644 --- a/nova/tests/unit/api/openstack/compute/test_services.py +++ b/nova/tests/unit/api/openstack/compute/test_services.py @@ -712,11 +712,7 @@ class ServicesTestV21(test.TestCase): 'topic': 'compute', 'report_count': 0}) compute.create() - # FIXME(artom) Until bug 1860312 is fixed, the ComputeHostNotFound - # error will get bubbled up to the API as an error 500. - self.assertRaises( - webob.exc.HTTPInternalServerError, - self.controller.delete, self.req, compute.id) + self.controller.delete(self.req, compute.id) mock_get_all_by_host.assert_called_with( self.req.environ['nova.context'], 'fake-compute-host') |