|
| 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) |
0 commit comments