diff options
author | Joffrey F <joffrey@docker.com> | 2018-01-26 14:34:20 -0800 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-01-26 14:34:20 -0800 |
commit | 8b5a52ae0ced380fbd761f891830107d8817f240 (patch) | |
tree | 8c23be396696ad8510c291313ffad5c64d572241 | |
parent | 601c5a41d2e6d281fa9917a0dd9b66dd45b8dcae (diff) | |
download | docker-py-8b5a52ae0ced380fbd761f891830107d8817f240.tar.gz |
Error handling in ImageCollection.loadhongbin-image-load
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/errors.py | 4 | ||||
-rw-r--r-- | docker/models/images.py | 5 | ||||
-rw-r--r-- | tests/integration/models_images_test.py | 5 |
3 files changed, 13 insertions, 1 deletions
diff --git a/docker/errors.py b/docker/errors.py index 50423a2..eeeac57 100644 --- a/docker/errors.py +++ b/docker/errors.py @@ -144,6 +144,10 @@ class BuildError(Exception): pass +class ImageLoadError(DockerException): + pass + + def create_unexpected_kwargs_error(name, kwargs): quoted_kwargs = ["'{}'".format(k) for k in sorted(kwargs)] text = ["{}() ".format(name)] diff --git a/docker/models/images.py b/docker/models/images.py index 4372730..dcdeac9 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -3,7 +3,7 @@ import re import six from ..api import APIClient -from ..errors import BuildError +from ..errors import BuildError, ImageLoadError from ..utils.json_stream import json_stream from .resource import Collection, Model @@ -258,6 +258,9 @@ class ImageCollection(Collection): if match: image_id = match.group(2) images.append(image_id) + if 'error' in chunk: + raise ImageLoadError(chunk['error']) + return [self.get(i) for i in images] def pull(self, name, tag=None, **kwargs): diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py index 8f812d9..8840e15 100644 --- a/tests/integration/models_images_test.py +++ b/tests/integration/models_images_test.py @@ -71,6 +71,11 @@ class ImageCollectionTest(BaseIntegrationTest): image = client.images.pull('alpine', tag='3.3') assert 'alpine:3.3' in image.attrs['RepoTags'] + def test_load_error(self): + client = docker.from_env(version=TEST_API_VERSION) + with pytest.raises(docker.errors.ImageLoadError): + client.images.load('abc') + class ImageTest(BaseIntegrationTest): |