Debian Codegraph @

tests/integration/lifetime/test_lifetime.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2
3
4 import os
5 import time
6 import unittest
7
8 from packaging import version
9 from parameterized import parameterized
10
11 from tests.integration.test_utils import RunSubprocessMixin
12 from tests.integration.test_utils import get_podman_version
13 from tests.integration.test_utils import podman_compose_path
14 from tests.integration.test_utils import test_path
15
16
17 class TestLifetime(unittest.TestCase, RunSubprocessMixin):
18 def test_up_single_container(self) -> None:
19 """Podman compose up should be able to start containers one after another"""
20
21 compose_path = os.path.join(test_path(), "lifetime/up_single_container/docker-compose.yml")
22
23 try:
24 self.run_subprocess_assert_returncode([
25 podman_compose_path(),
26 "-f",
27 compose_path,
28 "up",
29 "-d",
30 "container1",
31 ])
32
33 self.run_subprocess_assert_returncode([
34 podman_compose_path(),
35 "-f",
36 compose_path,
37 "up",
38 "-d",
39 "container2",
40 ])
41
42 out, _ = self.run_subprocess_assert_returncode([
43 podman_compose_path(),
44 "-f",
45 compose_path,
46 "logs",
47 "--no-log-prefix",
48 "--no-color",
49 "container1",
50 ])
51
52 self.assertEqual(out, b"test1\n")
53
54 out, _ = self.run_subprocess_assert_returncode([
55 podman_compose_path(),
56 "-f",
57 compose_path,
58 "logs",
59 "--no-log-prefix",
60 "--no-color",
61 "container2",
62 ])
63
64 self.assertEqual(out, b"test2\n")
65
66 finally:
67 out, _ = self.run_subprocess_assert_returncode([
68 podman_compose_path(),
69 "-f",
70 compose_path,
71 "down",
72 ])
73
74 @parameterized.expand([
75 ("no_ports", "up_single_container_many_times"),
76 ("with_ports", "up_single_container_many_times_with_ports"),
77 ])
78 @unittest.skipIf(get_podman_version() >= version.parse("5.0.0"), "Breaks as of podman-5.4.2.")
79 def test_up_single_container_many_times(self, name: str, subdir: str) -> None:
80 """Podman compose up should be able to start a container many times after it finishes
81 running.
82 """
83
84 compose_path = os.path.join(test_path(), f"lifetime/{subdir}/docker-compose.yml")
85
86 try:
87 self.run_subprocess_assert_returncode([
88 podman_compose_path(),
89 "-f",
90 compose_path,
91 "up",
92 "-d",
93 "container1",
94 ])
95
96 self.run_subprocess_assert_returncode([
97 podman_compose_path(),
98 "-f",
99 compose_path,
100 "up",
101 "-d",
102 "container2",
103 ])
104
105 out, _ = self.run_subprocess_assert_returncode([
106 podman_compose_path(),
107 "-f",
108 compose_path,
109 "logs",
110 "--no-log-prefix",
111 "--no-color",
112 "container1",
113 ])
114
115 self.assertEqual(out, b"test1\n")
116
117 # "restart: always" keeps restarting container until its removal
118 out, _ = self.run_subprocess_assert_returncode([
119 podman_compose_path(),
120 "-f",
121 compose_path,
122 "logs",
123 "--no-log-prefix",
124 "--no-color",
125 "container2",
126 ])
127
128 if not out.startswith(b"test2\ntest2"):
129 time.sleep(1)
130 out, _ = self.run_subprocess_assert_returncode([
131 podman_compose_path(),
132 "-f",
133 compose_path,
134 "logs",
135 "--no-log-prefix",
136 "--no-color",
137 "container2",
138 ])
139 self.assertTrue(out.startswith(b"test2\ntest2"))
140 finally:
141 out, _ = self.run_subprocess_assert_returncode([
142 podman_compose_path(),
143 "-f",
144 compose_path,
145 "down",
146 "-t",
147 "0",
148 ])