Skip to content

Commit 98a335c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Delete resource providers for all nodes when deleting compute service" into stable/rocky
2 parents 5e564c1 + 64d5278 commit 98a335c

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

nova/api/openstack/compute/services.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,14 @@ def delete(self, req, id):
245245
ag.id,
246246
service.host)
247247
# remove the corresponding resource provider record from
248-
# placement for this compute node
249-
self.placementclient.delete_resource_provider(
250-
context, service.compute_node, cascade=True)
248+
# placement for the compute nodes managed by this service;
249+
# remember that an ironic compute service can manage multiple
250+
# nodes
251+
compute_nodes = objects.ComputeNodeList.get_all_by_host(
252+
context, service.host)
253+
for compute_node in compute_nodes:
254+
self.placementclient.delete_resource_provider(
255+
context, compute_node, cascade=True)
251256
# remove the host_mapping of this host.
252257
try:
253258
hm = objects.HostMapping.get_by_host(context, service.host)

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,25 +712,33 @@ def test_compute_service_delete_host_mapping_not_found(
712712
"""Tests that we are still able to successfully delete a nova-compute
713713
service even if the HostMapping is not found.
714714
"""
715+
@mock.patch('nova.objects.ComputeNodeList.get_all_by_host',
716+
return_value=objects.ComputeNodeList(objects=[
717+
objects.ComputeNode(host='host1',
718+
hypervisor_hostname='node1'),
719+
objects.ComputeNode(host='host1',
720+
hypervisor_hostname='node2')]))
715721
@mock.patch.object(self.controller.host_api, 'service_get_by_id',
716722
return_value=objects.Service(
717-
host='host1', binary='nova-compute',
718-
compute_node=objects.ComputeNode()))
723+
host='host1', binary='nova-compute'))
719724
@mock.patch.object(self.controller.aggregate_api,
720725
'get_aggregates_by_host',
721726
return_value=objects.AggregateList())
722727
@mock.patch.object(self.controller.placementclient,
723728
'delete_resource_provider')
724729
def _test(delete_resource_provider,
725-
get_aggregates_by_host, service_get_by_id):
730+
get_aggregates_by_host, service_get_by_id,
731+
cn_get_all_by_host):
726732
self.controller.delete(self.req, 2)
727733
ctxt = self.req.environ['nova.context']
728734
service_get_by_id.assert_called_once_with(ctxt, 2)
729735
get_instances.assert_called_once_with(ctxt, 'host1')
730736
get_aggregates_by_host.assert_called_once_with(ctxt, 'host1')
731-
delete_resource_provider.assert_called_once_with(
732-
ctxt, service_get_by_id.return_value.compute_node,
733-
cascade=True)
737+
self.assertEqual(2, delete_resource_provider.call_count)
738+
nodes = cn_get_all_by_host.return_value
739+
delete_resource_provider.assert_has_calls([
740+
mock.call(ctxt, node, cascade=True) for node in nodes
741+
], any_order=True)
734742
get_hm.assert_called_once_with(ctxt, 'host1')
735743
service_delete.assert_called_once_with()
736744
_test()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
fixes:
3+
- |
4+
`Bug 1811726`_ is fixed by deleting the resource provider (in placement)
5+
associated with each compute node record managed by a ``nova-compute``
6+
service when that service is deleted via the
7+
``DELETE /os-services/{service_id}`` API. This is particularly important
8+
for compute services managing ironic baremetal nodes.
9+
10+
.. _Bug 1811726: https://bugs.launchpad.net/nova/+bug/1811726

0 commit comments

Comments
 (0)