diff --git a/Makefile b/Makefile index 79aa15e2e9..7fa5394945 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -TEST_API_VERSION ?= 1.45 -TEST_ENGINE_VERSION ?= 26.1 +TEST_API_VERSION ?= 1.48 +TEST_ENGINE_VERSION ?= 28.3 ifeq ($(OS),Windows_NT) PLATFORM := Windows @@ -11,7 +11,7 @@ ifeq ($(PLATFORM),Linux) uid_args := "--build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g)" endif -SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER ?= $(shell git describe --match '[0-9]*' --dirty='.m' --always --tags 2>/dev/null | sed -r 's/-([0-9]+)/.dev\1/' | sed 's/-/+/') +SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER ?= $(shell git describe --match '[0-9]*' --dirty='.m' --tags 2>/dev/null | sed -r 's/-([0-9]+)/.dev\1/' | sed 's/-/+/') ifeq ($(SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER),) SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER = "0.0.0.dev0" endif diff --git a/docker/api/network.py b/docker/api/network.py index 2b1925710e..7eb6e9e80e 100644 --- a/docker/api/network.py +++ b/docker/api/network.py @@ -39,8 +39,8 @@ def networks(self, names=None, ids=None, filters=None): def create_network(self, name, driver=None, options=None, ipam=None, check_duplicate=None, internal=False, labels=None, - enable_ipv6=False, attachable=None, scope=None, - ingress=None): + enable_ipv4=True, enable_ipv6=False, attachable=None, + scope=None, ingress=None): """ Create a network. Similar to the ``docker network create``. @@ -55,6 +55,7 @@ def create_network(self, name, driver=None, options=None, ipam=None, ``False``. labels (dict): Map of labels to set on the network. Default ``None``. + enable_ipv4 (bool): Enable IPv4 on the network. Default ``True``. enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``. attachable (bool): If enabled, and the network is in the global scope, non-service containers on worker nodes will be able to @@ -112,6 +113,13 @@ def create_network(self, name, driver=None, options=None, ipam=None, raise TypeError('labels must be a dictionary') data["Labels"] = labels + if not enable_ipv4: + if version_lt(self._version, '1.48'): + raise InvalidVersion( + 'enable_ipv4 was introduced in API 1.48' + ) + data['EnableIPv4'] = False + if enable_ipv6: if version_lt(self._version, '1.23'): raise InvalidVersion( diff --git a/docker/constants.py b/docker/constants.py index 0e39dc2917..f478f9ed87 100644 --- a/docker/constants.py +++ b/docker/constants.py @@ -2,7 +2,7 @@ from .version import __version__ -DEFAULT_DOCKER_API_VERSION = '1.45' +DEFAULT_DOCKER_API_VERSION = '1.48' MINIMUM_DOCKER_API_VERSION = '1.24' DEFAULT_TIMEOUT_SECONDS = 60 STREAM_HEADER_SIZE_BYTES = 8 diff --git a/tests/Dockerfile-dind-certs b/tests/Dockerfile-dind-certs index 7b819eb154..5432c371a4 100644 --- a/tests/Dockerfile-dind-certs +++ b/tests/Dockerfile-dind-certs @@ -8,8 +8,7 @@ VOLUME /certs WORKDIR /tmp/certs RUN openssl genrsa -aes256 -passout pass:foobar -out ca-key.pem 4096 -RUN echo "[req]\nprompt=no\ndistinguished_name = req_distinguished_name\n[req_distinguished_name]\ncountryName=AU" > /tmp/config -RUN openssl req -new -x509 -passin pass:foobar -config /tmp/config -days 365 -key ca-key.pem -sha256 -out ca.pem +RUN openssl req -new -x509 -passin pass:foobar -extensions v3_ca -subj '/CN=DockerTest Root CA/C=AU' -days 365 -key ca-key.pem -sha256 -out ca.pem RUN openssl genrsa -out server-key.pem -passout pass:foobar 4096 RUN openssl req -subj "/CN=docker" -sha256 -new -key server-key.pem -out server.csr RUN echo subjectAltName = DNS:docker,DNS:localhost > extfile.cnf diff --git a/tests/integration/api_network_test.py b/tests/integration/api_network_test.py index ce2e8ea4c3..2826d24714 100644 --- a/tests/integration/api_network_test.py +++ b/tests/integration/api_network_test.py @@ -447,6 +447,15 @@ def test_create_network_with_labels_wrong_type(self): with pytest.raises(TypeError): self.create_network(labels=['com.docker.py.test=label', ]) + @requires_api_version('1.48') + def test_create_network_ipv4_disabled(self): + _, net_id = self.create_network( + driver='macvlan', + enable_ipv4=False + ) + net = self.client.inspect_network(net_id) + assert net['EnableIPv4'] is False + @requires_api_version('1.23') def test_create_network_ipv6_enabled(self): _, net_id = self.create_network( diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py index b2e5237a2a..1c4dda756a 100644 --- a/tests/unit/api_container_test.py +++ b/tests/unit/api_container_test.py @@ -1302,7 +1302,7 @@ def test_log_since_with_float(self): def test_log_since_with_datetime(self): ts = 809222400 - time = datetime.datetime.utcfromtimestamp(ts) + time = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc) with mock.patch('docker.api.client.APIClient.inspect_container', fake_inspect_container): self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False, diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py index 3ce127b346..7e3e95178a 100644 --- a/tests/unit/api_test.py +++ b/tests/unit/api_test.py @@ -231,7 +231,7 @@ def test_events(self): def test_events_with_since_until(self): ts = 1356048000 - now = datetime.datetime.utcfromtimestamp(ts) + now = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc) since = now - datetime.timedelta(seconds=10) until = now + datetime.timedelta(seconds=10) diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py index 03e53cc648..f4a43e44e1 100644 --- a/tests/unit/fake_api.py +++ b/tests/unit/fake_api.py @@ -460,6 +460,7 @@ def get_fake_network_list(): "Id": FAKE_NETWORK_ID, "Scope": "local", "Driver": "bridge", + "EnableIPv4": True, "EnableIPv6": False, "Internal": False, "IPAM": {