mirror of https://github.com/docker/docker-py.git
Update DockerClient.images.pull to always stream response
Also raise a warning when users attempt to specify the "stream" parameter Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
a74d546864
commit
c53423f118
|
@ -1,5 +1,6 @@
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
|
import warnings
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -425,8 +426,21 @@ class ImageCollection(Collection):
|
||||||
if not tag:
|
if not tag:
|
||||||
repository, tag = parse_repository_tag(repository)
|
repository, tag = parse_repository_tag(repository)
|
||||||
|
|
||||||
kwargs['stream'] = False
|
if 'stream' in kwargs:
|
||||||
self.client.api.pull(repository, tag=tag, **kwargs)
|
warnings.warn(
|
||||||
|
'`stream` is not a valid parameter for this method'
|
||||||
|
' and will be overridden'
|
||||||
|
)
|
||||||
|
del kwargs['stream']
|
||||||
|
|
||||||
|
pull_log = self.client.api.pull(
|
||||||
|
repository, tag=tag, stream=True, **kwargs
|
||||||
|
)
|
||||||
|
for _ in pull_log:
|
||||||
|
# We don't do anything with the logs, but we need
|
||||||
|
# to keep the connection alive and wait for the image
|
||||||
|
# to be pulled.
|
||||||
|
pass
|
||||||
if tag:
|
if tag:
|
||||||
return self.get('{0}{2}{1}'.format(
|
return self.get('{0}{2}{1}'.format(
|
||||||
repository, tag, '@' if tag.startswith('sha256:') else ':'
|
repository, tag, '@' if tag.startswith('sha256:') else ':'
|
||||||
|
|
|
@ -232,8 +232,9 @@ class ContainerCollectionTest(unittest.TestCase):
|
||||||
container = client.containers.run('alpine', 'sleep 300', detach=True)
|
container = client.containers.run('alpine', 'sleep 300', detach=True)
|
||||||
|
|
||||||
assert container.id == FAKE_CONTAINER_ID
|
assert container.id == FAKE_CONTAINER_ID
|
||||||
client.api.pull.assert_called_with('alpine', platform=None, tag=None,
|
client.api.pull.assert_called_with(
|
||||||
stream=False)
|
'alpine', platform=None, tag=None, stream=True
|
||||||
|
)
|
||||||
|
|
||||||
def test_run_with_error(self):
|
def test_run_with_error(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import unittest
|
||||||
|
import warnings
|
||||||
|
|
||||||
from docker.constants import DEFAULT_DATA_CHUNK_SIZE
|
from docker.constants import DEFAULT_DATA_CHUNK_SIZE
|
||||||
from docker.models.images import Image
|
from docker.models.images import Image
|
||||||
import unittest
|
|
||||||
|
|
||||||
from .fake_api import FAKE_IMAGE_ID
|
from .fake_api import FAKE_IMAGE_ID
|
||||||
from .fake_api_client import make_fake_client
|
from .fake_api_client import make_fake_client
|
||||||
|
@ -43,8 +45,9 @@ class ImageCollectionTest(unittest.TestCase):
|
||||||
def test_pull(self):
|
def test_pull(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
image = client.images.pull('test_image:latest')
|
image = client.images.pull('test_image:latest')
|
||||||
client.api.pull.assert_called_with('test_image', tag='latest',
|
client.api.pull.assert_called_with(
|
||||||
stream=False)
|
'test_image', tag='latest', stream=True
|
||||||
|
)
|
||||||
client.api.inspect_image.assert_called_with('test_image:latest')
|
client.api.inspect_image.assert_called_with('test_image:latest')
|
||||||
assert isinstance(image, Image)
|
assert isinstance(image, Image)
|
||||||
assert image.id == FAKE_IMAGE_ID
|
assert image.id == FAKE_IMAGE_ID
|
||||||
|
@ -52,8 +55,9 @@ class ImageCollectionTest(unittest.TestCase):
|
||||||
def test_pull_multiple(self):
|
def test_pull_multiple(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
images = client.images.pull('test_image')
|
images = client.images.pull('test_image')
|
||||||
client.api.pull.assert_called_with('test_image', tag=None,
|
client.api.pull.assert_called_with(
|
||||||
stream=False)
|
'test_image', tag=None, stream=True
|
||||||
|
)
|
||||||
client.api.images.assert_called_with(
|
client.api.images.assert_called_with(
|
||||||
all=False, name='test_image', filters=None
|
all=False, name='test_image', filters=None
|
||||||
)
|
)
|
||||||
|
@ -63,6 +67,16 @@ class ImageCollectionTest(unittest.TestCase):
|
||||||
assert isinstance(image, Image)
|
assert isinstance(image, Image)
|
||||||
assert image.id == FAKE_IMAGE_ID
|
assert image.id == FAKE_IMAGE_ID
|
||||||
|
|
||||||
|
def test_pull_with_stream_param(self):
|
||||||
|
client = make_fake_client()
|
||||||
|
with warnings.catch_warnings(record=True) as w:
|
||||||
|
client.images.pull('test_image', stream=True)
|
||||||
|
|
||||||
|
assert len(w) == 1
|
||||||
|
assert str(w[0].message).startswith(
|
||||||
|
'`stream` is not a valid parameter'
|
||||||
|
)
|
||||||
|
|
||||||
def test_push(self):
|
def test_push(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
client.images.push('foobar', insecure_registry=True)
|
client.images.push('foobar', insecure_registry=True)
|
||||||
|
|
Loading…
Reference in New Issue