2
2
import os
3
3
import unittest
4
4
5
+ from tests .integration .test_utils import PodmanAwareRunSubprocessMixin
5
6
from tests .integration .test_utils import RunSubprocessMixin
7
+ from tests .integration .test_utils import is_systemd_available
6
8
from tests .integration .test_utils import podman_compose_path
7
9
from tests .integration .test_utils import test_path
8
10
@@ -14,7 +16,7 @@ def compose_yaml_path(suffix=""):
14
16
class TestComposeBaseDeps (unittest .TestCase , RunSubprocessMixin ):
15
17
def test_deps (self ):
16
18
try :
17
- output , error = self .run_subprocess_assert_returncode ([
19
+ output , _ = self .run_subprocess_assert_returncode ([
18
20
podman_compose_path (),
19
21
"-f" ,
20
22
compose_yaml_path (),
@@ -37,7 +39,7 @@ def test_deps(self):
37
39
38
40
def test_run_nodeps (self ):
39
41
try :
40
- output , error = self .run_subprocess_assert_returncode ([
42
+ output , _ = self .run_subprocess_assert_returncode ([
41
43
podman_compose_path (),
42
44
"-f" ,
43
45
compose_yaml_path (),
@@ -71,7 +73,7 @@ def test_up_nodeps(self):
71
73
"--detach" ,
72
74
"sleep" ,
73
75
])
74
- output , error = self .run_subprocess_assert_returncode ([
76
+ output , _ = self .run_subprocess_assert_returncode ([
75
77
podman_compose_path (),
76
78
"-f" ,
77
79
compose_yaml_path (),
@@ -144,7 +146,7 @@ class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
144
146
def test_deps_succeeds (self ):
145
147
suffix = "-conditional-succeeds"
146
148
try :
147
- output , error = self .run_subprocess_assert_returncode ([
149
+ output , _ = self .run_subprocess_assert_returncode ([
148
150
podman_compose_path (),
149
151
"-f" ,
150
152
compose_yaml_path (suffix ),
@@ -168,7 +170,7 @@ def test_deps_succeeds(self):
168
170
def test_deps_fails (self ):
169
171
suffix = "-conditional-fails"
170
172
try :
171
- output , error = self .run_subprocess_assert_returncode ([
173
+ output , _ = self .run_subprocess_assert_returncode ([
172
174
podman_compose_path (),
173
175
"-f" ,
174
176
compose_yaml_path (suffix ),
@@ -183,3 +185,82 @@ def test_deps_fails(self):
183
185
compose_yaml_path (suffix ),
184
186
"down" ,
185
187
])
188
+
189
+
190
+ class TestComposeConditionalDepsHealthy (unittest .TestCase , PodmanAwareRunSubprocessMixin ):
191
+ def setUp (self ):
192
+ self .podman_version = self .retrieve_podman_version ()
193
+
194
+ def test_up_deps_healthy (self ):
195
+ suffix = "-conditional-healthy"
196
+ try :
197
+ self .run_subprocess_assert_returncode ([
198
+ podman_compose_path (),
199
+ "-f" ,
200
+ compose_yaml_path (suffix ),
201
+ "up" ,
202
+ "sleep" ,
203
+ "--detach" ,
204
+ ])
205
+
206
+ # Since the command `podman wait --condition=healthy` is invalid prior to 4.6.0,
207
+ # we only validate healthy status for podman 4.6.0+, which won't be tested in the
208
+ # CI pipeline of the podman-compose project where podman 4.3.1 is employed.
209
+ podman_ver_major , podman_ver_minor , podman_ver_patch = self .podman_version
210
+ if podman_ver_major >= 4 and podman_ver_minor >= 6 and podman_ver_patch >= 0 :
211
+ self .run_subprocess_assert_returncode ([
212
+ "podman" ,
213
+ "wait" ,
214
+ "--condition=running" ,
215
+ "deps_web_1" ,
216
+ "deps_sleep_1" ,
217
+ ])
218
+
219
+ # check both web and sleep are running
220
+ output , _ = self .run_subprocess_assert_returncode ([
221
+ podman_compose_path (),
222
+ "-f" ,
223
+ compose_yaml_path (),
224
+ "ps" ,
225
+ "--format" ,
226
+ "{{.ID}}\t {{.Names}}\t {{.Status}}\t {{.StartedAt}}" ,
227
+ ])
228
+
229
+ # extract container id of web
230
+ decoded_out = output .decode ('utf-8' )
231
+ lines = decoded_out .split ("\n " )
232
+
233
+ web_lines = [line for line in lines if "web" in line ]
234
+ self .assertTrue (web_lines )
235
+ self .assertEqual (1 , len (web_lines ))
236
+ web_cnt_id , web_cnt_name , web_cnt_status , web_cnt_started = web_lines [0 ].split ("\t " )
237
+ self .assertNotEqual ("" , web_cnt_id )
238
+ self .assertEqual ("deps_web_1" , web_cnt_name )
239
+
240
+ sleep_lines = [line for line in lines if "sleep" in line ]
241
+ self .assertTrue (sleep_lines )
242
+ self .assertEqual (1 , len (sleep_lines ))
243
+ sleep_cnt_id , sleep_cnt_name , _ , sleep_cnt_started = sleep_lines [0 ].split ("\t " )
244
+ self .assertNotEqual ("" , sleep_cnt_id )
245
+ self .assertEqual ("deps_sleep_1" , sleep_cnt_name )
246
+
247
+ # When test case is executed inside container like github actions, the absence of
248
+ # systemd prevents health check from working properly, resulting in failure to
249
+ # transit to healthy state. As a result, we only assert the `healthy` state where
250
+ # systemd is functioning.
251
+ if (
252
+ is_systemd_available ()
253
+ and podman_ver_major >= 4
254
+ and podman_ver_minor >= 6
255
+ and podman_ver_patch >= 0
256
+ ):
257
+ self .assertIn ("healthy" , web_cnt_status )
258
+ self .assertGreaterEqual (int (sleep_cnt_started ), int (web_cnt_started ))
259
+
260
+ finally :
261
+ self .run_subprocess_assert_returncode ([
262
+ podman_compose_path (),
263
+ "-f" ,
264
+ compose_yaml_path (),
265
+ "down" ,
266
+ ])
0 commit comments