Skip to content

Commit 7734c29

Browse files
Merge pull request #23045 from ricardobranco777/runtime_py
Add tests for docker-py & podman-py
2 parents 01d754f + ace1c14 commit 7734c29

File tree

7 files changed

+481
-0
lines changed

7 files changed

+481
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
From e47e966e944deb637a16f445abd5fc92f6dba38a Mon Sep 17 00:00:00 2001
2+
From: Sebastiaan van Stijn <[email protected]>
3+
Date: Wed, 22 May 2024 15:12:42 +0200
4+
Subject: [PATCH] Bump default API version to 1.45 (Moby 26.0/26.1)
5+
6+
- Update API version to the latest maintained release.
7+
0 Adjust tests for API 1.45
8+
9+
Signed-off-by: Sebastiaan van Stijn <[email protected]>
10+
---
11+
Makefile | 4 ++--
12+
docker/constants.py | 2 +-
13+
tests/Dockerfile-ssh-dind | 4 ++--
14+
tests/integration/models_containers_test.py | 11 +++++------
15+
4 files changed, 10 insertions(+), 11 deletions(-)
16+
17+
diff --git a/Makefile b/Makefile
18+
index 13a00f5e20..d1c07ac739 100644
19+
--- a/Makefile
20+
+++ b/Makefile
21+
@@ -1,5 +1,5 @@
22+
-TEST_API_VERSION ?= 1.44
23+
-TEST_ENGINE_VERSION ?= 25.0
24+
+TEST_API_VERSION ?= 1.45
25+
+TEST_ENGINE_VERSION ?= 26.1
26+
27+
ifeq ($(OS),Windows_NT)
28+
PLATFORM := Windows
29+
diff --git a/docker/constants.py b/docker/constants.py
30+
index 3c527b47e3..0e39dc2917 100644
31+
--- a/docker/constants.py
32+
+++ b/docker/constants.py
33+
@@ -2,7 +2,7 @@
34+
35+
from .version import __version__
36+
37+
-DEFAULT_DOCKER_API_VERSION = '1.44'
38+
+DEFAULT_DOCKER_API_VERSION = '1.45'
39+
MINIMUM_DOCKER_API_VERSION = '1.24'
40+
DEFAULT_TIMEOUT_SECONDS = 60
41+
STREAM_HEADER_SIZE_BYTES = 8
42+
diff --git a/tests/Dockerfile-ssh-dind b/tests/Dockerfile-ssh-dind
43+
index 250c20f2c8..49529f84b7 100644
44+
--- a/tests/Dockerfile-ssh-dind
45+
+++ b/tests/Dockerfile-ssh-dind
46+
@@ -1,7 +1,7 @@
47+
# syntax=docker/dockerfile:1
48+
49+
-ARG API_VERSION=1.44
50+
-ARG ENGINE_VERSION=25.0
51+
+ARG API_VERSION=1.45
52+
+ARG ENGINE_VERSION=26.1
53+
54+
FROM docker:${ENGINE_VERSION}-dind
55+
56+
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
57+
index 2cd713ec8a..8727455932 100644
58+
--- a/tests/integration/models_containers_test.py
59+
+++ b/tests/integration/models_containers_test.py
60+
@@ -131,10 +131,9 @@ def test_run_with_networking_config(self):
61+
assert 'NetworkSettings' in attrs
62+
assert 'Networks' in attrs['NetworkSettings']
63+
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
64+
- # Expect Aliases to list 'test_alias' and the container's short-id.
65+
- # In API version 1.45, the short-id will be removed.
66+
+ # Aliases no longer include the container's short-id in API v1.45.
67+
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] \
68+
- == [test_alias, attrs['Id'][:12]]
69+
+ == [test_alias]
70+
assert attrs['NetworkSettings']['Networks'][net_name]['DriverOpts'] \
71+
== test_driver_opt
72+
73+
@@ -191,9 +190,9 @@ def test_run_with_networking_config_only_undeclared_network(self):
74+
assert 'NetworkSettings' in attrs
75+
assert 'Networks' in attrs['NetworkSettings']
76+
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
77+
- # Aliases should include the container's short-id (but it will be removed
78+
- # in API v1.45).
79+
- assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] == [attrs["Id"][:12]]
80+
+ # Aliases no longer include the container's short-id in API v1.45.
81+
+ assert (attrs['NetworkSettings']['Networks'][net_name]['Aliases']
82+
+ is None)
83+
assert (attrs['NetworkSettings']['Networks'][net_name]['DriverOpts']
84+
is None)
85+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
From 96ef4d3bee53ed17bf62670837b51c73911d7455 Mon Sep 17 00:00:00 2001
2+
From: Laura Brehm <[email protected]>
3+
Date: Fri, 27 Sep 2024 13:36:48 +0100
4+
Subject: [PATCH 1/2] tests/exec: expect 127 exit code for missing executable
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
Docker Engine has always returned `126` when starting an exec fails due
10+
to a missing binary, but this was due to a bug in the daemon causing the
11+
correct exit code to be overwritten in some cases – see: https://github.com/moby/moby/issues/45795
12+
13+
Change tests to expect correct exit code (`127`).
14+
15+
Signed-off-by: Laura Brehm <[email protected]>
16+
---
17+
tests/integration/models_containers_test.py | 7 +++++--
18+
1 file changed, 5 insertions(+), 2 deletions(-)
19+
20+
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
21+
index 476263ae23..c65f3d7f88 100644
22+
--- a/tests/integration/models_containers_test.py
23+
+++ b/tests/integration/models_containers_test.py
24+
@@ -359,8 +359,11 @@ def test_exec_run_failed(self):
25+
"alpine", "sh -c 'sleep 60'", detach=True
26+
)
27+
self.tmp_containers.append(container.id)
28+
- exec_output = container.exec_run("docker ps")
29+
- assert exec_output[0] == 126
30+
+ exec_output = container.exec_run("non-existent")
31+
+ # older versions of docker return `126` in the case that an exec cannot
32+
+ # be started due to a missing executable. We're fixing this for the
33+
+ # future, so accept both for now.
34+
+ assert exec_output[0] == 127 or exec_output == 126
35+
36+
def test_kill(self):
37+
client = docker.from_env(version=TEST_API_VERSION)
38+
39+
From b1265470e64c29d8b270e43387c5abb442e084c7 Mon Sep 17 00:00:00 2001
40+
From: Laura Brehm <[email protected]>
41+
Date: Fri, 27 Sep 2024 15:05:08 +0100
42+
Subject: [PATCH 2/2] tests/exec: add test for exit code from exec
43+
44+
Execs should return the exit code of the exec'd process, if it started.
45+
46+
Signed-off-by: Laura Brehm <[email protected]>
47+
---
48+
tests/integration/models_containers_test.py | 11 ++++++++++-
49+
1 file changed, 10 insertions(+), 1 deletion(-)
50+
51+
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
52+
index c65f3d7f88..2cd713ec8a 100644
53+
--- a/tests/integration/models_containers_test.py
54+
+++ b/tests/integration/models_containers_test.py
55+
@@ -353,6 +353,15 @@ def test_exec_run_success(self):
56+
assert exec_output[0] == 0
57+
assert exec_output[1] == b"hello\n"
58+
59+
+ def test_exec_run_error_code_from_exec(self):
60+
+ client = docker.from_env(version=TEST_API_VERSION)
61+
+ container = client.containers.run(
62+
+ "alpine", "sh -c 'sleep 20'", detach=True
63+
+ )
64+
+ self.tmp_containers.append(container.id)
65+
+ exec_output = container.exec_run("sh -c 'exit 42'")
66+
+ assert exec_output[0] == 42
67+
+
68+
def test_exec_run_failed(self):
69+
client = docker.from_env(version=TEST_API_VERSION)
70+
container = client.containers.run(
71+
@@ -363,7 +372,7 @@ def test_exec_run_failed(self):
72+
# older versions of docker return `126` in the case that an exec cannot
73+
# be started due to a missing executable. We're fixing this for the
74+
# future, so accept both for now.
75+
- assert exec_output[0] == 127 or exec_output == 126
76+
+ assert exec_output[0] == 127 or exec_output[0] == 126
77+
78+
def test_kill(self):
79+
client = docker.from_env(version=TEST_API_VERSION)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 6efb722c941af7daef1f4a7e4c9c670f61e90c9b Mon Sep 17 00:00:00 2001
2+
From: Ricardo Branco <[email protected]>
3+
Date: Wed, 20 Aug 2025 21:02:52 +0200
4+
Subject: [PATCH] tests: Fix deprecation warning for utcfromtimestamp()
5+
6+
Fix DeprecationWarning for datetime.datetime.utcfromtimestamp()
7+
8+
It suggests to use timezone-aware objects to represent datetimes in UTC
9+
with datetime.UTC but datetime.timezone.utc is backwards compatible.
10+
11+
Signed-off-by: Ricardo Branco <[email protected]>
12+
---
13+
tests/unit/api_container_test.py | 2 +-
14+
tests/unit/api_test.py | 2 +-
15+
2 files changed, 2 insertions(+), 2 deletions(-)
16+
17+
diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py
18+
index b2e5237a2a..1c4dda756a 100644
19+
--- a/tests/unit/api_container_test.py
20+
+++ b/tests/unit/api_container_test.py
21+
@@ -1302,7 +1302,7 @@ def test_log_since_with_float(self):
22+
23+
def test_log_since_with_datetime(self):
24+
ts = 809222400
25+
- time = datetime.datetime.utcfromtimestamp(ts)
26+
+ time = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc)
27+
with mock.patch('docker.api.client.APIClient.inspect_container',
28+
fake_inspect_container):
29+
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False,
30+
diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py
31+
index 3ce127b346..7e3e95178a 100644
32+
--- a/tests/unit/api_test.py
33+
+++ b/tests/unit/api_test.py
34+
@@ -231,7 +231,7 @@ def test_events(self):
35+
36+
def test_events_with_since_until(self):
37+
ts = 1356048000
38+
- now = datetime.datetime.utcfromtimestamp(ts)
39+
+ now = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc)
40+
since = now - datetime.timedelta(seconds=10)
41+
until = now + datetime.timedelta(seconds=10)
42+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 74d880c4771ded8cda6dd69bb827688d56792e0b Mon Sep 17 00:00:00 2001
2+
From: Ricardo Branco <[email protected]>
3+
Date: Thu, 21 Aug 2025 21:28:09 +0200
4+
Subject: [PATCH] tests: Fix tests to reflect removal of rw as default option
5+
6+
Behaviour changed upstream with https://github.com/containers/podman/pull/25942
7+
8+
Signed-off-by: Ricardo Branco <[email protected]>
9+
---
10+
podman/tests/integration/test_container_create.py | 2 +-
11+
1 file changed, 1 insertion(+), 1 deletion(-)
12+
13+
diff --git a/podman/tests/integration/test_container_create.py b/podman/tests/integration/test_container_create.py
14+
index f098efbc..4e751163 100644
15+
--- a/podman/tests/integration/test_container_create.py
16+
+++ b/podman/tests/integration/test_container_create.py
17+
@@ -316,7 +316,7 @@ def test_container_mounts(self):
18+
self.containers.append(container)
19+
self.assertEqual(
20+
container.attrs.get('HostConfig', {}).get('Tmpfs', {}).get(mount['target']),
21+
- f"size={mount['size']},rw,rprivate,nosuid,nodev,tmpcopyup",
22+
+ f"size={mount['size']},rprivate,nosuid,nodev,tmpcopyup",
23+
)
24+
25+
container.start()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From a27a9d06a47cec4f684d7c16d14096f277d4fe30 Mon Sep 17 00:00:00 2001
2+
From: Ricardo Branco <[email protected]>
3+
Date: Sun, 24 Aug 2025 13:10:17 +0200
4+
Subject: [PATCH] tests: Fix deprecation warning for utcfromtimestamp()
5+
6+
Fix DeprecationWarning for datetime.datetime.utcfromtimestamp()
7+
8+
It suggests to use timezone-aware objects to represent datetimes in UTC
9+
with datetime.UTC but datetime.timezone.utc is backwards compatible.
10+
11+
Signed-off-by: Ricardo Branco <[email protected]>
12+
---
13+
podman/api/parse_utils.py | 6 ++++--
14+
1 file changed, 4 insertions(+), 2 deletions(-)
15+
16+
diff --git a/podman/api/parse_utils.py b/podman/api/parse_utils.py
17+
index 39e30da7..0294712d 100644
18+
--- a/podman/api/parse_utils.py
19+
+++ b/podman/api/parse_utils.py
20+
@@ -4,7 +4,7 @@
21+
import ipaddress
22+
import json
23+
import struct
24+
-from datetime import datetime
25+
+from datetime import datetime, timezone
26+
from typing import Any, Optional, Union
27+
from collections.abc import Iterator
28+
29+
@@ -48,7 +48,9 @@ def prepare_timestamp(value: Union[datetime, int, None]) -> Optional[int]:
30+
return value
31+
32+
if isinstance(value, datetime):
33+
- delta = value - datetime.utcfromtimestamp(0)
34+
+ if value.tzinfo is None:
35+
+ value = value.replace(tzinfo=timezone.utc)
36+
+ delta = value - datetime.fromtimestamp(0, timezone.utc)
37+
return delta.seconds + delta.days * 24 * 3600
38+
39+
raise ValueError(f"Type '{type(value)}' is not supported by prepare_timestamp()")

lib/main_containers.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ sub load_host_tests_podman {
183183
load_compose_tests($run_args);
184184
loadtest('containers/seccomp', run_args => $run_args, name => $run_args->{runtime} . "_seccomp") unless is_sle('<15');
185185
loadtest('containers/isolation', run_args => $run_args, name => $run_args->{runtime} . "_isolation") unless (is_public_cloud || is_transactional);
186+
unless (is_jeos || is_staging || is_transactional || !is_tumbleweed || get_var("OCI_RUNTIME")) {
187+
loadtest('containers/python_runtime', run_args => $run_args, name => "python_podman");
188+
}
186189
loadtest('containers/podmansh') if (is_tumbleweed && !is_staging && !is_transactional);
187190
}
188191

@@ -215,6 +218,9 @@ sub load_host_tests_docker {
215218
# select_user_serial_terminal is broken on public cloud
216219
loadtest 'containers/rootless_docker' unless (is_public_cloud);
217220
}
221+
unless (is_jeos || is_staging || is_transactional || !is_tumbleweed || check_var("CONTAINERS_DOCKER_FLAVOUR", "stable")) {
222+
loadtest('containers/python_runtime', run_args => $run_args, name => "python_docker");
223+
}
218224
# Expected to work anywhere except of real HW backends, PC and Micro
219225
unless (is_generalhw || is_ipmi || is_public_cloud || is_openstack || is_sle_micro || is_microos || is_leap_micro || (is_sle('=12-SP5') && is_aarch64)) {
220226
loadtest 'containers/validate_btrfs';

0 commit comments

Comments
 (0)