summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2015-06-30 15:19:14 -0700
committerJoffrey F <f.joffrey@gmail.com>2015-06-30 15:19:14 -0700
commit2d7f1cfa1e3a93fe1aab67a64965fcbeda2fc08d (patch)
tree2eaaf7de2c703c745ab5ba6f8d8abe0f04da379f
parentac90a874be1b306c36a5bb01926ad4ddb6f347f0 (diff)
parent9e87884ba8cbddc0c7f2ad7ccdc11e172e844ac6 (diff)
downloaddocker-py-2d7f1cfa1e3a93fe1aab67a64965fcbeda2fc08d.tar.gz
Merge pull request #651 from docker/fix_647
Fix adapter bug + regression test
-rw-r--r--docker/client.py15
-rw-r--r--tests/integration_test.py9
2 files changed, 19 insertions, 5 deletions
diff --git a/docker/client.py b/docker/client.py
index 1f41c86..321989f 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -52,15 +52,16 @@ class Client(requests.Session):
base_url = utils.parse_host(base_url)
if base_url.startswith('http+unix://'):
- unix_socket_adapter = unixconn.UnixAdapter(base_url, timeout)
- self.mount('http+docker://', unix_socket_adapter)
+ self._adapter = unixconn.UnixAdapter(base_url, timeout)
+ self.mount('http+docker://', self._adapter)
self.base_url = 'http+docker://localunixsocket'
else:
# Use SSLAdapter for the ability to specify SSL version
if isinstance(tls, TLSConfig):
tls.configure_client(self)
elif tls:
- self.mount('https://', ssladapter.SSLAdapter())
+ self._adapter = ssladapter.SSLAdapter()
+ self.mount('https://', self._adapter)
self.base_url = base_url
# version detection needs to be after unix adapter mounting
@@ -243,6 +244,14 @@ class Client(requests.Session):
def api_version(self):
return self._version
+ def get_adapter(self, url):
+ try:
+ return super(Client, self).get_adapter(url)
+ except requests.exceptions.InvalidSchema as e:
+ if self._adapter:
+ return self._adapter
+ raise e
+
@check_resource
def attach(self, container, stdout=True, stderr=True,
stream=False, logs=False):
diff --git a/tests/integration_test.py b/tests/integration_test.py
index 4b9869e..ac4a871 100644
--- a/tests/integration_test.py
+++ b/tests/integration_test.py
@@ -872,8 +872,8 @@ class TestRunContainerStreaming(BaseTestCase):
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
- socket = self.client.attach_socket(container, ws=False)
- self.assertTrue(socket.fileno() > -1)
+ sock = self.client.attach_socket(container, ws=False)
+ self.assertTrue(sock.fileno() > -1)
class TestPauseUnpauseContainer(BaseTestCase):
@@ -1467,12 +1467,17 @@ class TestRegressions(BaseTestCase):
result = self.client.containers(all=True, trunc=True)
self.assertEqual(len(result[0]['Id']), 12)
+ def test_647(self):
+ with self.assertRaises(docker.errors.APIError):
+ self.client.inspect_image('gensokyo.jp//kirisame')
+
def test_649(self):
self.client.timeout = None
ctnr = self.client.create_container('busybox', ['sleep', '2'])
self.client.start(ctnr)
self.client.stop(ctnr)
+
if __name__ == '__main__':
c = docker.Client(base_url=DEFAULT_BASE_URL)
c.pull('busybox')