Skip to content

Commit 4888f70

Browse files
committed
Fix deleting clusters if stack is deleted
If a stack has been deleted (either by Magnum or the user) but Magnum did not update and set `stack_id` to empty, the cluster will fail to delete inside pre-deletion. This will have a safe failover to skip if it can't find the Heat stack, it assumes things are gone. Change-Id: I6ebe188895e51ed83ad1514a380e4772fed5eb42
1 parent 0bf3242 commit 4888f70

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

magnum/common/octavia.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import re
1515
import time
1616

17+
import heatclient.exc as heat_exc
1718
from osc_lib import exceptions as osc_exc
1819
from oslo_config import cfg
1920
from oslo_log import log as logging
@@ -106,9 +107,14 @@ def delete_loadbalancers(context, cluster):
106107

107108
# Get load balancers created for Kubernetes api/etcd
108109
lbs = []
109-
lb_resources = heat_client.resources.list(
110-
cluster.stack_id, nested_depth=2,
111-
filters={"type": lb_resource_type})
110+
try:
111+
lb_resources = heat_client.resources.list(
112+
cluster.stack_id, nested_depth=2,
113+
filters={"type": lb_resource_type})
114+
except heat_exc.HTTPNotFound:
115+
# NOTE(mnaser): It's possible that the stack has been deleted
116+
# but Magnum still has a `stack_id` pointing.
117+
return
112118
for lb_res in lb_resources:
113119
lb_id = lb_res.physical_resource_id
114120
if not lb_id:

magnum/tests/unit/common/test_octavia.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from unittest import mock
1616

17+
import heatclient.exc as heat_exc
18+
1719
from magnum.common import exception
1820
from magnum.common import octavia
1921
from magnum import objects
@@ -169,3 +171,26 @@ def test_delete_loadbalancers_already_deleted(self, mock_clients,
169171

170172
self.assertFalse(mock_octavia_client.load_balancer_show.called)
171173
self.assertFalse(mock_octavia_client.load_balancer_delete.called)
174+
175+
@mock.patch("magnum.common.neutron.delete_floatingip")
176+
@mock.patch('magnum.common.clients.OpenStackClients')
177+
def test_delete_loadbalancers_with_stack_not_found(self, mock_clients,
178+
mock_delete_fip):
179+
mock_octavia_client = mock.MagicMock()
180+
mock_octavia_client.load_balancer_list.return_value = {
181+
"loadbalancers": []
182+
}
183+
184+
mock_heat_client = mock.MagicMock()
185+
mock_heat_client.resources.list.side_effect = \
186+
heat_exc.HTTPNotFound
187+
188+
osc = mock.MagicMock()
189+
mock_clients.return_value = osc
190+
osc.octavia.return_value = mock_octavia_client
191+
osc.heat.return_value = mock_heat_client
192+
193+
octavia.delete_loadbalancers(self.context, self.cluster)
194+
195+
self.assertFalse(mock_octavia_client.load_balancer_show.called)
196+
self.assertFalse(mock_octavia_client.load_balancer_delete.called)

0 commit comments

Comments
 (0)