From 31330416043bacb220569d1eed38182cd034492a Mon Sep 17 00:00:00 2001 From: Bharath Thiruveedula Date: Wed, 24 Aug 2016 00:11:27 +0530 Subject: [PATCH] Raise 409 exception while deleting running container Change-Id: I597cbd473e204dd244e95e4814bf650437b540c9 Closes-Bug: #1614384 --- zun/common/exception.py | 6 ++++++ zun/compute/manager.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/zun/common/exception.py b/zun/common/exception.py index 4cf341ccc..90c950be3 100644 --- a/zun/common/exception.py +++ b/zun/common/exception.py @@ -339,3 +339,9 @@ class ContainerNotFound(HTTPNotFound): class ContainerAlreadyExists(ResourceExists): message = _("A container with UUID %(uuid)s already exists.") + + +class ContainerRunningException(ZunException): + message = _("The container %(id)s is running." + "Please stop and delete the container.") + code = 409 diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 7f97948e8..53ec1aa18 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -72,6 +72,9 @@ class Manager(object): return container except Exception as e: LOG.exception(_LE("Unexpected exception: %s"), str(e)) + if e.response.status_code == 409: + raise exception.ContainerRunningException( + id=container.container_id) raise e @translate_exception