c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn#!/bin/bash
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# lxc: linux Container library
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# Authors:
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# Serge Hallyn <serge.hallyn@ubuntu.com>
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn#
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# This is a test for dependency between snapshots
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn#
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# When container c2 is created as an overlayfs clone of c1, then
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# we record it as such, because c1 cannot be deleted until c2 is
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# deleted. Once c2 is deleted, c1 should be delete-able.
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# This library is free software; you can redistribute it and/or
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# modify it under the terms of the GNU Lesser General Public
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# License as published by the Free Software Foundation; either
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# version 2.1 of the License, or (at your option) any later version.
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# This library is distributed in the hope that it will be useful,
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# but WITHOUT ANY WARRANTY; without even the implied warranty of
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# Lesser General Public License for more details.
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# You should have received a copy of the GNU Lesser General Public
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# License along with this library; if not, write to the Free Software
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn# This test assumes an Ubuntu host
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynset -e
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynif ! grep -q overlay /proc/filesystems; then
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn echo "Not running this test as overlay is not available"
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn exit 0
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynfi
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyncleanup() {
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn for i in `seq 1 20`; do
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn lxc-destroy -n snapdeptest$i > /dev/null 2>&1 || true
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn done
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn lxc-destroy -n snapdeptest > /dev/null 2>&1 || true
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn}
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynverify_deps() {
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn n=$1
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn m=`wc -l /var/lib/lxc/snapdeptest/lxc_snapshots | awk '{ print $1 }'`
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn [ $((n*2)) -eq $m ]
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn}
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyncleanup
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyntrap cleanup EXIT SIGHUP SIGINT SIGTERM
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynlxc-create -t busybox -n snapdeptest
d0a6bd39400a6d14cfec94ad647f3af1bda1e321Christian Braunerlxc-copy -s -n snapdeptest -N snapdeptest1
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynfail=0
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynlxc-destroy -n snapdeptest || fail=1
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynif [ $fail -eq 0 ]; then
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn echo "FAIL: clone did not prevent deletion"
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn false
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynfi
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynfor i in `seq 2 20`; do
d0a6bd39400a6d14cfec94ad647f3af1bda1e321Christian Brauner lxc-copy -s -n snapdeptest -N snapdeptest$i
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyndone
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynverify_deps 20
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynlxc-destroy -n snapdeptest1
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynverify_deps 19
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynlxc-destroy -n snapdeptest20
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynverify_deps 18
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynfor i in `seq 2 19`; do
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn lxc-destroy -n snapdeptest$i
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyndone
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynlxc-destroy -n snapdeptest
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallyn
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynecho "Snapshot clone dependency test passed"
c4532a2036fd4a9283275b499b7a379fa9689172Serge Hallynexit 0