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 "runc exec" {
|
2016-05-20 08:28:58 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
runc exec test_busybox echo Hello from exec
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
echo text echoed = "'""${output}""'"
|
2016-03-15 03:55:05 +08:00
|
|
|
[[ "${output}" == *"Hello from exec"* ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "runc exec --pid-file" {
|
2016-05-20 08:28:58 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
runc exec --pid-file pid.txt test_busybox echo Hello from exec
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
echo text echoed = "'""${output}""'"
|
2016-03-15 03:55:05 +08:00
|
|
|
[[ "${output}" == *"Hello from exec"* ]]
|
|
|
|
|
2016-05-16 16:21:52 +08:00
|
|
|
# check pid.txt was generated
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e pid.txt ]
|
|
|
|
|
|
|
|
run cat pid.txt
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ ${lines[0]} =~ [0-9]+ ]]
|
2016-10-25 15:00:51 +08:00
|
|
|
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
|
2016-03-15 03:55:05 +08:00
|
|
|
}
|
2016-09-24 12:21:50 +08:00
|
|
|
|
2016-11-01 19:13:49 +08:00
|
|
|
@test "runc exec --pid-file with new CWD" {
|
|
|
|
# create pid_file directory as the CWD
|
|
|
|
run mkdir pid_file
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
run cd pid_file
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
|
2016-11-01 19:13:49 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
runc exec --pid-file pid.txt test_busybox echo Hello from exec
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo text echoed = "'""${output}""'"
|
|
|
|
[[ "${output}" == *"Hello from exec"* ]]
|
|
|
|
|
|
|
|
# check pid.txt was generated
|
|
|
|
[ -e pid.txt ]
|
|
|
|
|
|
|
|
run cat pid.txt
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ ${lines[0]} =~ [0-9]+ ]]
|
|
|
|
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
|
|
|
|
}
|
|
|
|
|
2016-09-24 12:21:50 +08:00
|
|
|
@test "runc exec ls -la" {
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-09-24 12:21:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
runc exec test_busybox ls -la
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ ${lines[0]} == *"total"* ]]
|
|
|
|
[[ ${lines[1]} == *"."* ]]
|
|
|
|
[[ ${lines[2]} == *".."* ]]
|
|
|
|
}
|
2016-10-20 15:10:43 +08:00
|
|
|
|
|
|
|
@test "runc exec ls -la with --cwd" {
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-10-20 15:10:43 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
runc exec --cwd /bin test_busybox pwd
|
|
|
|
[ "$status" -eq 0 ]
|
2017-07-20 04:12:19 +08:00
|
|
|
[[ ${output} == "/bin"* ]]
|
2016-10-20 15:10:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "runc exec --env" {
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-10-20 15:10:43 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
runc exec --env RUNC_EXEC_TEST=true test_busybox env
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
[[ ${output} == *"RUNC_EXEC_TEST=true"* ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "runc exec --user" {
|
2017-09-07 07:54:46 +08:00
|
|
|
# --user can't work in rootless containers that don't have idmap.
|
|
|
|
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
|
2016-05-11 15:45:00 +08:00
|
|
|
|
2016-10-20 15:10:43 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-10-20 15:10:43 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
runc exec --user 1000:1000 test_busybox id
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2017-09-07 07:54:46 +08:00
|
|
|
[[ "${output}" == "uid=1000 gid=1000"* ]]
|
2016-10-20 15:10:43 +08:00
|
|
|
}
|
2017-02-03 06:08:35 +08:00
|
|
|
|
|
|
|
@test "runc exec --additional-gids" {
|
2017-10-11 04:07:35 +08:00
|
|
|
requires root
|
|
|
|
|
2017-02-03 06:08:35 +08:00
|
|
|
# run busybox detached
|
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
wait_for_container 15 1 test_busybox
|
|
|
|
|
2019-07-08 10:08:30 +08:00
|
|
|
runc exec --user 1000:1000 --additional-gids 100 --additional-gids 65534 test_busybox id
|
2017-02-03 06:08:35 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2019-07-08 10:08:30 +08:00
|
|
|
[[ ${output} == "uid=1000 gid=1000 groups=100(users),65534(nogroup)" ]]
|
2017-02-03 06:08:35 +08:00
|
|
|
}
|
2019-02-25 17:58:43 +08:00
|
|
|
|
|
|
|
@test "runc exec --preserve-fds" {
|
|
|
|
# run busybox detached
|
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2019-03-14 11:10:38 +08:00
|
|
|
run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC ${RUNC_USE_SYSTEMD:+--systemd-cgroup} --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3"
|
2019-02-25 17:58:43 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
[[ "${output}" == *"hello"* ]]
|
|
|
|
}
|