From f7ab815d14df8e3a65e628d14369ab5e5a50902f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 2 Jul 2022 22:33:23 +0200 Subject: [PATCH 1/2] Rewrite the docker_volume_info module. --- changelogs/fragments/412-docker-api.yml | 4 ++++ plugins/modules/docker_volume_info.py | 17 +++++------------ .../targets/docker_volume_info/tasks/main.yml | 5 ++--- 3 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 changelogs/fragments/412-docker-api.yml diff --git a/changelogs/fragments/412-docker-api.yml b/changelogs/fragments/412-docker-api.yml new file mode 100644 index 000000000..9e729fb72 --- /dev/null +++ b/changelogs/fragments/412-docker-api.yml @@ -0,0 +1,4 @@ +major_changes: + - "docker_volume_info - no longer uses the Docker SDK for Python. It requires ``requests`` to be installed, + and depending on the features used has some more requirements. If the Docker SDK for Python is installed, + these requirements are likely met (https://github.com/ansible-collections/community.docker/pull/412)." diff --git a/plugins/modules/docker_volume_info.py b/plugins/modules/docker_volume_info.py index 2f9993a77..4afab3ae5 100644 --- a/plugins/modules/docker_volume_info.py +++ b/plugins/modules/docker_volume_info.py @@ -23,15 +23,14 @@ - volume_name extends_documentation_fragment: -- community.docker.docker -- community.docker.docker.docker_py_1_documentation +- community.docker.docker.api_documentation author: - Felix Fontein (@felixfontein) requirements: - - "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.8.0" + - "Docker API >= 1.25" ''' EXAMPLES = ''' @@ -78,21 +77,16 @@ from ansible.module_utils.common.text.converters import to_native -try: - from docker.errors import DockerException, NotFound -except ImportError: - # missing Docker SDK for Python handled in ansible.module_utils.docker.common - pass - -from ansible_collections.community.docker.plugins.module_utils.common import ( +from ansible_collections.community.docker.plugins.module_utils.common_api import ( AnsibleDockerClient, RequestException, ) +from ansible_collections.community.docker.plugins.module_utils._api.errors import DockerException, NotFound def get_existing_volume(client, volume_name): try: - return client.inspect_volume(volume_name) + return client.get_json('/volumes/{0}', volume_name) except NotFound as dummy: return None except Exception as exc: @@ -107,7 +101,6 @@ def main(): client = AnsibleDockerClient( argument_spec=argument_spec, supports_check_mode=True, - min_docker_version='1.8.0', ) try: diff --git a/tests/integration/targets/docker_volume_info/tasks/main.yml b/tests/integration/targets/docker_volume_info/tasks/main.yml index 1ee580f89..e7007b72c 100644 --- a/tests/integration/targets/docker_volume_info/tasks/main.yml +++ b/tests/integration/targets/docker_volume_info/tasks/main.yml @@ -67,8 +67,7 @@ - "'is too new. Maximum supported API version is' in docker_volume_inspect.stderr" when: docker_volume_inspect is failed - # Requirements for docker_volume - when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.25', '>=') + when: docker_api_version is version('1.25', '>=') - fail: msg="Too old docker / docker-py version to run docker_volume_info tests!" - when: not(docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6) + when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6) From dd86a2d08a84f548f30916f341aa3d19883af0e4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 3 Jul 2022 16:32:52 +0200 Subject: [PATCH 2/2] Improve error messages. --- plugins/modules/docker_volume_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/docker_volume_info.py b/plugins/modules/docker_volume_info.py index 4afab3ae5..c60808e12 100644 --- a/plugins/modules/docker_volume_info.py +++ b/plugins/modules/docker_volume_info.py @@ -112,10 +112,10 @@ def main(): volume=volume, ) except DockerException as e: - client.fail('An unexpected docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc()) + client.fail('An unexpected Docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc()) except RequestException as e: client.fail( - 'An unexpected requests error occurred when Docker SDK for Python tried to talk to the docker daemon: {0}'.format(to_native(e)), + 'An unexpected requests error occurred when trying to talk to the Docker daemon: {0}'.format(to_native(e)), exception=traceback.format_exc())