lxc-test-unpriv revision 42e5c9878f0d20b3e9682ef441afed2f0228b298
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# lxc: linux Container library
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# Serge Hallyn <serge.hallyn@ubuntu.com>
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# This is a test script for unprivileged containers
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# This library is free software; you can redistribute it and/or
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# modify it under the terms of the GNU Lesser General Public
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# License as published by the Free Software Foundation; either
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# version 2.1 of the License, or (at your option) any later version.
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# This library is distributed in the hope that it will be useful,
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# but WITHOUT ANY WARRANTY; without even the implied warranty of
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# Lesser General Public License for more details.
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# You should have received a copy of the GNU Lesser General Public
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# License along with this library; if not, write to the Free Software
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# This test assumes an Ubuntu host
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib echo "ERROR: Must run as root."
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdibwhich newuidmap >/dev/null 2>&1 || { echo "'newuidmap' command is missing" >&2; exit 1; }
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib run_cmd lxc-stop -n c2 -k || true
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib run_cmd lxc-stop -n c1 -k || true
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib sed -i '/lxcunpriv/d' /run/lxc/nics /etc/lxc/lxc-usernet
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib if [ $DONE -eq 0 ]; then
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib env http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# create a test user
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdiblxc.network.type = veth
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdiblxc.network.link = lxcbr0
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdiblxc.id_map = u 0 910000 9999
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdiblxc.id_map = g 0 910000 9999
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib cgm chown all $TUSER $(id -u $TUSER) $(id -g $TUSER)
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Create \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Chown \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib string:$d string:$TUSER int32:$(id -u $TUSER) int32:$(id -g $TUSER) >/dev/null
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.MovePid \
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib# Copy the download template cache if available
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdibrun_cmd lxc-create -t download -n c1 -- -d ubuntu -r trusty -a $ARCH
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib[ "$p1" != "-1" ] || { echo "Failed to start container c1"; false; }
3d2b040efe01bad393a1b2505e59d6d0a7b117d2theAdib[ "$p1" != "-1" ] || { echo "Failed to start container c2"; false; }