Skip to content

Commit f8749ba

Browse files
committed
merge branch 'pr-2509'
Kir Kolyshkin (2): tests/int/checkpoint: fds and pids cleanup tests/int/checkpoint: don't remove readonly flag LGTMs: @mrunalp @AkihiroSuda @cyphar Closes #2509
2 parents f9850af + 6d5125f commit f8749ba

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

tests/integration/checkpoint.bats

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ function setup() {
1212

1313
function teardown() {
1414
teardown_busybox
15+
local pid fd
16+
17+
for pid in "${PIDS_TO_KILL[@]}"; do
18+
kill -9 $pid || true
19+
done
20+
PIDS_TO_KILL=()
21+
22+
for fd in "${FDS_TO_CLOSE[@]}"; do
23+
exec {fd}>&-
24+
done
25+
FDS_TO_CLOSE=()
1526
}
1627

1728
function setup_pipes() {
@@ -21,22 +32,23 @@ function setup_pipes() {
2132

2233
# Create two sets of pipes
2334
# for stdout/stderr
24-
exec 52<> <(:)
25-
exec 50</proc/self/fd/52
26-
exec 51>/proc/self/fd/52
27-
exec 52>&-
35+
exec {pipe}<> <(:)
36+
exec {out_r}</proc/self/fd/$pipe
37+
exec {out_w}>/proc/self/fd/$pipe
38+
exec {pipe}>&-
2839
# ... and stdin
29-
exec 62<> <(:)
30-
exec 60</proc/self/fd/62
31-
exec 61>/proc/self/fd/62
32-
exec 62>&-
40+
exec {pipe}<> <(:)
41+
exec {in_r}</proc/self/fd/$pipe
42+
exec {in_w}>/proc/self/fd/$pipe
43+
exec {pipe}>&-
44+
FDS_TO_CLOSE=($in_r $in_w $out_r $out_w)
3345
}
3446

3547
function check_pipes() {
36-
echo Ping >&61
37-
exec 61>&-
38-
exec 51>&-
39-
run cat <&50
48+
echo Ping >&${in_w}
49+
exec {in_w}>&-
50+
exec {out_w}>&-
51+
run cat <&${out_r}
4052
[ "$status" -eq 0 ]
4153
[[ "${output}" == *"ponG Ping"* ]]
4254
}
@@ -84,7 +96,7 @@ function simple_cr() {
8496
setup_pipes
8597

8698
# run busybox
87-
__runc run -d test_busybox <&60 >&51 2>&51
99+
__runc run -d test_busybox <&${in_r} >&${out_w} 2>&${out_w}
88100
[ $? -eq 0 ]
89101

90102
testcontainer test_busybox running
@@ -108,7 +120,7 @@ function simple_cr() {
108120
testcontainer test_busybox checkpointed
109121

110122
# restore from checkpoint
111-
__runc --criu "$CRIU" restore -d --work-path ./work-dir --image-path ./image-dir test_busybox <&60 >&51 2>&51
123+
__runc --criu "$CRIU" restore -d --work-path ./work-dir --image-path ./image-dir test_busybox <&${in_r} >&${out_w} 2>&${out_w}
112124
ret=$?
113125
cat ./work-dir/restore.log | grep -B 5 Error || true
114126
[ $ret -eq 0 ]
@@ -132,14 +144,11 @@ function simple_cr() {
132144

133145
setup_pipes
134146

135-
# This should not be necessary: https://github.com/checkpoint-restore/criu/issues/575
136-
update_config '(.. | select(.readonly? != null)) .readonly |= false'
137-
138147
# TCP port for lazy migration
139148
port=27277
140149

141150
# run busybox
142-
__runc run -d test_busybox <&60 >&51 2>&51
151+
__runc run -d test_busybox <&${in_r} >&${out_w} 2>&${out_w}
143152
[ $? -eq 0 ]
144153

145154
testcontainer test_busybox running
@@ -150,16 +159,18 @@ function simple_cr() {
150159

151160
# For lazy migration we need to know when CRIU is ready to serve
152161
# the memory pages via TCP.
153-
exec 72<> <(:)
154-
exec 70</proc/self/fd/72 71>/proc/self/fd/72
155-
exec 72>&-
162+
exec {pipe}<> <(:)
163+
exec {lazy_r}</proc/self/fd/$pipe {lazy_w}>/proc/self/fd/$pipe
164+
exec {pipe}>&-
165+
FDS_TO_CLOSE+=($lazy_r $lazy_w)
156166

157-
__runc --criu "$CRIU" checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd 71 --work-path ./work-dir --image-path ./image-dir test_busybox &
167+
__runc --criu "$CRIU" checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd ${lazy_w} --work-path ./work-dir --image-path ./image-dir test_busybox &
158168
cpt_pid=$!
169+
PIDS_TO_KILL=($cpt_pid)
159170

160171
# wait for lazy page server to be ready
161-
out=$(timeout 2 dd if=/proc/self/fd/70 bs=1 count=1 2>/dev/null | od)
162-
exec 71>&-
172+
out=$(timeout 2 dd if=/proc/self/fd/${lazy_r} bs=1 count=1 2>/dev/null | od)
173+
exec {lazy_w}>&-
163174
out=$(echo $out) # rm newlines
164175
# show errors if there are any before we fail
165176
grep -B5 Error ./work-dir/dump.log || true
@@ -172,14 +183,15 @@ function simple_cr() {
172183
# Start CRIU in lazy-daemon mode
173184
${CRIU} lazy-pages --page-server --address 127.0.0.1 --port ${port} -D image-dir &
174185
lp_pid=$!
186+
PIDS_TO_KILL+=($lp_pid)
175187

176188
# Restore lazily from checkpoint.
177189
# The restored container needs a different name as the checkpointed
178190
# container is not yet destroyed. It is only destroyed at that point
179191
# in time when the last page is lazily transferred to the destination.
180192
# Killing the CRIU on the checkpoint side will let the container
181193
# continue to run if the migration failed at some point.
182-
__runc --criu "$CRIU" restore -d --work-path ./image-dir --image-path ./image-dir --lazy-pages test_busybox_restore <&60 >&51 2>&51
194+
__runc --criu "$CRIU" restore -d --work-path ./image-dir --image-path ./image-dir --lazy-pages test_busybox_restore <&${in_r} >&${out_w} 2>&${out_w}
183195
ret=$?
184196
cat ./work-dir/restore.log | grep -B 5 Error || true
185197
[ $ret -eq 0 ]
@@ -196,6 +208,7 @@ function simple_cr() {
196208

197209
wait $lp_pid
198210
[ $? -eq 0 ]
211+
PIDS_TO_KILL=()
199212

200213
check_pipes
201214
}

0 commit comments

Comments
 (0)