From cc085b4cf4c3ee5e06fa13856f30e3264d8652a7 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Sun, 18 Jan 2015 11:33:38 -0700 Subject: [PATCH] Delete bay independent of presence of heat stack If the Heat stack has already been deleted by the user, it shouldn't block the bay from being deleted. Instead just ignore that Heat exception and continue on deleting the bay as if the Heat stack had already been deleted (because it has, or Heat has suffered data loss) Change-Id: I38da49044f155105502a7e1bcccff45cde29fa86 Closes-Bug: 1412204 --- magnum/conductor/handlers/bay_k8s_heat.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/magnum/conductor/handlers/bay_k8s_heat.py b/magnum/conductor/handlers/bay_k8s_heat.py index 62d0a6a50d..c539ac5dbd 100644 --- a/magnum/conductor/handlers/bay_k8s_heat.py +++ b/magnum/conductor/handlers/bay_k8s_heat.py @@ -13,6 +13,7 @@ # under the License. from heatclient.common import template_utils +from heatclient import exc from oslo.config import cfg from magnum.common import clients @@ -150,7 +151,22 @@ class Handler(object): bay = objects.Bay.get_by_uuid(ctxt, uuid) stack_id = bay.stack_id # TODO(yuanying): handle stack status DELETE_IN_PROGRESS - osc.heat().stacks.delete(stack_id) + # + # NOTE(sdake): This will execute a stack_delete operation. This will + # Ignore HTTPNotFound exceptions (stack wasn't present). In the case + # that Heat couldn't find the stack representing the bay, likely a user + # has deleted the stack outside the context of Magnum. Therefore the + # contents of the bay are forever lost. + # + # If the exception is unhandled, the original exception will be raised. + try: + osc.heat().stacks.delete(stack_id) + except Exception as e: + if isinstance(e, exc.HTTPNotFound): + LOG.info('The stack %s was not be found during bay deletion.' % + stack_id) + else: + raise # TODO(yuanying): bay.destroy will be triggered by stack status change. bay.destroy()