]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc-test-symlink
meson: Remove non-existent tests
[mirror_lxc.git] / src / tests / lxc-test-symlink
1 #!/bin/bash
2
3 set -ex
4
5 # lxc: linux Container library
6
7 # Authors:
8 # Serge Hallyn <serge.hallyn@ubuntu.com>
9 #
10 # This is a regression test for symbolic links
11
12 dirname=$(mktemp -d)
13 fname=$(mktemp)
14 fname2=$(mktemp)
15
16 lxcpath=/var/lib/lxcsym1
17
18 cleanup() {
19 lxc-destroy -P $lxcpath -f -n symtest1 || true
20 rm -f $lxcpath
21 rmdir $dirname || true
22 rm -f $fname || true
23 rm -f $fname2 || true
24 }
25
26 trap cleanup EXIT SIGHUP SIGINT SIGTERM
27
28 testrun() {
29 expected=$1
30 run=$2
31 pass="pass"
32 lxc-start -P $lxcpath -n symtest1 -l trace -o $lxcpath/log || pass="fail"
33 [ $pass = "pass" ] && lxc-wait -P $lxcpath -n symtest1 -t 10 -s RUNNING || pass="fail"
34 if [ "$pass" != "$expected" ]; then
35 echo "Test $run: expected $expected but container did not. Start log:"
36 cat $lxcpath/log
37 echo "FAIL: Test $run: expected $expected but container did not."
38 false
39 fi
40 lxc-stop -P $lxcpath -n symtest1 -k || true
41 }
42
43 # make lxcpath a symlink - this should NOT cause failure
44 ln -s /var/lib/lxc $lxcpath
45
46 lxc-destroy -P $lxcpath -f -n symtest1 || true
47 lxc-create -P $lxcpath -t busybox -n symtest1
48
49 cat >> /var/lib/lxc/symtest1/config << EOF
50 lxc.mount.entry = $dirname opt/xxx/dir none bind,create=dir
51 lxc.mount.entry = $fname opt/xxx/file none bind,create=file
52 lxc.mount.entry = $fname2 opt/xxx/file2 none bind
53 lxc.mount.entry = $dirname /var/lib/lxc/symtest1/rootfs/opt/xxx/dir2 none bind,create=dir
54 EOF
55
56 # Regular - should succeed
57 mkdir -p /var/lib/lxc/symtest1/rootfs/opt/xxx
58 touch /var/lib/lxc/symtest1/rootfs/opt/xxx/file2
59 testrun pass 1
60
61 # symlink - should fail
62 rm -rf /var/lib/lxc/symtest1/rootfs/opt/xxx
63 mkdir -p /var/lib/lxc/symtest1/rootfs/opt/xxx2
64 ln -s /var/lib/lxc/symtest1/rootfs/opt/xxx2 /var/lib/lxc/symtest1/rootfs/opt/xxx
65 touch /var/lib/lxc/symtest1/rootfs/opt/xxx/file2
66 testrun fail 2
67
68 # final final symlink - should fail
69 rm -rf $lxcpath/symtest1/rootfs/opt/xxx
70 mkdir -p $lxcpath/symtest1/rootfs/opt/xxx
71 mkdir -p $lxcpath/symtest1/rootfs/opt/xxx/dir
72 touch $lxcpath/symtest1/rootfs/opt/xxx/file
73 touch $lxcpath/symtest1/rootfs/opt/xxx/file2src
74 ln -s $lxcpath/symtest1/rootfs/opt/xxx/file2src $lxcpath/symtest1/rootfs/opt/xxx/file2
75 testrun fail 3
76
77 # Ideally we'd also try a loop device, but that won't work in nested containers
78 # anyway - TODO
79
80 # what about /proc itself
81
82 rm -rf $lxcpath/symtest1/rootfs/opt/xxx
83 mkdir -p $lxcpath/symtest1/rootfs/opt/xxx
84 touch $lxcpath/symtest1/rootfs/opt/xxx/file2
85 mv $lxcpath/symtest1/rootfs/proc $lxcpath/symtest1/rootfs/proc1
86 ln -s $lxcpath/symtest1/rootfs/proc1 $lxcpath/symtest1/rootfs/proc
87 testrun fail 4
88
89 echo "all tests passed"