Commit Graph

53 Commits

Author SHA1 Message Date
Felix Fontein
892e9d9cbd Reorganize imports due to https://github.com/ansible-community/antsibull-nox/pull/136. 2025-10-10 21:19:28 +02:00
Felix Fontein
e8ec22d3b1
Python code modernization, 3/n (#1157)
* Remove __metaclass__ = type.

for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do
  sed -e '/^__metaclass__ = type/d' -i $i;
done

* Remove super arguments, and stop inheriting from object.
2025-10-10 08:11:58 +02:00
Felix Fontein
741c318b1d
Python code modernization, 2/n (#1156)
* Adjust all __future__ imports:

for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do
  sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i;
done

* Remove all UTF-8 encoding specifications for Python source files:

for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do
  sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i;
done

* Reformat.
2025-10-09 20:46:48 +02:00
Felix Fontein
a3efa26e2e
Address some pylint issues (#1155)
* Address cyclic-import.

* Address redefined-builtin.

* Address redefined-argument-from-local.

* Address many redefined-outer-name.

* Address pointless-string-statement.

* No longer needed due to separate bugfix.

* Address useless-return.

* Address possibly-used-before-assignment.

* Add TODOs.

* Address super-init-not-called.

* Address function-redefined.

* Address unspecified-encoding.

* Clean up more imports.
2025-10-09 20:11:36 +02:00
Felix Fontein
acf18f0ade
Add more CI checks (#1150)
* Enable mypy.

* Add flake8.

* Add pylint with a long list of ignores to be removed.
2025-10-07 19:37:16 +02:00
Felix Fontein
117271579e
Make all doc fragments, module utils, and plugin utils private (#1144)
* Make all doc fragments, module utils, and plugin utils private.

* Remove some unused and no longer needed imports.

This hopefully also fixes the CI issues, which do not happen locally for me...

* Fix formatting.

* Try to make CI happy, again.

* Fix imports.

* Lint.
2025-10-07 07:32:33 +02:00
Felix Fontein
d65d37e9e9 Reformat code with black and isort. 2025-10-06 18:34:59 +02:00
Felix Fontein
f45232635c
Python code modernization, 1/n (#1141)
* Remove unicode text prefixes.

* Replace str.format() uses with f-strings.

* Replace % with f-strings, and do some cleanup.

* Fix wrong variable.

* Avoid unnecessary string conversion.
2025-10-06 18:30:54 +02:00
Felix Fontein
1f2817fa20
Prepare 5.0.0 (#1123)
* Bump version to 5.0.0-a1.

* Drop support for ansible-core 2.15 and 2.16.

* Remove Python 2 and early Python 3 compatibility.
2025-10-05 20:22:50 +02:00
Felix Fontein
ebe42308cc
Replace ansible.module_utils.six with own module utils in some cases (#1138)
* Replace ansible.module_utils.six with own module utils in some cases.

* Add ignore.txt entires.
2025-10-04 23:45:27 +02:00
Felix Fontein
1902e0fdf2
Avoid six in plugin code. (#1137) 2025-10-04 21:51:59 +02:00
Felix Fontein
ad989c1942
docker_container_copy_into: add mode_parse option (#1074)
* Add mode_parse option.

* Make yamllint config strict.

* Lint.
2025-04-28 20:46:11 +02:00
Felix Fontein
a1e9412bed
Use new tools from community.internal_test_tools. (#1061) 2025-03-22 11:59:27 +01:00
Felix Fontein
9730b2a3c3
Use shared unit test utils from community.internal_test_tools. (#1056) 2025-03-12 21:39:05 +01:00
Felix Fontein
fdb97428a3
Fix/improve tests (#1052)
* Improve unit test condition.

* Improve/fix tests.
2025-03-08 09:54:41 +01:00
Felix Fontein
3b6068e44b
Add docker_context_info module (#1039)
* Vendor parts of the Docker SDK for Python

This is a combination of the latest git version
(db7f8b8bb6)
with some fixes to make it compatible with Python 2.7
and adjusting some imports.

* Polishing.

* Fix bug that prevents contexts to be found when no Docker config file is present.

Ref: https://github.com/docker/docker-py/issues/3190

* Linting.

* Fix typos.

* Adjust more to behavior of Docker CLI.

* Add first iteration of docker_context_info module.

* Improvements.

* Add basic CI.

* Add caveat on contexts[].config result.
2025-02-10 21:59:05 +01:00
Felix Fontein
bcd6e57450
Vendored Docker SDK for Python code: remove unused constants (#1037)
* Remove constants that are never used.

* Adjust unit tests.
2025-02-01 23:14:19 +01:00
Felix Fontein
8616e7f6f2
docker_image_build: work around strange behavior of docker buildx build when --output is provided (#1006)
* Work around strange behavior of docker buildx build when --output is provided.

* Adjust tests.

* Allow to pass multiple image names; correctly quote --output values.

* Return executed command.

* Adjust tests.
2024-12-14 21:32:33 +01:00
Felix Fontein
a740cfa0c4
Add more tests. (#980) 2024-10-19 22:07:06 +02:00
x4e-jonas
d8cefc4190
Fix typo in Docker connection tests. (#964)
Co-authored-by: x4e-jonas <x4e-jonas@users.noreply.github.com>
2024-09-09 15:28:17 +02:00
Felix Fontein
3cc27ecd65
Handle yet another random unstructured error output. (#949) 2024-08-07 15:58:23 +02:00
Felix Fontein
48c0cdf2c5
Imporve parsing of skipped messages. (#916) 2024-07-06 21:10:39 +02:00
Felix Fontein
2eb2c9febf
Add test for unsafe plugin util. (#856) 2024-05-12 01:00:50 +02:00
Felix Fontein
8ad45286a3
Remove unused code that relies on functionality deprecated in Python 3.12. (#834) 2024-04-15 11:21:46 +00:00
Felix Fontein
6aea7efed9
Improve parsing of warnings and errors (#811)
* Add logfmt message parser.

* Parse logfmt formatted warnings.

* Follow-up for #810.

* Fix handling of warning and error messages.

* Make Python 2 compatible.

* Linting. Improving tests.
2024-03-03 13:38:55 +00:00
Felix Fontein
7b554082ea
Improve parsing. (#786) 2024-02-01 17:52:31 +00:00
Felix Fontein
b5d085bb88
Parse build events from stderr. (#779) 2024-01-25 06:40:32 +01:00
Felix Fontein
f429017d94
Add inventory filter capability (#698)
* Add inventory filter capability.

* Use community.library_inventory_filtering_v1 collection.

* Bump dependency to 1.0.0.

* Mention the new dependency in the changelog.
2024-01-13 15:51:02 +01:00
Felix Fontein
97a0610f25
Docker Compose v2: extend/improve event parsing tests (#752)
* Normalize ansible-docker-test-xxx in stderr logs.

* Deduplicate.

* Add new testcases including the new module.
2024-01-13 15:49:30 +01:00
Felix Fontein
cb4dd2fed1
docker_compose_v2: move some code to module_utils (#747)
* Move some code to module_utils.

* Add unit tests.

Test cases are auto-generated from integration test logs.

* Rename ResourceEvent → Event.
2024-01-07 16:17:31 +01:00
Felix Fontein
4d9b85c975
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 bea63224e0

Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* 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 78439ebbe1

Co-authored-by: Mathieu Virbel <mat@meltingrocks.com>

* vendored Docker SDK for Python code: fix: use response.text to get string rather than bytes

Adjusted from 0618951093

Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* vendored Docker SDK for Python code: Fix missing asserts or assignments

Cherry-picked from 0566f1260c

Co-authored-by: Aarni Koskela <akx@iki.fi>

---------

Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>
Co-authored-by: Mathieu Virbel <mat@meltingrocks.com>
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Aarni Koskela <akx@iki.fi>
2023-10-08 18:16:27 +02:00
Felix Fontein
92fc542c00
Make unit tests work with Python 3.12. (#673) 2023-07-23 22:33:07 +02:00
Felix Fontein
449b91d489
Remove unnecessary test imports. (#583) 2023-02-12 20:59:51 +01:00
Felix Fontein
e198e4ab43
Add docker_container_copy_into module (#545)
* Move copying functionality to module_utils.

* Add docker_container_copy_into module.

* Use new module in other tests.

* Fix copyright and attributes.

* Improve idempotency, improve stat code.

* Document and test when a stopped container works.

* Improve owner/group detection error handling when container is stopped.

* Fix formulation.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

* Improve file comparison.

* Avoid reading whole file at once.

* Stream when fetching files from daemon.

* Fix comment.

* Use read() instead of read1().

* Stream files when copying into container.

* Linting.

* Add force parameter.

* Simplify library code.

* Linting.

* Add content and content_is_b64 options.

* Make force=false work as for copy module: only copy if the destination does not exist.

* Improve docs.

* content should be no_log.

* Implement diff mode.

* Improve error handling.

* Lint and improve.

* Set owner/group ID to avoid ID lookup (which fails in paused containers).

* Apply suggestions from code review

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
2023-01-09 11:52:29 +01:00
iamjpotts
166d485216
Make image archive/save idempotent, using image id and repo tags as keys (#500) 2022-11-30 23:45:36 +01:00
Felix Fontein
ae708a7333
Vendored Docker SDK for Python updates (#434)
* utils: fix IPv6 address w/ port parsing

This was using a deprecated function (`urllib.splitnport`),
ostensibly to work around issues with brackets on IPv6 addresses.

Ironically, its usage was broken, and would result in mangled IPv6
addresses if they had a port specified in some instances.

Usage of the deprecated function has been eliminated and extra test
cases added where missing. All existing cases pass as-is. (The only
other change to the test was to improve assertion messages.)

Cherry-picked from
f16c4e1147

Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* client: fix exception semantics in _raise_for_status

We want "The above exception was the direct cause of the following exception:" instead of "During handling of the above exception, another exception occurred:"

Cherry-picked from
bb11197ee3

Co-authored-by: Maor Kleinberger <kmaork@gmail.com>

* tls: use auto-negotiated highest version

Specific TLS versions are deprecated in latest Python, which
causes test failures due to treating deprecation errors as
warnings.

Luckily, the fix here is straightforward: we can eliminate some
custom version selection logic by using `PROTOCOL_TLS_CLIENT`,
which is the recommended method and will select the highest TLS
version supported by both client and server.

Cherry-picked from
56dd6de7df

Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* transport: fix ProxyCommand for SSH conn

Cherry-picked from
4e19cc48df

Co-authored-by: Guy Lichtman <glicht@users.noreply.github.com>

* ssh: do not create unnecessary subshell on exec

Cherry-picked from
bb40ba051f

Co-authored-by: liubo <liubo@uniontech.com>

* ssh: reject unknown host keys when using Python SSH impl

In the Secure Shell (SSH) protocol, host keys are used to verify the identity of remote hosts. Accepting unknown host keys may leave the connection open to man-in-the-middle attacks.

Do not accept unknown host keys. In particular, do not set the default missing host key policy for the Paramiko library to either AutoAddPolicy or WarningPolicy. Both of these policies continue even when the host key is unknown. The default setting of RejectPolicy is secure because it throws an exception when it encounters an unknown host key.

Reference: https://cwe.mitre.org/data/definitions/295.html

NOTE: This only affects SSH connections using the native Python SSH implementation (Paramiko), when `use_ssh_client=False` (default). If using the system SSH client (`use_ssh_client=True`), the host configuration
(e.g. `~/.ssh/config`) will apply.

Cherry-picked from
d9298647d9

Co-authored-by: Audun Nes <audun.nes@gmail.com>

* lint: fix deprecation warnings from threading package

Set `daemon` attribute instead of using `setDaemon` method that
was deprecated in Python 3.10.

Cherry-picked from
adf5a97b12

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>

* api: preserve cause when re-raising error

Use `from e` to ensure that the error context is propagated
correctly.

Cherry-picked from
05e143429e

Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* build: trim trailing whitespace from dockerignore entries

Cherry-picked from
3ee3a2486f

Co-authored-by: Clément Loiselet <clement.loiselet@capgemini.com>

* Improve formulation, also mention the security change as a breaking change.

Co-authored-by: Milas Bowman <milas.bowman@docker.com>
Co-authored-by: Maor Kleinberger <kmaork@gmail.com>
Co-authored-by: Guy Lichtman <glicht@users.noreply.github.com>
Co-authored-by: liubo <liubo@uniontech.com>
Co-authored-by: Audun Nes <audun.nes@gmail.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Clément Loiselet <clement.loiselet@capgemini.com>
2022-07-31 17:09:18 +02:00
Maxwell G
a33e51e04a
Prefer unitest.mock by universally using compat.mock (#433)
* Prefer unitest.mock by using compat.mock

`mock` is a backport of the `unittest.mock` module from the stdlib, and
there's no reason to use it on newer Python versions. `mock` is deprecated
in Fedora, so I figured I'd propose this here before downstream patching
our ansible-collection-community-docker package.

* Remove compat.mock code for older Python 3 versions

This removes compatibility for older versions of Python 3 that are no
longer supported.
2022-07-31 16:39:31 +02:00
Felix Fontein
a4539a309e
Move licenses to LICENSES/, use SPDX-License-Identifier, mention all licenses in galaxy.yml (#430)
* Move licenses to LICENSES/, use SPDX-License-Identifier, mention all licenses in galaxy.yml.

* ignore.txt lines cannot be empty or contain only a comment.

* Cleanup.

* This particular __init__.py seems to be crucial.

* Try extra newline.

* Markdown comments are a real mess. I hope this won't break Galaxy...

* More licenses.

* Add sanity test.

* Skip some files, lint.

* Make sure there is a copyright line everywhere.

* Also check for copyright line in sanity tests.

* Remove colon after 'Copyright'.

* Normalize lint script.

* Avoid colon after 'Copyright' in lint script.

* Improve license checker.

* Update README.md

Co-authored-by: Maxwell G <9920591+gotmax23@users.noreply.github.com>

* Remove superfluous space.

* Referencing target instead of symlink

Co-authored-by: Maxwell G <9920591+gotmax23@users.noreply.github.com>
2022-07-20 07:45:33 +02:00
Felix Fontein
77e63e2cca
Rewrite docker_container to use Docker API directly (#422)
* Begin experiments for docker_container rewrite.

* Continued.

* We support API >= 1.25 only anyway.

* Continued.

* Fix bugs.

* Complete first basic implementation.

* Continuing.

* Improvements and fixes.

* Continuing.

* More 'easy' options.

* More options.

* Work on volumes and mounts.

* Add more options.

* The last option.

* Copy over.

* Fix exposed ports.

* Fix bugs.

* Fix command and entrypoint.

* More fixes.

* Fix more bugs.

* ci_complete

* Lint, fix Python 2.7 bugs, work around ansible-test bug.

ci_complete

* Remove no longer applicable test.

ci_complete

* Remove unnecessary ignore.

ci_complete

* Start with engine driver.

* Refactoring.

* Avoid using anything Docker specific from self.client.

* Refactor.

* Add Python 2.6 ignore.txt entries for ansible-core < 2.12.

* Improve healthcheck handling.

* Fix container removal logic.

* ci_complete

* Remove handling of older Docker SDK for Pyhon versions from integration tests.

* Avoid recreation if a pure update is possible without losing the diff data.

* Cover the case that blkio_weight does not work.

* Update plugins/module_utils/module_container/docker_api.py

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

* Improve memory_swap tests.

* Fix URLs in changelog fragment.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
2022-07-15 07:24:14 +02:00
Felix Fontein
23a90668c9
Rewrite the docker_containers inventory plugin (#413)
* Rewrite the docker_containers inventory plugin.

* Improve error messages.
2022-07-06 21:48:32 +02:00
Felix Fontein
6869eaf869
Rewrite the docker_volume module (#411)
* Rewrite the docker_volume module.

* Improve error messages.
2022-07-06 21:48:16 +02:00
Felix Fontein
4d508b4c37
Vendor API connection code from Docker SDK for Python (#398)
* Vendor parts of the Docker SDK for Python

This is a combination of the latest git version
(a48a5a9647)
and the version before Python 2.7 support was removed
(650aad3a5f),
including some modifications to work with Ansible module_utils's
system (i.e. third-party imports are guarded, and errors are
reported during runtime through a new exception
MissingRequirementException).

* Create module_utils and plugin_utils for working with the vendored code.

The delete call cannot be called delete() since that method already exists from requests.

* Vendor more code from Docker SDK for Python.

* Adjust code from common module_utils.

* Add unit tests from Docker SDK for Python.

* Make test compile with Python 2.6, but skip them on Python 2.6.

* Skip test that requires a network server.

* Add changelog.

* Update changelogs/fragments/398-docker-api.yml

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

* Minimum API version is 1.25.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
2022-07-02 16:40:44 +02:00
Felix Fontein
f41d7ac1b8
Move common utility code to plugins.module_utils.util (#390)
* Move common utility code to plugins.module_utils.util.

* Also adjust plugins.

* Fix import.
2022-06-20 18:39:13 +02:00
Brian Coca
6679eee41e
docker connection: handle version and docker_args (#327)
* handle version and docker_args

* Remove breaking change.

* Add changelog fragment.

* Fix unit tests.

Co-authored-by: Felix Fontein <felix@fontein.de>
2022-04-25 20:35:33 +02:00
Brian Coca
37a3264042
docker connection plugin: fix config docs and update to use config system (#297)
* fix config docs and update to use config system

 wean off play_context which did not have the correct data in all cases

* moar fixes

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* updated for backwards compat

* badmergeresolution

* makeitworks

* attempt to fix unit test

* mocking it# No more than 50 chars. #### 50 chars is here: #

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/connection/docker.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* nomock

* remove bad paste

* properly load connection to initialize config

* initizlie docker args

* Fix bugs.

* Call _set_conn_data() when needed.

* Cache result of _get_docker_remote_user() now that it is called multiple times per task.

* Fix unit tests.

* list.clear() is Python 3...

* Add changelog.

* Call _set_conn_data() also in _connect().

Co-authored-by: Felix Fontein <felix@fontein.de>
2022-03-21 19:19:14 +01:00
Felix Fontein
1cdf8d5620
Forgot one change in #164. (#166) 2021-06-27 21:21:01 +02:00
Felix Fontein
2d5875a397 Revert "Remove superfluous file."
This reverts commit d3d8f33ec5.
2021-06-26 14:27:58 +02:00
Felix Fontein
d3d8f33ec5 Remove superfluous file. 2021-06-26 13:51:08 +02:00
Felix Fontein
9b131399ce
Docker inventory plugin (#61)
* Began with docker inventory plugin.

* Linting.

* Improve plugin, add basic unit tests.

* Linting.

* Add integration test.

* Adjust tests to case that there are more containers.

* There can be stopped containers.

ci_coverage

* docker -> docker_containers
2020-12-30 08:44:24 +01:00
Felix Fontein
6555a5a0de Initial cleanup. 2020-10-30 07:05:51 +01:00