]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add test script to test the ro option of lxc.rootfs.options
authorLi Feng <lifeng68@huawei.com>
Tue, 18 Jul 2017 10:31:35 +0000 (18:31 +0800)
committerLi Feng <lifeng68@huawei.com>
Tue, 18 Jul 2017 10:31:35 +0000 (18:31 +0800)
Signed-off-by: Li Feng <lifeng68@huawei.com>
src/tests/Makefile.am
src/tests/lxc-test-rootfs [new file with mode: 0755]

index be6735e6e5f00007e51ea51d12faae22c10edc61..59a52b737e3b7124023aeefc4ba496063796605f 100644 (file)
@@ -61,7 +61,8 @@ bin_SCRIPTS = lxc-test-automount \
              lxc-test-autostart \
              lxc-test-cloneconfig \
              lxc-test-createconfig \
-             lxc-test-no-new-privs
+             lxc-test-no-new-privs \
+             lxc-test-rootfs
 
 if DISTRO_UBUNTU
 bin_SCRIPTS += \
@@ -94,6 +95,7 @@ EXTRA_DIST = \
        lxcpath.c \
        lxc-test-lxc-attach \
        lxc-test-automount \
+       lxc-test-rootfs \
        lxc-test-autostart \
        lxc-test-apparmor-mount \
        lxc-test-checkpoint-restore \
diff --git a/src/tests/lxc-test-rootfs b/src/tests/lxc-test-rootfs
new file mode 100755 (executable)
index 0000000..08202ff
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# lxc: linux Container library
+
+# Authors:
+# Feng Li <lifeng68@huawei.com>
+
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+set -ex
+
+cleanup() {
+       set +e
+       lxc-destroy -n lxc-test-rootfs -f
+       if [ $PHASE != "done" ]; then
+               echo "rootfs test failed at $PHASE"
+               exit 1
+       fi
+       echo "rootfs test passed"
+       exit 0
+}
+
+PHASE=setup
+trap cleanup EXIT
+
+lxc-destroy -n lxc-test-rootfs -f || true
+lxc-create -t busybox -n lxc-test-rootfs
+
+PHASE=ro_rootfs
+echo "Starting phase $PHASE"
+config=/var/lib/lxc/lxc-test-rootfs/config
+sed -i '/lxc.rootfs.options/d' $config
+echo "lxc.rootfs.options = ro" >> $config
+
+lxc-start -n lxc-test-rootfs
+pid=`lxc-info -n lxc-test-rootfs -p -H`
+ro=0
+mkdir /proc/$pid/root/rotest || ro=1
+[ $ro -ne 0 ]
+
+lxc-stop -n lxc-test-rootfs -k
+PHASE=rw_rootfs
+echo "Starting phase $PHASE"
+sed -i '/lxc.rootfs.options/d' $config
+echo "lxc.rootfs.options = rw" >> $config
+lxc-start -n lxc-test-rootfs
+pid=`lxc-info -n lxc-test-rootfs -p -H`
+ro=0
+mkdir /proc/$pid/root/rwtest || ro=1
+[ $ro -ne 1 ]
+rmdir /proc/$pid/root/rwtest
+ro=0
+
+PHASE=done