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
This commit is contained in:
Feng Shengqin 2017-10-19 18:48:29 +08:00 committed by feng.shengqin
parent d4883cef78
commit 35b5e36edb

View File

@ -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