Debian Codegraph @

src/tests/lxc-test-exit-code

raw
1 #!/bin/sh
2
3 # SPDX-License-Identifier: LGPL-2.1+
4
5 # lxc: linux Container library
6
7 set -e
8
9 FAIL() {
10 echo -n "Failed " >&2
11 echo "$*" >&2
12 lxc-destroy -n busy -f
13 exit 1
14 }
15
16 # Create a container
17 lxc-create -t busybox -n busy || FAIL "creating busybox container"
18
19 # Run lxc-execute to make sure it fails when the command fails, and
20 # succeed when the command succeeds.
21 lxc-execute -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true
22 lxc-execute -n busy -- sh -c 'exit 0' || FAIL "should be succeeding"
23
24 # Now, start the container and wait for it to be in running state.
25 lxc-start -n busy -d || FAIL "starting busybox container"
26 lxc-wait -n busy -s RUNNING || FAIL "waiting for busybox container to run"
27
28 # And run the same tests on lxc-attach.
29 lxc-attach -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true
30 lxc-attach -n busy -- sh -c 'exit 0' || FAIL "should be succeeding"
31
32 lxc-destroy -n busy -f
33
34 exit 0