From 4d9b85c975696b516f7c15719447c3a410021541 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 8 Oct 2023 18:16:27 +0200 Subject: [PATCH] Update vendored Docker SDK for Python code (#694) * vendored Docker SDK for Python code: volume: added support for bind propagation https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation Cherry-picked from https://github.com/docker/docker-py/commit/bea63224e028226085c85caecace6480fe0aa6b0 Co-authored-by: Janne Jakob Fleischer Co-authored-by: Milas Bowman * vendored Docker SDK for Python code: fix: eventlet compatibility Check if poll attribute exists on select module instead of win32 platform check The implementation done in #2865 is breaking usage of docker-py library within eventlet. As per the Python `select.poll` documentation (https://docs.python.org/3/library/select.html#select.poll) and eventlet select removal advice (eventlet/eventlet#608 (comment)), it is preferable to use an implementation based on the availability of the `poll()` method that trying to check if the platform is `win32`. Fixes https://github.com/docker/docker-py/issues/3131 Cherry-picked from https://github.com/docker/docker-py/commit/78439ebbe1aae77ff0fd9b666894d80807182e28 Co-authored-by: Mathieu Virbel * vendored Docker SDK for Python code: fix: use response.text to get string rather than bytes Adjusted from https://github.com/docker/docker-py/commit/0618951093bf3116af482c6dfb983219c5684343 Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Co-authored-by: Milas Bowman * vendored Docker SDK for Python code: Fix missing asserts or assignments Cherry-picked from https://github.com/docker/docker-py/commit/0566f1260cd6f89588df2128ec4e86e8266e5d74 Co-authored-by: Aarni Koskela --------- Co-authored-by: Janne Jakob Fleischer Co-authored-by: Milas Bowman Co-authored-by: Mathieu Virbel Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Co-authored-by: Aarni Koskela --- plugins/module_utils/_api/errors.py | 3 ++- plugins/module_utils/_api/utils/socket.py | 3 +-- plugins/module_utils/_api/utils/utils.py | 16 ++++++++++++++++ .../plugins/module_utils/_api/api/test_client.py | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/_api/errors.py b/plugins/module_utils/_api/errors.py index 90dd5aad..47c284d3 100644 --- a/plugins/module_utils/_api/errors.py +++ b/plugins/module_utils/_api/errors.py @@ -12,6 +12,7 @@ __metaclass__ = type from ._import_helper import HTTPError as _HTTPError +from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.six import raise_from @@ -32,7 +33,7 @@ def create_api_error_from_http_exception(e): try: explanation = response.json()['message'] except ValueError: - explanation = (response.content or '').strip() + explanation = to_native((response.content or '').strip()) cls = APIError if response.status_code == 404: if explanation and ('No such image' in str(explanation) or diff --git a/plugins/module_utils/_api/utils/socket.py b/plugins/module_utils/_api/utils/socket.py index 9193ce30..792aa0cb 100644 --- a/plugins/module_utils/_api/utils/socket.py +++ b/plugins/module_utils/_api/utils/socket.py @@ -15,7 +15,6 @@ import os import select import socket as pysocket import struct -import sys from ansible.module_utils.six import PY3, binary_type @@ -43,7 +42,7 @@ def read(socket, n=4096): recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK) if PY3 and not isinstance(socket, NpipeSocket): - if sys.platform == 'win32': + if not hasattr(select, "poll"): # Limited to 1024 select.select([socket], [], []) else: diff --git a/plugins/module_utils/_api/utils/utils.py b/plugins/module_utils/_api/utils/utils.py index 910b0dc3..db3718d4 100644 --- a/plugins/module_utils/_api/utils/utils.py +++ b/plugins/module_utils/_api/utils/utils.py @@ -160,6 +160,22 @@ def convert_volume_binds(binds): else: mode = 'rw' + # NOTE: this is only relevant for Linux hosts + # (doesn't apply in Docker Desktop) + propagation_modes = [ + 'rshared', + 'shared', + 'rslave', + 'slave', + 'rprivate', + 'private', + ] + if 'propagation' in v and v['propagation'] in propagation_modes: + if mode: + mode = ','.join([mode, v['propagation']]) + else: + mode = v['propagation'] + result.append( text_type('{0}:{1}:{2}').format(k, bind, mode) ) diff --git a/tests/unit/plugins/module_utils/_api/api/test_client.py b/tests/unit/plugins/module_utils/_api/api/test_client.py index ea003565..57040b63 100644 --- a/tests/unit/plugins/module_utils/_api/api/test_client.py +++ b/tests/unit/plugins/module_utils/_api/api/test_client.py @@ -619,7 +619,7 @@ class TCPSocketStreamTest(unittest.TestCase): def test_read_from_socket_no_stream_no_tty(self): res = self.request(stream=False, tty=False, demux=False) - res == self.stdout_data + self.stderr_data + assert res == self.stdout_data + self.stderr_data def test_read_from_socket_no_stream_no_tty_demux(self): res = self.request(stream=False, tty=False, demux=True)