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

Test multiple api versions #3234

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ jobs:
strategy:
matrix:
variant: [ "integration-dind", "integration-dind-ssl", "integration-dind-ssh" ]
api-version: [1.44, 1.43, 1.42, 1.24] # 1.24 is the oldest supported version
engine-version: [25.0] # latest
include: # ugly repetition because GHA doesn't support lists in these objects so we need a separate entry for each variant
- engine-version: 23.0 # mirantis lts
api-version: 1.42
variant: "integration-dind"
- engine-version: 23.0 # mirantis lts
api-version: 1.42
variant: "integration-dind-ssl"
- engine-version: 23.0 # mirantis lts
api-version: 1.42
variant: "integration-dind-ssh"

steps:
- uses: actions/checkout@v4
- name: make ${{ matrix.variant }}
- name: ${{ matrix.variant }} - v${{ matrix.engine-version }}/v${{ matrix.api-version }}
run: |
docker logout
rm -rf ~/.docker
make ${{ matrix.variant }}
env:
TEST_ENGINE_VERSION: ${{ matrix.engine-version }}
TEST_API_VERSION: ${{ matrix.api-version }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST_API_VERSION ?= 1.43
TEST_ENGINE_VERSION ?= 24.0
TEST_API_VERSION ?= 1.44
TEST_ENGINE_VERSION ?= 25.0

ifeq ($(OS),Windows_NT)
PLATFORM := Windows
Expand Down
13 changes: 10 additions & 3 deletions tests/integration/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..helpers import ctrl_with
from ..helpers import requires_api_version, skip_if_desktop
from .base import BaseAPIIntegrationTest
from .base import TEST_IMG
from .base import TEST_IMG, TEST_API_VERSION
from docker.constants import IS_WINDOWS_PLATFORM
from docker.utils.socket import next_frame_header
from docker.utils.socket import read_exactly
Expand Down Expand Up @@ -1285,7 +1285,11 @@ def test_run_container_reading_socket_ws(self):
self.client.start(container)

data = pty_stdout.recv()
assert data.decode('utf-8') == line

if TEST_API_VERSION < "1.25":
assert data == line
else:
assert data.decode('utf-8') == line

@pytest.mark.timeout(10)
def test_attach_no_stream(self):
Expand All @@ -1294,7 +1298,10 @@ def test_attach_no_stream(self):
)
self.tmp_containers.append(container)
self.client.start(container)
self.client.wait(container, condition='not-running')
wait_kwargs = {}
if TEST_API_VERSION >= "1.30":
wait_kwargs['condition'] = 'not-running'
self.client.wait(container, **wait_kwargs)
output = self.client.attach(container, stream=False, logs=True)
assert output == 'hello\n'.encode(encoding='ascii')

Expand Down
26 changes: 14 additions & 12 deletions tests/integration/api_exec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..helpers import ctrl_with
from ..helpers import requires_api_version
from .base import BaseAPIIntegrationTest
from .base import TEST_IMG
from .base import TEST_IMG, TEST_API_VERSION
from docker.utils.proxy import ProxyConfig
from docker.utils.socket import next_frame_header
from docker.utils.socket import read_exactly
Expand Down Expand Up @@ -35,17 +35,19 @@ def test_execute_command_with_proxy_env(self):
for item in expected:
assert item in output

# Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}

res = self.client.exec_create(container, cmd=cmd, environment=env)
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=XXX', 'HTTP_PROXY=c', 'NO_PROXY=d'
]
for item in expected:
assert item in output
# Setting environment for exec is not supported in API < 1.25
if TEST_API_VERSION > "1.24":
# Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}

res = self.client.exec_create(container, cmd=cmd, environment=env)
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=XXX', 'HTTP_PROXY=c', 'NO_PROXY=d'
]
for item in expected:
assert item in output

def test_execute_command(self):
container = self.client.create_container(TEST_IMG, 'cat',
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/api_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def test_create_service_with_custom_networks(self):
{'Target': net1['Id']}, {'Target': net2['Id']}
]

@requires_api_version('1.25')
def test_create_service_with_network_attachment_config(self):
network = self.client.create_network(
'dockerpytest_1', driver='overlay', ipam={'Driver': 'default'}
Expand Down Expand Up @@ -1108,6 +1109,7 @@ def test_update_service_with_defaults_update_config(self):
assert update_config['Delay'] == uc['Delay']
assert update_config['FailureAction'] == uc['FailureAction']

@requires_api_version('1.25')
def test_update_service_with_defaults_networks(self):
net1 = self.client.create_network(
'dockerpytest_1', driver='overlay', ipam={'Driver': 'default'}
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/api_swarm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def test_init_swarm_simple(self):

@requires_api_version('1.24')
def test_init_swarm_force_new_cluster(self):
pytest.skip('Test stalls the engine on 1.12.0')

assert self.init_swarm()
version_1 = self.client.inspect_swarm()['Version']['Index']
assert self.client.init_swarm(force_new_cluster=True)
Expand Down
11 changes: 8 additions & 3 deletions tests/integration/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_run_with_network(self):
assert 'Networks' in attrs['NetworkSettings']
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]

@requires_api_version('1.32')
def test_run_with_networking_config(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand Down Expand Up @@ -132,11 +133,12 @@ def test_run_with_networking_config(self):
assert 'NetworkSettings' in attrs
assert 'Networks' in attrs['NetworkSettings']
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] == \
test_aliases
for alias in test_aliases:
assert alias in attrs['NetworkSettings']['Networks'][net_name]['Aliases']
assert attrs['NetworkSettings']['Networks'][net_name]['DriverOpts'] \
== test_driver_opt

@requires_api_version('1.32')
def test_run_with_networking_config_with_undeclared_network(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand Down Expand Up @@ -165,6 +167,7 @@ def test_run_with_networking_config_with_undeclared_network(self):
)
self.tmp_containers.append(container.id)

@requires_api_version('1.32')
def test_run_with_networking_config_only_undeclared_network(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand All @@ -190,9 +193,11 @@ def test_run_with_networking_config_only_undeclared_network(self):
assert 'NetworkSettings' in attrs
assert 'Networks' in attrs['NetworkSettings']
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] is None
assert (attrs['NetworkSettings']['Networks'][net_name]['DriverOpts']
is None)
# Aliases should include the container's short-id (but it will be removed
# in API v1.45).
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] == [attrs["Id"][:12]]

def test_run_with_none_driver(self):
client = docker.from_env(version=TEST_API_VERSION)
Expand Down
30 changes: 18 additions & 12 deletions tests/integration/models_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@ def tearDownClass(cls):
def test_create(self):
client = docker.from_env(version=TEST_API_VERSION)
name = helpers.random_name()
service = client.services.create(
create_kwargs = {
# create arguments
name=name,
labels={'foo': 'bar'},
'name': name,
'labels': {'foo': 'bar'},
# ContainerSpec arguments
image="alpine",
command="sleep 300",
container_labels={'container': 'label'},
rollback_config={'order': 'start-first'}
)
'image': "alpine",
'command': "sleep 300",
'container_labels': {'container': 'label'}
}
if TEST_API_VERSION >= "1.28":
create_kwargs['rollback_config'] = {'order': 'start-first'}

service = client.services.create(**create_kwargs)

assert service.name == name
assert service.attrs['Spec']['Labels']['foo'] == 'bar'
container_spec = service.attrs['Spec']['TaskTemplate']['ContainerSpec']
assert "alpine" in container_spec['Image']
assert container_spec['Labels'] == {'container': 'label'}
spec_rollback = service.attrs['Spec'].get('RollbackConfig', None)
assert spec_rollback is not None
assert ('Order' in spec_rollback and
spec_rollback['Order'] == 'start-first')
if TEST_API_VERSION >= "1.28":
spec_rollback = service.attrs['Spec'].get('RollbackConfig', None)
assert spec_rollback is not None
assert ('Order' in spec_rollback and
spec_rollback['Order'] == 'start-first')

@helpers.requires_api_version("1.25")
def test_create_with_network(self):
client = docker.from_env(version=TEST_API_VERSION)
name = helpers.random_name()
Expand Down
Loading