Skip to content
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

Autodetect Docker API version #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

skion
Copy link

@skion skion commented Jan 3, 2017

This patch avoids the following error when connecting to Docker 1.11:

>>> docker.Client().containers(all=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 85, in containers
    res = self._result(self._get(u, params=params), True)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 178, in _result
    self._raise_for_status(response)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 174, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.24, server API version: 1.23)")

@shortdudey123
Copy link
Member

Can you fix the tests?

@skion
Copy link
Author

skion commented Jan 24, 2017

I'm not sure I can, as the Travis results don't reproduce for me and I seem to have unrelated test failures locally, maybe due to Docker 1.13?

$ docker -v
Docker version 1.13.0, build 49bf474
$ coverage run --source=diamond test.py
..EE..................................................No handlers could be found for logger "bernhard"
........................................................................................................................................................................................................................................................................................................................................................................................................................................
======================================================================
ERROR: test_should_get_containers (testmemory_docker.TestMemoryDockerCollector)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/pieter/workspace/python-diamond/src/collectors/memory_docker/test/testmemory_docker.py", line 81, in test_should_get_containers
    self.collector.collect()
  File "/home/pieter/workspace/python-diamond/src/collectors/memory_docker/memory_docker.py", line 34, in collect
    for c in docker.Client(version='auto').containers(all=True)
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/docker/client.py", line 56, in __init__
    self._auth_configs = auth.load_config()
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/docker/auth/auth.py", line 253, in load_config
    with open(config_file) as f:
AttributeError: __exit__

======================================================================
ERROR: test_should_open_all_cpuacct_stat (testmemory_docker.TestMemoryDockerCollector)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/pieter/workspace/python-diamond/src/collectors/memory_docker/test/testmemory_docker.py", line 67, in test_should_open_all_cpuacct_stat
    self.collector.collect()
  File "/home/pieter/workspace/python-diamond/src/collectors/memory_docker/memory_docker.py", line 34, in collect
    for c in docker.Client(version='auto').containers(all=True)
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/docker/client.py", line 56, in __init__
    self._auth_configs = auth.load_config()
  File "/home/pieter/.virtualenvs/python-diamond/local/lib/python2.7/site-packages/docker/auth/auth.py", line 253, in load_config
    with open(config_file) as f:
AttributeError: __exit__

----------------------------------------------------------------------
Ran 478 tests in 83.823s

@shortdudey123
Copy link
Member

Probably need to fix the stubbing in the test
@patch.object(Client, 'containers', Mock(return_value=[])) and @patch.object(Client, 'containers')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants