]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/lxc-test-symlink
spelling: timeout
[mirror_lxc.git] / src / tests / lxc-test-symlink
CommitLineData
592fd47a
SH
1#!/bin/bash
2
3set -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
12dirname=`mktemp -d`
13fname=`mktemp`
14fname2=`mktemp`
15
16lxcpath=/var/lib/lxcsym1
17
18cleanup() {
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
26trap cleanup EXIT SIGHUP SIGINT SIGTERM
27
28testrun() {
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
44ln -s /var/lib/lxc $lxcpath
45
46lxc-destroy -P $lxcpath -f -n symtest1 || true
47lxc-create -P $lxcpath -t busybox -n symtest1
48
49cat >> /var/lib/lxc/symtest1/config << EOF
50lxc.mount.entry = $dirname opt/xxx/dir none bind,create=dir
51lxc.mount.entry = $fname opt/xxx/file none bind,create=file
52lxc.mount.entry = $fname2 opt/xxx/file2 none bind
13cea07d 53lxc.mount.entry = $dirname /var/lib/lxc/symtest1/rootfs/opt/xxx/dir2 none bind,create=dir
592fd47a
SH
54EOF
55
56# Regular - should succeed
57mkdir -p /var/lib/lxc/symtest1/rootfs/opt/xxx
58touch /var/lib/lxc/symtest1/rootfs/opt/xxx/file2
59testrun pass 1
60
61# symlink - should fail
62rm -rf /var/lib/lxc/symtest1/rootfs/opt/xxx
63mkdir -p /var/lib/lxc/symtest1/rootfs/opt/xxx2
64ln -s /var/lib/lxc/symtest1/rootfs/opt/xxx2 /var/lib/lxc/symtest1/rootfs/opt/xxx
65touch /var/lib/lxc/symtest1/rootfs/opt/xxx/file2
66testrun fail 2
67
68# final final symlink - should fail
69rm -rf $lxcpath/symtest1/rootfs/opt/xxx
70mkdir -p $lxcpath/symtest1/rootfs/opt/xxx
71mkdir -p $lxcpath/symtest1/rootfs/opt/xxx/dir
72touch $lxcpath/symtest1/rootfs/opt/xxx/file
73touch $lxcpath/symtest1/rootfs/opt/xxx/file2src
74ln -s $lxcpath/symtest1/rootfs/opt/xxx/file2src $lxcpath/symtest1/rootfs/opt/xxx/file2
75testrun 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
82rm -rf $lxcpath/symtest1/rootfs/opt/xxx
83mkdir -p $lxcpath/symtest1/rootfs/opt/xxx
84touch $lxcpath/symtest1/rootfs/opt/xxx/file2
85mv $lxcpath/symtest1/rootfs/proc $lxcpath/symtest1/rootfs/proc1
86ln -s $lxcpath/symtest1/rootfs/proc1 $lxcpath/symtest1/rootfs/proc
87testrun fail 4
88
89echo "all tests passed"