mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
docker_container: improve race condition behavior for detach:no, auto_remove:yes behavior (#47712)
* Don't die when get_container is called for container which is terminating during get_container call. If it terminates between client.containers() and client.inspect_container(), the module will fail with an error such as Error inspecting container: 404 Client Error: Not Found ("No such container: xxx") * Add changelog.
This commit is contained in:
parent
a87a62ba8a
commit
b9706e2ff5
2 changed files with 8 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "docker_container - fixing race condition when ``detach`` and ``auto_remove`` are both ``true``."
|
|
@ -32,7 +32,7 @@ HAS_DOCKER_ERROR = None
|
||||||
try:
|
try:
|
||||||
from requests.exceptions import SSLError
|
from requests.exceptions import SSLError
|
||||||
from docker import __version__ as docker_version
|
from docker import __version__ as docker_version
|
||||||
from docker.errors import APIError, TLSParameterError
|
from docker.errors import APIError, NotFound, TLSParameterError
|
||||||
from docker.tls import TLSConfig
|
from docker.tls import TLSConfig
|
||||||
from docker import auth
|
from docker import auth
|
||||||
|
|
||||||
|
@ -112,6 +112,9 @@ if not HAS_DOCKER_PY:
|
||||||
class APIError(Exception): # noqa: F811
|
class APIError(Exception): # noqa: F811
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class NotFound(Exception): # noqa: F811
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def is_image_name_id(name):
|
def is_image_name_id(name):
|
||||||
"""Checks whether the given image name is in fact an image ID (hash)."""
|
"""Checks whether the given image name is in fact an image ID (hash)."""
|
||||||
|
@ -442,6 +445,8 @@ 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 NotFound as exc:
|
||||||
|
return None
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail("Error inspecting container: %s" % exc)
|
self.fail("Error inspecting container: %s" % exc)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue