mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
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.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
@@ -22,16 +22,12 @@ import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from ansible.module_utils import six
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from socketserver import ThreadingTCPServer
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api import constants, errors
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.api.client import APIClient
|
||||
from ansible_collections.community.docker.tests.unit.plugins.module_utils._api.constants import DEFAULT_DOCKER_API_VERSION
|
||||
@@ -52,7 +48,7 @@ def response(status_code=200, content='', headers=None, reason=None, elapsed=0,
|
||||
request=None, raw=None):
|
||||
res = requests.Response()
|
||||
res.status_code = status_code
|
||||
if not isinstance(content, six.binary_type):
|
||||
if not isinstance(content, bytes):
|
||||
content = json.dumps(content).encode('ascii')
|
||||
res._content = content
|
||||
res.headers = requests.structures.CaseInsensitiveDict(headers or {})
|
||||
@@ -103,7 +99,7 @@ def fake_delete(self, url, *args, **kwargs):
|
||||
|
||||
|
||||
def fake_read_from_socket(self, response, stream, tty=False, demux=False):
|
||||
return six.binary_type()
|
||||
return b""
|
||||
|
||||
|
||||
url_base = '{prefix}/'.format(prefix=fake_api.prefix)
|
||||
@@ -202,13 +198,13 @@ class DockerApiTest(BaseAPIClientTest):
|
||||
|
||||
def test_retrieve_server_version(self):
|
||||
client = APIClient(version="auto")
|
||||
assert isinstance(client._version, six.string_types)
|
||||
assert isinstance(client._version, str)
|
||||
assert not (client._version == "auto")
|
||||
client.close()
|
||||
|
||||
def test_auto_retrieve_server_version(self):
|
||||
version = self.client._retrieve_server_version()
|
||||
assert isinstance(version, six.string_types)
|
||||
assert isinstance(version, str)
|
||||
|
||||
def test_info(self):
|
||||
self.client.info()
|
||||
@@ -296,9 +292,7 @@ class DockerApiTest(BaseAPIClientTest):
|
||||
|
||||
def test_stream_helper_decoding(self):
|
||||
status_code, content = fake_api.fake_responses[url_prefix + 'events']()
|
||||
content_str = json.dumps(content)
|
||||
if six.PY3:
|
||||
content_str = content_str.encode('utf-8')
|
||||
content_str = json.dumps(content).encode('utf-8')
|
||||
body = io.BytesIO(content_str)
|
||||
|
||||
# mock a stream interface
|
||||
@@ -465,8 +459,7 @@ class TCPSocketStreamTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.server = six.moves.socketserver.ThreadingTCPServer(
|
||||
('', 0), cls.get_handler_class())
|
||||
cls.server = ThreadingTCPServer(('', 0), cls.get_handler_class())
|
||||
cls.thread = threading.Thread(target=cls.server.serve_forever)
|
||||
cls.thread.daemon = True
|
||||
cls.thread.start()
|
||||
@@ -484,7 +477,7 @@ class TCPSocketStreamTest(unittest.TestCase):
|
||||
stdout_data = cls.stdout_data
|
||||
stderr_data = cls.stderr_data
|
||||
|
||||
class Handler(six.moves.BaseHTTPServer.BaseHTTPRequestHandler, object):
|
||||
class Handler(BaseHTTPRequestHandler, object):
|
||||
def do_POST(self):
|
||||
resp_data = self.get_resp_data()
|
||||
self.send_response(101)
|
||||
|
||||
@@ -18,13 +18,9 @@ import random
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api import auth, errors
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.credentials.errors import CredentialsNotFound
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.credentials.store import Store
|
||||
|
||||
@@ -11,14 +11,9 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.errors import (
|
||||
APIError, DockerException,
|
||||
create_unexpected_kwargs_error,
|
||||
|
||||
@@ -11,12 +11,6 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.transport.sshconn import SSHSocket, SSHHTTPAdapter
|
||||
|
||||
|
||||
@@ -11,13 +11,9 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.transport import ssladapter
|
||||
|
||||
HAS_MATCH_HOSTNAME = True
|
||||
|
||||
@@ -17,13 +17,9 @@ import socket
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.constants import IS_WINDOWS_PLATFORM
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.utils.build import exclude_paths, tar
|
||||
|
||||
|
||||
@@ -15,12 +15,6 @@ import unittest
|
||||
import shutil
|
||||
import tempfile
|
||||
import json
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from pytest import mark, fixture
|
||||
|
||||
|
||||
@@ -11,12 +11,6 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.api.client import APIClient
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.utils.decorators import update_headers
|
||||
|
||||
@@ -10,13 +10,6 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.utils.json_stream import json_splitter, stream_as_text, json_stream
|
||||
|
||||
|
||||
|
||||
@@ -11,13 +11,9 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.utils.ports import build_port_bindings, split_port
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,6 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.utils.proxy import ProxyConfig
|
||||
|
||||
|
||||
@@ -17,15 +17,9 @@ import os.path
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._six import PY3
|
||||
|
||||
import pytest
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
pytestmark = pytest.mark.skip('Python 2.6 is not supported')
|
||||
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.api.client import APIClient
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.constants import IS_WINDOWS_PLATFORM
|
||||
from ansible_collections.community.docker.plugins.module_utils._api.errors import DockerException
|
||||
@@ -456,11 +450,7 @@ class UtilsTest(unittest.TestCase):
|
||||
|
||||
def test_decode_json_header(self):
|
||||
obj = {'a': 'b', 'c': 1}
|
||||
data = None
|
||||
if PY3:
|
||||
data = base64.urlsafe_b64encode(bytes(json.dumps(obj), 'utf-8'))
|
||||
else:
|
||||
data = base64.urlsafe_b64encode(json.dumps(obj))
|
||||
data = base64.urlsafe_b64encode(bytes(json.dumps(obj), 'utf-8'))
|
||||
decoded_data = decode_json_header(data)
|
||||
assert obj == decoded_data
|
||||
|
||||
@@ -469,10 +459,6 @@ class SplitCommandTest(unittest.TestCase):
|
||||
def test_split_command_with_unicode(self):
|
||||
assert split_command(u'echo μμ') == ['echo', 'μμ']
|
||||
|
||||
@pytest.mark.skipif(PY3, reason="shlex doesn't support bytes in py3")
|
||||
def test_split_command_with_bytes(self):
|
||||
assert split_command('echo μμ') == ['echo', 'μμ']
|
||||
|
||||
|
||||
class FormatEnvironmentTest(unittest.TestCase):
|
||||
def test_format_env_binary_unicode_value(self):
|
||||
|
||||
@@ -13,8 +13,7 @@ from ansible_collections.community.docker.plugins.module_utils.copy import (
|
||||
|
||||
|
||||
def _simple_generator(sequence):
|
||||
for elt in sequence:
|
||||
yield elt
|
||||
yield from sequence
|
||||
|
||||
|
||||
@pytest.mark.parametrize('chunks, read_sizes', [
|
||||
|
||||
@@ -62,7 +62,7 @@ def test_archived_image_manifest_raises_when_file_not_a_tar():
|
||||
archived_image_manifest(__file__)
|
||||
raise AssertionError()
|
||||
except ImageArchiveInvalidException as e:
|
||||
assert isinstance(e.cause, tarfile.ReadError)
|
||||
assert isinstance(e.__cause__, tarfile.ReadError)
|
||||
assert str(__file__) in str(e)
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ def test_archived_image_manifest_raises_when_tar_missing_manifest(tar_file_name)
|
||||
archived_image_manifest(tar_file_name)
|
||||
raise AssertionError()
|
||||
except ImageArchiveInvalidException as e:
|
||||
assert isinstance(e.cause, KeyError)
|
||||
assert 'manifest.json' in str(e.cause)
|
||||
assert isinstance(e.__cause__, KeyError)
|
||||
assert 'manifest.json' in str(e.__cause__)
|
||||
|
||||
|
||||
def test_archived_image_manifest_raises_when_manifest_missing_id(tar_file_name):
|
||||
@@ -90,5 +90,5 @@ def test_archived_image_manifest_raises_when_manifest_missing_id(tar_file_name):
|
||||
archived_image_manifest(tar_file_name)
|
||||
raise AssertionError()
|
||||
except ImageArchiveInvalidException as e:
|
||||
assert isinstance(e.cause, KeyError)
|
||||
assert 'Config' in str(e.cause)
|
||||
assert isinstance(e.__cause__, KeyError)
|
||||
assert 'Config' in str(e.__cause__)
|
||||
|
||||
@@ -34,8 +34,7 @@ def tar_file_name(tmpdir):
|
||||
Return the name of a non-existing tar file in an existing temporary directory.
|
||||
"""
|
||||
|
||||
# Cast to str required by Python 2.x
|
||||
return str(tmpdir.join('foo.tar'))
|
||||
return tmpdir.join('foo.tar')
|
||||
|
||||
|
||||
def test_archived_image_action_when_missing(tar_file_name):
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -37,8 +37,7 @@ def write_imitation_archive(file_name, image_id, repo_tags):
|
||||
|
||||
|
||||
def write_imitation_archive_with_manifest(file_name, manifest):
|
||||
tf = tarfile.open(file_name, 'w')
|
||||
try:
|
||||
with tarfile.open(file_name, 'w') as tf:
|
||||
with TemporaryFile() as f:
|
||||
f.write(json.dumps(manifest).encode('utf-8'))
|
||||
|
||||
@@ -48,10 +47,6 @@ def write_imitation_archive_with_manifest(file_name, manifest):
|
||||
f.seek(0)
|
||||
tf.addfile(ti, f)
|
||||
|
||||
finally:
|
||||
# In Python 2.6, this does not have __exit__
|
||||
tf.close()
|
||||
|
||||
|
||||
def write_irrelevant_tar(file_name):
|
||||
'''
|
||||
|
||||
@@ -2,8 +2,4 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
unittest2 ; python_version < '2.7'
|
||||
importlib ; python_version < '2.7'
|
||||
|
||||
requests
|
||||
backports.ssl-match-hostname ; python_version < '3.5'
|
||||
|
||||
Reference in New Issue
Block a user