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

Implement all remaining deprecations for 3.0.0 #400

Merged
merged 6 commits into from
Jul 2, 2022
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
92 changes: 4 additions & 88 deletions .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,6 @@ stages:
test: '2.11/sanity/1'
- name: Units
test: '2.11/units/1'
- stage: Ansible_2_10
displayName: Sanity & Units 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
targets:
- name: Sanity
test: '2.10/sanity/1'
- name: Units
test: '2.10/units/1'
- stage: Ansible_2_9
displayName: Sanity & Units 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
targets:
- name: Sanity
test: '2.9/sanity/1'
- name: Units
test: '2.9/units/1'

### Docker
- stage: Docker_devel
Expand Down Expand Up @@ -168,6 +146,8 @@ stages:
parameters:
testFormat: 2.12/linux/{0}
targets:
- name: Fedora 33
test: fedora33
- name: Fedora 34
test: fedora34
- name: Ubuntu 18.04
Expand All @@ -182,39 +162,11 @@ stages:
- template: templates/matrix.yml
parameters:
testFormat: 2.11/linux/{0}
targets:
- name: Fedora 33
test: fedora33
- name: Alpine 3
test: alpine3
groups:
- 4
- 5
- stage: Docker_2_10
displayName: Docker 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.10/linux/{0}
targets:
- name: Fedora 32
test: fedora32
- name: Ubuntu 16.04
test: ubuntu1604
groups:
- 4
- 5
- stage: Docker_2_9
displayName: Docker 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.9/linux/{0}
targets:
- name: Fedora 31
test: fedora31
- name: Alpine 3
test: alpine3
groups:
- 4
- 5
Expand Down Expand Up @@ -304,36 +256,6 @@ stages:
- 3
- 4
- 5
- stage: Remote_2_10
displayName: Remote 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: RHEL {0}
testFormat: 2.10/rhel/{0}
targets:
- test: '7.8'
groups:
- 1
- 2
- 3
- 4
- stage: Remote_2_9
displayName: Remote 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: RHEL {0}
testFormat: 2.9/rhel/{0}
targets:
- test: '8.2'
groups:
- 1
- 2
- 3
- 4

## Finally

Expand All @@ -344,20 +266,14 @@ stages:
- Ansible_2_13
- Ansible_2_12
- Ansible_2_11
- Ansible_2_10
- Ansible_2_9
- Remote_devel
- Remote_2_13
- Remote_2_12
- Remote_2_11
- Remote_2_10
- Remote_2_9
- Docker_devel
- Docker_2_13
- Docker_2_12
- Docker_2_11
- Docker_2_10
- Docker_2_9
- Docker_community_devel
jobs:
- template: templates/coverage.yml
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ Please note that this collection does **not** support Windows targets. The conne

## Tested with Ansible

Tested with the current Ansible 2.9, ansible-base 2.10, ansible-core 2.11, ansible-core 2.12 and ansible-core 2.13 releases and the current development version of ansible-core. Ansible versions before 2.9.10 are not supported.
Tested with the current ansible-core 2.11, ansible-core 2.12, and ansible-core 2.13 releases, and the current development version of ansible-core. Ansible/ansible-base versions before 2.11.0 are not supported.

Please note that support for Ansible 2.9 and ansible-base 2.10 has been deprecated and will be dropped from community.docker 3.0.0 on.

This collection does not work with ansible-core before 2.12 (this includes ansible-base and Ansible 2.9) on Python 2.12+.
Please note that Ansible 2.9 and ansible-base 2.10 are no longer supported. If you need to use them, use community.docker 2.x.y. Also note that this collection does not work with ansible-core 2.11 (this includes ansible-base and Ansible 2.9) on Python 2.12+.

## External requirements

Most modules and plugins require the [Docker SDK for Python](https://pypi.org/project/docker/). For Python 2.6 support, use [the deprecated docker-py library](https://pypi.org/project/docker-py/) instead.

Please note that Python 2.6 support has been deprecated and will be dropped from community.docker 3.0.0 on.
Most modules and plugins require the [Docker SDK for Python](https://pypi.org/project/docker/) and Python 2.7 or newer. Python 2.6 is no longer supported; use community.docker 2.x.y if you need to use Python 2.6.

Both libraries cannot be installed at the same time. If you accidentally did install them simultaneously, you have to uninstall *both* before re-installing one of them.
If you have Docker SDK for Python < 2.0.0 installed ([docker-py](https://pypi.org/project/docker-py/)), you can still use it, though we recommend to uninstall it and then install [docker](https://pypi.org/project/docker/), the Docker SDK for Python >= 2.0.0. Note that both libraries cannot be installed at the same time. If you accidentally did install them simultaneously, you have to uninstall *both* before re-installing one of them.

## Included content

Expand Down
5 changes: 5 additions & 0 deletions changelogs/fragments/400-deprecations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
removed_features:
- Support for Ansible 2.9 and ansible-base 2.10 has been removed. If you need support for Ansible 2.9 or ansible-base 2.10, please use community.docker 2.x.y (https://github.com/ansible-collections/community.docker/pull/400).
- Execution Environments built with community.docker no longer include docker-compose < 2.0.0. If you need to use it with the ``docker_compose`` module, please install that requirement manually (https://github.com/ansible-collections/community.docker/pull/400).
- Support for Python 2.6 has been removed. If you need support for Python 2.6, please use community.docker 2.x.y (https://github.com/ansible-collections/community.docker/pull/400).
- Support for Docker API versions 1.20 to 1.24 has been removed. If you need support for these API versions, please use community.docker 2.x.y (https://github.com/ansible-collections/community.docker/pull/400).
12 changes: 2 additions & 10 deletions docs/docsite/rst/scenario_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ For Python 2.7, you need to use a version between 2.0.0 and 4.4.4 since the Pyth

$ pip install 'docker==4.4.4'

For Python 2.6, you need a version before 2.0.0. For these versions, the SDK was called ``docker-py``, so you need to install it as follows:

.. code-block:: bash

$ pip install 'docker-py>=1.10.0'

Please install only one of ``docker`` or ``docker-py``. Installing both will result in a broken installation. If this happens, Ansible will detect it and inform you about it. If that happens, you must uninstall both and reinstall the correct version.

If in doubt, always install ``docker`` and never ``docker-py``.
Note that the Docker SDK for Python was called ``docker-py`` on PyPi before version 2.0.0. Please avoid installing this really old version, and make sure to not install both ``docker`` and ``docker-py``. Installing both will result in a broken installation. If this happens, Ansible will detect it and inform you about it. If that happens, you must uninstall both and reinstall the correct version. If in doubt, always install ``docker`` and never ``docker-py``.


Connecting to the Docker API
Expand Down Expand Up @@ -94,7 +86,7 @@ For plugins, they have to be set for the environment Ansible itself runs in. For

DOCKER_API_VERSION
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported
by docker-py.
by Docker SDK for Python.

DOCKER_TIMEOUT
The maximum amount of time in seconds to wait on a response from the API.
Expand Down
1 change: 0 additions & 1 deletion meta/ee-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
docker
docker-compose
requests
paramiko

Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
requires_ansible: '>=2.9.10'
requires_ansible: '>=2.11.0'
action_groups:
docker:
- docker_compose
Expand Down
6 changes: 3 additions & 3 deletions plugins/connection/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _call_client(self, callable, not_found_can_be_resource=False):
)
except RequestException as e:
self.client.fail(
'An unexpected requests error occurred for container "{1}" when docker-py tried to talk to the docker daemon: {0}'
'An unexpected requests error occurred for container "{1}" when Docker SDK for Python tried to talk to the docker daemon: {0}'
.format(e, self.get_option('remote_addr'))
)

Expand Down Expand Up @@ -298,8 +298,8 @@ def put_file(self, in_path, out_path):
bio = io.BytesIO()
with tarfile.open(fileobj=bio, mode='w|', dereference=True, encoding='utf-8') as tar:
# Note that without both name (bytes) and arcname (unicode), this either fails for
# Python 2.6/2.7, Python 3.5/3.6, or Python 3.7+. Only when passing both (in this
# form) it works with Python 2.6, 2.7, 3.5, 3.6, and 3.7 up to 3.9.
# Python 2.7, Python 3.5/3.6, or Python 3.7+. Only when passing both (in this
# form) it works with Python 2.7, 3.5, 3.6, and 3.7 up to 3.11
tarinfo = tar.gettarinfo(b_in_path, arcname=to_text(out_file))
user_id, group_id = self.ids[self.actual_user]
tarinfo.uid = user_id
Expand Down
10 changes: 4 additions & 6 deletions plugins/doc_fragments/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,10 @@ class ModuleDocFragment(object):
requirements:
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/)
Python module has been superseded by L(docker,https://pypi.org/project/docker/)
(see L(here,https://github.com/docker/docker-py/issues/1310) for details).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should *not*
be installed at the same time. Also note that when both modules are installed
and one of them is uninstalled, the other might no longer function and a
reinstall of it is required."
(see L(here,https://github.com/docker/docker-py/issues/1310) for details). Note that both
modules should *not* be installed at the same time. Also note that when both modules are
installed and one of them is uninstalled, the other might no longer function and a reinstall
of it is required."
'''

# Additional, more specific stuff for minimal Docker SDK for Python version >= 2.0.
Expand Down
2 changes: 1 addition & 1 deletion plugins/inventory/docker_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,5 @@ def parse(self, inventory, loader, path, cache=True):
)
except RequestException as e:
raise AnsibleError(
'An unexpected requests error occurred when docker-py tried to talk to the docker daemon: {0}'.format(e)
'An unexpected requests error occurred when Docker SDK for Python tried to talk to the docker daemon: {0}'.format(e)
)
2 changes: 1 addition & 1 deletion plugins/inventory/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
api_version:
description:
- The version of the Docker API running on the Docker Host.
- Defaults to the latest version of the API supported by docker-py.
- Defaults to the latest version of the API supported by Docker SDK for Python.
type: str
aliases: [ docker_api_version ]
timeout:
Expand Down
36 changes: 14 additions & 22 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
try:
from requests.exceptions import RequestException
except ImportError:
# Either docker-py is no longer using requests, or docker-py isn't around either,
# or docker-py's dependency requests is missing. In any case, define an exception
# Either Docker SDK for Python is no longer using requests, or Docker SDK for Python isn't around either,
# or Docker SDK for Python's dependency requests is missing. In any case, define an exception
# class RequestException so that our code doesn't break.
class RequestException(Exception):
pass
Expand Down Expand Up @@ -180,9 +180,7 @@ def get_connect_params(auth, fail_function):

DOCKERPYUPGRADE_SWITCH_TO_DOCKER = "Try `pip uninstall docker-py` followed by `pip install docker`."
DOCKERPYUPGRADE_UPGRADE_DOCKER = "Use `pip install --upgrade docker` to upgrade."
DOCKERPYUPGRADE_RECOMMEND_DOCKER = ("Use `pip install --upgrade docker-py` to upgrade. "
"Hint: if you do not need Python 2.6 support, try "
"`pip uninstall docker-py` instead, followed by `pip install docker`.")
DOCKERPYUPGRADE_RECOMMEND_DOCKER = "Use `pip install --upgrade docker-py` to upgrade."


class AnsibleDockerClientBase(Client):
Expand All @@ -197,28 +195,22 @@ def __init__(self, min_docker_version=None, min_docker_api_version=None):
self.fail("Cannot have both the docker-py and docker python modules (old and new version of Docker "
"SDK for Python) installed together as they use the same namespace and cause a corrupt "
"installation. Please uninstall both packages, and re-install only the docker-py or docker "
"python module (for %s's Python %s). It is recommended to install the docker module if no "
"support for Python 2.6 is required. Please note that simply uninstalling one of the modules "
"can leave the other module in a broken state." % (platform.node(), sys.executable))
"python module (for %s's Python %s). It is recommended to install the docker module. Please "
"note that simply uninstalling one of the modules can leave the other module in a broken "
"state." % (platform.node(), sys.executable))

if not HAS_DOCKER_PY:
if NEEDS_DOCKER_PY2:
msg = missing_required_lib("Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or "
"docker before 5.0.0 (Python 2.7)")
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or " \
+ "`pip install docker==4.4.4` (Python 2.7). The error was: %s"
else:
msg = missing_required_lib("Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or "
"docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)")
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) " \
+ "or `pip install docker-py` (Python 2.6). The error was: %s"
msg = missing_required_lib("Docker SDK for Python: docker>=5.0.0 (Python >= 3.6) or "
"docker<5.0.0 (Python 2.7)")
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or " \
+ "`pip install docker==4.4.4` (Python 2.7). The error was: %s"
self.fail(msg % HAS_DOCKER_ERROR, exception=HAS_DOCKER_TRACEBACK)

if self.docker_py_version < LooseVersion(min_docker_version):
msg = "Error: Docker SDK for Python version is %s (%s's Python %s). Minimum version required is %s."
if not NEEDS_DOCKER_PY2:
# The minimal required version is < 2.0 (and the current version as well).
# Advertise docker (instead of docker-py) for non-Python-2.6 users.
# Advertise docker (instead of docker-py).
msg += DOCKERPYUPGRADE_RECOMMEND_DOCKER
elif docker_version < LooseVersion('2.0'):
msg += DOCKERPYUPGRADE_SWITCH_TO_DOCKER
Expand All @@ -237,9 +229,9 @@ def __init__(self, min_docker_version=None, min_docker_api_version=None):
self.fail("Error connecting: %s" % exc)

self.docker_api_version = LooseVersion(self.docker_api_version_str)
if min_docker_api_version is not None:
if self.docker_api_version < LooseVersion(min_docker_api_version):
self.fail('Docker API version is %s. Minimum version required is %s.' % (self.docker_api_version_str, min_docker_api_version))
min_docker_api_version = min_docker_api_version or '1.25'
if self.docker_api_version < LooseVersion(min_docker_api_version):
self.fail('Docker API version is %s. Minimum version required is %s.' % (self.docker_api_version_str, min_docker_api_version))

def log(self, msg, pretty_print=False):
pass
Expand Down
24 changes: 1 addition & 23 deletions plugins/module_utils/socket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _write(self):

def select(self, timeout=None, _internal_recursion=False):
if not _internal_recursion and self._paramiko_read_workaround and len(self._write_buffer) > 0:
# When the SSH transport is used, docker-py internally uses Paramiko, whose
# When the SSH transport is used, Docker SDK for Python internally uses Paramiko, whose
# Channel object supports select(), but only for reading
# (https://github.com/paramiko/paramiko/issues/695).
if self._sock.send_ready():
Expand Down Expand Up @@ -208,25 +208,3 @@ def write(self, str):
class DockerSocketHandlerModule(DockerSocketHandlerBase):
def __init__(self, sock, module, selectors):
super(DockerSocketHandlerModule, self).__init__(sock, selectors, module.debug)


def find_selectors(module):
try:
# ansible-base 2.10+ has selectors a compat version of selectors, which a bundled fallback:
from ansible.module_utils.compat import selectors
return selectors
except ImportError:
pass
try:
# Python 3.4+
import selectors
return selectors
except ImportError:
pass
try:
# backport package installed in the system
import selectors2
return selectors2
except ImportError:
pass
module.fail_json(msg=missing_required_lib('selectors2', reason='for handling stdin'))
7 changes: 3 additions & 4 deletions plugins/modules/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@


requirements:
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.8.0 (use L(docker-py,https://pypi.org/project/docker-py/) for Python 2.6)"
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.8.0"
- "docker-compose >= 1.7.0, < 2.0.0"
- "Docker API >= 1.20"
- "Docker API >= 1.25"
- "PyYAML >= 3.11"
'''

Expand Down Expand Up @@ -1194,7 +1194,6 @@ def main():
argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True,
min_docker_api_version='1.20',
)

try:
Expand All @@ -1204,7 +1203,7 @@ def main():
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-py tried to talk to the docker daemon: {0}'.format(to_native(e)),
'An unexpected requests error occurred when Docker SDK for Python tried to talk to the docker daemon: {0}'.format(to_native(e)),
exception=traceback.format_exc())


Expand Down
Loading