New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add max_pool_size parameter to api/client.py #2480
Conversation
Please sign your commits following these rules: $ git clone -b "master" git@github.com:tcaiazzi/docker-py.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354325856
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I agree with the change, it shouldn't break backward compatibility.
It would be nice to have some tests to make sure that the APIClient argument is changing the urllib pool size, also.
edit: Thanks for your time to make this PR. 👍
docker/client.py
Outdated
ssl_version (int): A valid `SSL version`_. | ||
assert_hostname (bool): Verify the hostname of the server. | ||
environment (dict): The environment to read environment variables | ||
from. Default: the value of ``os.environ`` | ||
credstore_env (dict): Override environment variables when calling | ||
the credential store process. | ||
max_pool_size (int): number of connections for pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This argument is duplicated.
docker/transport/npipeconn.py
Outdated
super(NpipeHTTPConnectionPool, self).__init__( | ||
'localhost', timeout=timeout, maxsize=maxsize | ||
'localhost', timeout=timeout, maxsize=max_pool_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change will break backward compatibility.
docker/transport/sshconn.py
Outdated
super(SSHConnectionPool, self).__init__( | ||
'localhost', timeout=timeout, maxsize=maxsize | ||
'localhost', timeout=timeout, maxsize=max_pool_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change also breaks backward compatibility.
docker/transport/unixconn.py
Outdated
@@ -56,9 +56,9 @@ def response_class(self, sock, *args, **kwargs): | |||
|
|||
|
|||
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool): | |||
def __init__(self, base_url, socket_path, timeout=60, maxsize=10): | |||
def __init__(self, base_url, socket_path, timeout=60, max_pool_size=10): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That breaks backward compatibility also.
Hi @feliperuhland, I've fixed what you reported in the previous comment. My colleague @tcaiazzi erroneously renamed a parameter in *ConnectionPool classes. However, we don't know how to automatically test if the pool size changes accordingly (we tested it manually on our computers). If you have any ideas, report them here and we'll be happy to build the tests. |
Hi @Skazzino. Thank you for the changes. About the tests, Also, the commit must be signed #2480 (comment) |
Hi @feliperuhland, I think that this one is really similar to what we want to test (since I can create an APIClient instance with a desired pool size). In other case, I don't have any idea of how mock the urllib3 and inject it into the APIClient. Thanks for your patience. |
Hi @Skazzino IMHO, those tests should be a unit test, like this one. If you need help, let me know. |
Hi @feliperuhland, I was able to read the actual value from each EDIT: We need to run Thanks. |
Hi @Skazzino My mock idea was not to need a docker daemon. Something like: @mock.patch("docker.transport.unixconn.UnixHTTPConnectionPool")
def test_default_pool_size(self, mock_obj):
client = docker.DockerClient()
client.ping()
base_url = "{base_url}/v{version}/_ping".format(base_url=client.api.base_url, version=client.api._version)
timeout = 60
docker_sock = "/var/run/docker.sock"
mock_obj.assert_called_once_with(base_url, docker_sock, timeout, maxsize=10) EDIT: the mock class should be one of the |
Hi @feliperuhland,
Hope we can find a way to make it work! :) |
Hi @feliperuhland, Thanks. |
Hi @Skazzino, I'll take a look today. Sorry about the delay. |
Hi @Skazzino
Sorry again for the delay. I hope that helps and if you need anything, let me know. |
Hi @feliperuhland,
Ok.
Okay, I'll add them to the tests (accordingly to what I'm mocking)
Yes, I agree with you. But if I run the unit tests (like the example you wrote before), I get the following stack trace, since the mocked response isn't an integer and I cannot access to the response from the Client:
|
Hi @Skazzino Is this branch up to date? |
Hi @feliperuhland, |
Hi @Skazzino The first thing I noticed was the need to mock mock_obj.return_value.urlopen.return_value.status = 200 Another thing that I saw was the mock_obj.assert_called_once_with(base_url, "/var/run/docker.sock", 60, maxsize=DEFAULT_MAX_POOL_SIZE) I hope that could help. |
Hi @feliperuhland, Thanks. |
Hi @Skazzino It seems related to dependencies installation:
|
Also, it's essential to rebase from master to be sure that everything is up to date. :) |
Hi @feliperuhland, It seems to be a Python2.7 related issue. How we should proceed? EDIT: From Jenkins another error occured in
Still not related with my code. Tried to run the same test on my host and it works. What's going on? Thanks. |
Hi @feliperuhland, |
Hi @feliperuhland, |
Hi @Skazzino Cloud you update de branch again, please? I push into another branch, and all the tests passed. Thanks Edit: #2516 |
Hi @feliperuhland, Hope everything is okay now, tell me if you need something else. Thanks for all the help in these months. |
Hi @Skazzino |
Hi @feliperuhland, |
Hi @Skazzino You can use If you are not confortable with git command line, you can create another branch to execute the commands. |
These tests started failing on recent versions of the engine because the error string changed, and due to a regression, the status code for one endpoint changed from a 400 to a 500. On Docker 18.03: The `docker build` case properly returns a 400, and "invalid platform" as error string; ```bash docker build --platform=foobar -<<EOF FROM busybox EOF Sending build context to Docker daemon 2.048kB Error response from daemon: invalid platform: invalid platform os "foobar" ``` ``` DEBU[2019-07-15T12:17:22.745511870Z] Calling GET /_ping DEBU[2019-07-15T12:17:22.748224796Z] Calling POST /session DEBU[2019-07-15T12:17:22.748692282Z] Calling POST /v1.37/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&platform=foobar&rm=1&session=d7b6ceba9d8d0aed67a805528554feb5285781fe888a4bf4e0c15cb09bffd614&shmsize=0&target=&ulimits=null ``` The `docker pull --platform=foobar hello-world:latest` case incorrectly returns a 500 ``` DEBU[2019-07-15T12:16:08.744827612Z] Calling POST /v1.37/images/create?fromImage=hello-world&platform=foobar&tag=latest DEBU[2019-07-15T12:16:08.745594874Z] FIXME: Got an API for which error does not match any expected type!!!: invalid platform: invalid platform os "foobar" error_type="*errors.errorString" module=api ERRO[2019-07-15T12:16:08.745916686Z] Handler for POST /v1.37/images/create returned error: invalid platform: invalid platform os "foobar" DEBU[2019-07-15T12:16:08.746191172Z] FIXME: Got an API for which error does not match any expected type!!!: invalid platform: invalid platform os "foobar" error_type="*errors.errorString" module=api ``` On Docker 18.09; ```bash docker build --platform=foobar -<<EOF FROM busybox EOF Error response from daemon: "foobar": unknown operating system or architecture: invalid argument ``` Which incorrectly returns a 500 status; ``` DEBU[2019-07-15T11:59:20.687268380Z] Calling POST /v1.39/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&platform=foobar&rm=1&session=jko7kejjvs93judyfnq7shoda&shmsize=0&target=&ulimits=null&version=1 DEBU[2019-07-15T11:59:20.687282279Z] Calling POST /session INFO[2019-07-15T11:59:20.687761392Z] parsed scheme: "" module=grpc INFO[2019-07-15T11:59:20.687833668Z] scheme "" not registered, fallback to default scheme module=grpc INFO[2019-07-15T11:59:20.688017578Z] ccResolverWrapper: sending new addresses to cc: [{ 0 <nil>}] module=grpc INFO[2019-07-15T11:59:20.688270160Z] ClientConn switching balancer to "pick_first" module=grpc INFO[2019-07-15T11:59:20.688353083Z] pickfirstBalancer: HandleSubConnStateChange: 0xc4209b0630, CONNECTING module=grpc INFO[2019-07-15T11:59:20.688985698Z] pickfirstBalancer: HandleSubConnStateChange: 0xc4209b0630, READY module=grpc DEBU[2019-07-15T11:59:20.812700550Z] client is session enabled DEBU[2019-07-15T11:59:20.813139288Z] FIXME: Got an API for which error does not match any expected type!!!: invalid argument github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs.init /go/src/github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs/errors.go:40 github.com/docker/docker/vendor/github.com/containerd/containerd/content.init <autogenerated>:1 github.com/docker/docker/builder/builder-next.init <autogenerated>:1 github.com/docker/docker/api/server/backend/build.init <autogenerated>:1 main.init <autogenerated>:1 runtime.main /usr/local/go/src/runtime/proc.go:186 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:2361 error_type="*errors.fundamental" module=api ERRO[2019-07-15T11:59:20.813210677Z] Handler for POST /v1.39/build returned error: "foobar": unknown operating system or architecture: invalid argument DEBU[2019-07-15T11:59:20.813276737Z] FIXME: Got an API for which error does not match any expected type!!!: invalid argument github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs.init /go/src/github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs/errors.go:40 github.com/docker/docker/vendor/github.com/containerd/containerd/content.init <autogenerated>:1 github.com/docker/docker/builder/builder-next.init <autogenerated>:1 github.com/docker/docker/api/server/backend/build.init <autogenerated>:1 main.init <autogenerated>:1 runtime.main /usr/local/go/src/runtime/proc.go:186 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:2361 error_type="*errors.fundamental" module=api ``` Same for the `docker pull --platform=foobar hello-world:latest` case: ```bash docker pull --platform=foobar hello-world:latest Error response from daemon: "foobar": unknown operating system or architecture: invalid argument ``` ``` DEBU[2019-07-15T12:00:18.812995330Z] Calling POST /v1.39/images/create?fromImage=hello-world&platform=foobar&tag=latest DEBU[2019-07-15T12:00:18.813229172Z] FIXME: Got an API for which error does not match any expected type!!!: invalid argument github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs.init /go/src/github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs/errors.go:40 github.com/docker/docker/vendor/github.com/containerd/containerd/content.init <autogenerated>:1 github.com/docker/docker/builder/builder-next.init <autogenerated>:1 github.com/docker/docker/api/server/backend/build.init <autogenerated>:1 main.init <autogenerated>:1 runtime.main /usr/local/go/src/runtime/proc.go:186 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:2361 error_type="*errors.fundamental" module=api ERRO[2019-07-15T12:00:18.813365546Z] Handler for POST /v1.39/images/create returned error: "foobar": unknown operating system or architecture: invalid argument DEBU[2019-07-15T12:00:18.813461428Z] FIXME: Got an API for which error does not match any expected type!!!: invalid argument github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs.init /go/src/github.com/docker/docker/vendor/github.com/containerd/containerd/errdefs/errors.go:40 github.com/docker/docker/vendor/github.com/containerd/containerd/content.init <autogenerated>:1 github.com/docker/docker/builder/builder-next.init <autogenerated>:1 github.com/docker/docker/api/server/backend/build.init <autogenerated>:1 main.init <autogenerated>:1 runtime.main /usr/local/go/src/runtime/proc.go:186 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:2361 error_type="*errors.fundamental" module=api ``` Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Pytest 4.3.1 includes the fix from pytest-dev/pytest#4795 which should fix the following failure: > INFO: Building docker-sdk-python3:4.0.2... > sha256:c7a40413c985b6e75df324fae39b1c30cb78a25df71b7892f1a4a15449537fb3 > INFO: Starting docker-py tests... > Traceback (most recent call last): > File "/usr/local/bin/pytest", line 10, in <module> > sys.exit(main()) > File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 61, in main > config = _prepareconfig(args, plugins) > File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 182, in _prepareconfig > config = get_config() > File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 156, in get_config > pluginmanager.import_plugin(spec) > File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 530, in import_plugin > __import__(importspec) > File "/usr/local/lib/python3.6/site-packages/_pytest/tmpdir.py", line 25, in <module> > class TempPathFactory(object): > File "/usr/local/lib/python3.6/site-packages/_pytest/tmpdir.py", line 35, in TempPathFactory > lambda p: Path(os.path.abspath(six.text_type(p))) > TypeError: attrib() got an unexpected keyword argument 'convert' > Sending interrupt signal to process > Terminated > script returned exit code 143 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Till Riedel <riedel@teco.edu> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Till Riedel <riedel@teco.edu> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Till Riedel <riedel@teco.edu> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Renlong Tu <rentu@microsoft.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Tommaso Caiazzi <tommasocaiazzi@gmail.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Christopher Crone <christopher.crone@docker.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Christopher Crone <christopher.crone@docker.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
The ImageCollectionTest.test_pull_multiple test performs a `docker pull` without a `:tag` specified) to pull all tags of the given repository (image). After pulling the image, the image(s) pulled are checked to verify if the list of images contains the `:latest` tag. However, the test assumes that all tags of the image are tags for the same version of the image (same digest), and thus a *single* image is returned, which is not always the case. Currently, the `hello-world:latest` and `hello-world:linux` tags point to a different digest, therefore the `client.images.pull()` returns multiple images: one image for digest, making the test fail: =================================== FAILURES =================================== ____________________ ImageCollectionTest.test_pull_multiple ____________________ tests/integration/models_images_test.py:90: in test_pull_multiple assert len(images) == 1 E AssertionError: assert 2 == 1 E + where 2 = len([<Image: 'hello-world:linux'>, <Image: 'hello-world:latest'>]) This patch updates the test to not assume a single image is returned, and instead loop through the list of images and check if any of the images contains the `:latest` tag. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Signed-off-by: Anca Iordache <anca.iordache@docker.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
- Changelog - Next Version Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com> Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Hi @feliperuhland, |
The bot should approve the signature check |
Hi @feliperuhland, |
Hi @Skazzino My suggestion is to clean the past commits and sign those that are going to stay. |
Hi, |
As requested in #2477, it is now possible to choose the number of connections for each urllib3 pool.