2016-03-15 03:55:05 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
teardown_busybox
|
|
|
|
setup_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
teardown_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checkpoint and restore" {
|
2016-05-10 20:22:13 +08:00
|
|
|
# XXX: currently criu require root containers.
|
|
|
|
requires criu root
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# criu does not work with external terminals so..
|
|
|
|
# setting terminal and root:readonly: to false
|
2016-05-16 16:21:52 +08:00
|
|
|
sed -i 's;"terminal": true;"terminal": false;' config.json
|
|
|
|
sed -i 's;"readonly": true;"readonly": false;' config.json
|
2016-03-15 03:55:05 +08:00
|
|
|
sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
(
|
2016-05-14 06:49:45 +08:00
|
|
|
# run busybox (not detached)
|
|
|
|
runc run test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
) &
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# check state
|
|
|
|
wait_for_container 15 1 test_busybox
|
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
runc state test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == *"running"* ]]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# checkpoint the running container
|
2016-05-09 21:06:42 +08:00
|
|
|
runc --criu "$CRIU" checkpoint test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
# if you are having problems getting criu to work uncomment the following dump:
|
|
|
|
#cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# after checkpoint busybox is no longer running
|
2016-05-09 21:06:42 +08:00
|
|
|
runc state test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -ne 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# restore from checkpoint
|
|
|
|
(
|
2016-05-09 21:06:42 +08:00
|
|
|
runc --criu "$CRIU" restore test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
) &
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# check state
|
|
|
|
wait_for_container 15 1 test_busybox
|
|
|
|
|
|
|
|
# busybox should be back up and running
|
2016-05-09 21:06:42 +08:00
|
|
|
runc state test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == *"running"* ]]
|
|
|
|
}
|
2016-08-24 17:48:56 +08:00
|
|
|
|
|
|
|
@test "checkpoint(pre-dump) and restore" {
|
|
|
|
requires criu
|
|
|
|
|
|
|
|
# criu does not work with external terminals so..
|
|
|
|
# setting terminal and root:readonly: to false
|
|
|
|
sed -i 's;"terminal": true;"terminal": false;' config.json
|
|
|
|
sed -i 's;"readonly": true;"readonly": false;' config.json
|
|
|
|
sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json
|
|
|
|
|
|
|
|
(
|
|
|
|
# run busybox (not detached)
|
|
|
|
runc run test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
) &
|
|
|
|
|
|
|
|
# check state
|
|
|
|
wait_for_container 15 1 test_busybox
|
|
|
|
|
|
|
|
runc state test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == *"running"* ]]
|
|
|
|
|
|
|
|
|
|
|
|
#test checkpoint pre-dump
|
|
|
|
mkdir parent-dir
|
|
|
|
runc --criu "$CRIU" checkpoint --pre-dump --image-path ./parent-dir test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# busybox should still be running
|
|
|
|
runc state test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == *"running"* ]]
|
|
|
|
|
|
|
|
# checkpoint the running container
|
|
|
|
mkdir image-dir
|
|
|
|
runc --criu "$CRIU" checkpoint --parent-path ./parent-dir --image-path ./image-dir test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# after checkpoint busybox is no longer running
|
|
|
|
runc state test_busybox
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
|
|
|
|
# restore from checkpoint
|
|
|
|
(
|
|
|
|
runc --criu "$CRIU" restore --image-path ./image-dir test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
) &
|
|
|
|
|
|
|
|
# check state
|
|
|
|
wait_for_container 15 1 test_busybox
|
|
|
|
|
|
|
|
# busybox should be back up and running
|
|
|
|
runc state test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == *"running"* ]]
|
|
|
|
}
|