diff options
author | Lars Kellogg-Stedman <lars@redhat.com> | 2015-07-16 15:25:39 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2015-07-18 22:43:46 -0400 |
commit | 7a727a7a43fd0bdb7069deba379aa9b4677378ef (patch) | |
tree | d1e0d7bbdd801f5299aab6667e917e17b4011e0a | |
parent | 9b95541b5577530d055da5751a96aaedb937656c (diff) | |
download | ansible-modules-core-7a727a7a43fd0bdb7069deba379aa9b4677378ef.tar.gz |
Do not erroneously mask exceptions
There was a catch-all `except` statement in `create_containers`:
try:
containers = do_create(count, params)
except:
self.pull_image()
containers = do_create(count, params)
This would mask a variety of errors that should be exposed, including
API compatability errors (as in #1707) and common Python exceptions (KeyError, ValueError, etc) that could result from errors in the code.
This change makes the `except` statement more specific, and only attempts to pull the image and start a container if the original create attempt failed due to a 404 error from the docker API.
-rw-r--r-- | cloud/docker/docker.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index 76ca1222..b1679968 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -361,6 +361,7 @@ from urlparse import urlparse try: import docker.client import docker.utils + import docker.errors from requests.exceptions import RequestException except ImportError: HAS_DOCKER_PY = False @@ -1222,7 +1223,10 @@ class DockerManager(object): try: containers = do_create(count, params) - except: + except docker.errors.APIError as e: + if e.response.status_code != 404: + raise + self.pull_image() containers = do_create(count, params) |