Port docker_common.py to py3 compatible syntax (#15877)

Since docker-py depend on python 2.6 (cf their tox.ini),
we do not need to make it python 2.4 compatible.
pull/10296/head
Michael Scherer 9 years ago committed by Brian Coca
parent 97f16b7700
commit a4f6fc0dc2

@ -37,7 +37,7 @@ try:
from docker.constants import DEFAULT_TIMEOUT_SECONDS, DEFAULT_DOCKER_API_VERSION from docker.constants import DEFAULT_TIMEOUT_SECONDS, DEFAULT_DOCKER_API_VERSION
from docker.utils.types import Ulimit, LogConfig from docker.utils.types import Ulimit, LogConfig
from docker import auth from docker import auth
except ImportError, exc: except ImportError as exc:
HAS_DOCKER_ERROR = str(exc) HAS_DOCKER_ERROR = str(exc)
HAS_DOCKER_PY = False HAS_DOCKER_PY = False
@ -161,9 +161,9 @@ class AnsibleDockerClient(Client):
try: try:
super(AnsibleDockerClient, self).__init__(**self._connect_params) super(AnsibleDockerClient, self).__init__(**self._connect_params)
except APIError, exc: except APIError as exc:
self.fail("Docker API error: %s" % exc) self.fail("Docker API error: %s" % exc)
except Exception, exc: except Exception as exc:
self.fail("Error connecting: %s" % exc) self.fail("Error connecting: %s" % exc)
def log(self, msg, pretty_print=False): def log(self, msg, pretty_print=False):
@ -262,7 +262,7 @@ class AnsibleDockerClient(Client):
try: try:
tls_config = TLSConfig(**kwargs) tls_config = TLSConfig(**kwargs)
return tls_config return tls_config
except TLSParameterError, exc: except TLSParameterError as exc:
self.fail("TLS config error: %s" % exc) self.fail("TLS config error: %s" % exc)
def _get_connect_params(self): def _get_connect_params(self):
@ -372,9 +372,9 @@ class AnsibleDockerClient(Client):
if container['Id'] == name: if container['Id'] == name:
result = container result = container
break break
except SSLError, exc: except SSLError as exc:
self._handle_ssl_error(exc) self._handle_ssl_error(exc)
except Exception, exc: except Exception as exc:
self.fail("Error retrieving container list: %s" % exc) self.fail("Error retrieving container list: %s" % exc)
if result is not None: if result is not None:
@ -382,7 +382,7 @@ class AnsibleDockerClient(Client):
self.log("Inspecting container Id %s" % result['Id']) self.log("Inspecting container Id %s" % result['Id'])
result = self.inspect_container(container=result['Id']) result = self.inspect_container(container=result['Id'])
self.log("Completed container inspection") self.log("Completed container inspection")
except Exception, exc: except Exception as exc:
self.fail("Error inspecting container: %s" % exc) self.fail("Error inspecting container: %s" % exc)
return result return result
@ -411,7 +411,7 @@ class AnsibleDockerClient(Client):
if len(images) == 1: if len(images) == 1:
try: try:
inspection = self.inspect_image(images[0]['Id']) inspection = self.inspect_image(images[0]['Id'])
except Exception, exc: except Exception as exc:
self.fail("Error inspecting image %s:%s - %s" % (name, tag, str(exc))) self.fail("Error inspecting image %s:%s - %s" % (name, tag, str(exc)))
return inspection return inspection
@ -455,7 +455,7 @@ class AnsibleDockerClient(Client):
error_detail.get('message'))) error_detail.get('message')))
else: else:
self.fail("Error pulling %s - %s" % (name, line.get('error'))) self.fail("Error pulling %s - %s" % (name, line.get('error')))
except Exception, exc: except Exception as exc:
self.fail("Error pulling image %s:%s - %s" % (name, tag, str(exc))) self.fail("Error pulling image %s:%s - %s" % (name, tag, str(exc)))
return self.find_image(name, tag) return self.find_image(name, tag)

Loading…
Cancel
Save