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

Update vendored Docker SDK for Python code #694

Merged
merged 4 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/module_utils/_api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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


Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions plugins/module_utils/_api/utils/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import select
import socket as pysocket
import struct
import sys

from ansible.module_utils.six import PY3, binary_type

Expand Down Expand Up @@ -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"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the specifics of what's going on here, but the conditional is quite different. Was the issue actually that select.poll was not defined on Windows platforms? If the attribute exists on Windows but did not work (or didn't work correctly for this situation) then this test would cause failures.

I guess, this code being vendored, it never will run on Windows (unless I ever get around to trying to get Ansible Python modules to execute on Windows but alas....).

Still, what was the motivation for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been cherry-picked from docker/docker-py@78439eb to support eventlet. Our code neither supports Windows (outside WSL2) nor does it support eventlet, I'd still like the socket code to be as close as possible to Docker SDK for Python's code even for features we have no need for.

# Limited to 1024
select.select([socket], [], [])
else:
Expand Down
16 changes: 16 additions & 0 deletions plugins/module_utils/_api/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/plugins/module_utils/_api/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def test_read_from_socket_no_stream_tty_demux(self):

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)
Expand Down