Browse Source

Merge "Delete resource providers for all nodes when deleting compute service" into stable/queens

tags/17.0.12
Zuul 1 month ago
parent
commit
fcfc374d5e

+ 8
- 3
nova/api/openstack/compute/services.py View File

@@ -245,9 +245,14 @@ class ServiceController(wsgi.Controller):
245 245
                                                                   ag.id,
246 246
                                                                   service.host)
247 247
                 # 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)
251 256
                 # remove the host_mapping of this host.
252 257
                 try:
253 258
                     hm = objects.HostMapping.get_by_host(context, service.host)

+ 14
- 6
nova/tests/unit/api/openstack/compute/test_services.py View File

@@ -713,10 +713,15 @@ class ServicesTestV21(test.TestCase):
713 713
         """Tests that we are still able to successfully delete a nova-compute
714 714
         service even if the HostMapping is not found.
715 715
         """
716
+        @mock.patch('nova.objects.ComputeNodeList.get_all_by_host',
717
+                    return_value=objects.ComputeNodeList(objects=[
718
+                        objects.ComputeNode(host='host1',
719
+                                            hypervisor_hostname='node1'),
720
+                        objects.ComputeNode(host='host1',
721
+                                            hypervisor_hostname='node2')]))
716 722
         @mock.patch.object(self.controller.host_api, 'service_get_by_id',
717 723
                            return_value=objects.Service(
718
-                               host='host1', binary='nova-compute',
719
-                               compute_node=objects.ComputeNode()))
724
+                               host='host1', binary='nova-compute'))
720 725
         @mock.patch.object(self.controller.aggregate_api,
721 726
                            'get_aggregates_by_host',
722 727
                            return_value=objects.AggregateList())
@@ -724,15 +729,18 @@ class ServicesTestV21(test.TestCase):
724 729
                            'delete_resource_provider')
725 730
         @mock.patch.object(self.controller.host_api, 'service_delete')
726 731
         def _test(service_delete, delete_resource_provider,
727
-                  get_aggregates_by_host, service_get_by_id):
732
+                  get_aggregates_by_host, service_get_by_id,
733
+                  cn_get_all_by_host):
728 734
             self.controller.delete(self.req, 2)
729 735
             ctxt = self.req.environ['nova.context']
730 736
             service_get_by_id.assert_called_once_with(ctxt, 2)
731 737
             get_instances.assert_called_once_with(ctxt, 'host1')
732 738
             get_aggregates_by_host.assert_called_once_with(ctxt, 'host1')
733
-            delete_resource_provider.assert_called_once_with(
734
-                ctxt, service_get_by_id.return_value.compute_node,
735
-                cascade=True)
739
+            self.assertEqual(2, delete_resource_provider.call_count)
740
+            nodes = cn_get_all_by_host.return_value
741
+            delete_resource_provider.assert_has_calls([
742
+                mock.call(ctxt, node, cascade=True) for node in nodes
743
+            ], any_order=True)
736 744
             get_hm.assert_called_once_with(ctxt, 'host1')
737 745
             service_delete.assert_called_once_with(ctxt, 2)
738 746
         _test()

+ 10
- 0
releasenotes/notes/bug-1811726-multi-node-delete-2ba17f02c6171fbb.yaml View File

@@ -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

Loading…
Cancel
Save