Browse Source

Fix cluster deletion when load balancers don't exist

During cluster deletion, magnum tries to delete the cluster's load
balancers in advance of deleting the heat stack. If these load balancers
do not exist for some reason, the cluster deletion will fail with an
error such as the following:

    Failed to pre-delete resources for cluster
    748b628a-2cd8-456f-8aee-c93804b2099b, error: list indices must be
    integers or slices, not str.

This happens because the heat stack has the physical_resource_id set to
None for the load balancer, which causes the load_balancer_show method
of octavia client to GET all load balancers, rather than just one. The
returned data is a list, rather than a dict, leading to the error above.

This change fixes the issue by checking if physical_resource_id is set
to None, and skipping the load balancer deletion if so.

Change-Id: I8f4ca497a01ad04db6cb6c4bc81caed0d714b5a6
Story: 2008548
Task: 41669
changes/95/771995/1
Mark Goddard 5 months ago
parent
commit
8018bf9124
3 changed files with 32 additions and 0 deletions
  1. +2
    -0
      magnum/common/octavia.py
  2. +24
    -0
      magnum/tests/unit/common/test_octavia.py
  3. +6
    -0
      releasenotes/notes/story-2008548-65a571ad15451937.yaml

+ 2
- 0
magnum/common/octavia.py View File

@ -111,6 +111,8 @@ def delete_loadbalancers(context, cluster):
filters={"type": lb_resource_type})
for lb_res in lb_resources:
lb_id = lb_res.physical_resource_id
if not lb_id:
continue
try:
lb = octavia_client.load_balancer_show(lb_id)
lbs.append(lb)


+ 24
- 0
magnum/tests/unit/common/test_octavia.py View File

@ -145,3 +145,27 @@ class OctaviaTest(base.TestCase):
self.context,
self.cluster
)
@mock.patch("magnum.common.neutron.delete_floatingip")
@mock.patch('magnum.common.clients.OpenStackClients')
def test_delete_loadbalancers_already_deleted(self, mock_clients,
mock_delete_fip):
mock_octavia_client = mock.MagicMock()
mock_octavia_client.load_balancer_list.return_value = {
"loadbalancers": []
}
mock_heat_client = mock.MagicMock()
mock_heat_client.resources.list.return_value = [
TestHeatLBResource(None)
]
osc = mock.MagicMock()
mock_clients.return_value = osc
osc.octavia.return_value = mock_octavia_client
osc.heat.return_value = mock_heat_client
octavia.delete_loadbalancers(self.context, self.cluster)
self.assertFalse(mock_octavia_client.load_balancer_show.called)
self.assertFalse(mock_octavia_client.load_balancer_delete.called)

+ 6
- 0
releasenotes/notes/story-2008548-65a571ad15451937.yaml View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue with cluster deletion if load balancers do not exist. See
`story 2008548 <https://storyboard.openstack.org/#!/story/2008548>` for
details.

Loading…
Cancel
Save