From 35b5e36edbf31dad8616fa0d96aad993a783c368 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Thu, 19 Oct 2017 18:48:29 +0800 Subject: [PATCH] Container action response 500 Zun action APIs (i.e. exec, top, etc.) will return 500 if Docker return 409 (Conflict). Below are observations: * Docker will validate container state before executing a specific action, and raise state conflict (409) error if the state of the container doesn't allow the action to perform. For example, 'exec' is not allowed if container is on state 'Stopped'. * Zun will do a similar state validation in zun-api. * Zun will sync the container states from Docker every 60 seconds. As a result, the state in Zun and Docker might be different during the 60 seconds interval. This 500 error happened if the state between Zun and Docker is out-of-sync (sometimes in between the 60 seconds). This makes the state validation passed in Zun but failed in Docker. Change-Id: If1db262881ac89c62d5a2e7f3cfe67a09724ef5a Closes-Bug: #1723499 --- zun/container/docker/driver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zun/container/docker/driver.py b/zun/container/docker/driver.py index 97db1bb1b..93b464a7b 100644 --- a/zun/container/docker/driver.py +++ b/zun/container/docker/driver.py @@ -42,6 +42,14 @@ def is_not_found(e): return '404' in str(e) +def is_conflict(e): + conflict_infos = ['not running', 'not paused', 'paused'] + for info in conflict_infos: + if info in str(e): + return True + return False + + def handle_not_found(e, context, container, do_not_raise=False): if container.auto_remove: container.status = consts.DELETED @@ -67,6 +75,8 @@ def wrap_docker_error(function): except exception.DockerError as e: if is_not_found(e): handle_not_found(e, context, container) + if is_conflict(e): + raise exception.Conflict(_("%s") % str(e)) raise return decorated_function