Commit a35f48e4 authored by Mohammed Naser's avatar Mohammed Naser Committed by Jake Yip
Browse files

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
(cherry picked from commit 4888f706)
parent 5870994f
......@@ -14,6 +14,7 @@
import re
import time
import heatclient.exc as heat_exc
from osc_lib import exceptions as osc_exc
from oslo_config import cfg
from oslo_log import log as logging
......@@ -71,7 +72,7 @@ def _delete_loadbalancers(context, lbs, cluster, octavia_client,
return candidates
def delete_loadbalancers(context, cluster):
def delete_loadbalancers(context, cluster): # noqa: C901
"""Delete loadbalancers for the cluster.
The following load balancers are deleted:
......@@ -106,9 +107,14 @@ def delete_loadbalancers(context, cluster):
# Get load balancers created for Kubernetes api/etcd
lbs = []
lb_resources = heat_client.resources.list(
cluster.stack_id, nested_depth=2,
filters={"type": lb_resource_type})
lb_resources = heat_client.resources.list(
cluster.stack_id, nested_depth=2,
filters={"type": lb_resource_type})
except heat_exc.HTTPNotFound:
# NOTE(mnaser): It's possible that the stack has been deleted
# but Magnum still has a `stack_id` pointing.
for lb_res in lb_resources:
lb_id = lb_res.physical_resource_id
if not lb_id:
......@@ -14,6 +14,8 @@
from unittest import mock
import heatclient.exc as heat_exc
from magnum.common import exception
from magnum.common import octavia
from magnum import objects
......@@ -169,3 +171,26 @@ class OctaviaTest(base.TestCase):
def test_delete_loadbalancers_with_stack_not_found(self, mock_clients,
mock_octavia_client = mock.MagicMock()
mock_octavia_client.load_balancer_list.return_value = {
"loadbalancers": []
mock_heat_client = mock.MagicMock()
mock_heat_client.resources.list.side_effect = \
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment