lxc-test-unpriv revision e2ef635e682cef87b234d27e0b41923db857efa3
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews# lxc: linux Container library
2f1c460beaa1e372255e7a1b8aad8996f011816dMark Andrews# Serge Hallyn <serge.hallyn@ubuntu.com>
9ee66e3a5b45654235472711439f9db1766c82caMark Andrews# This is a test script for unprivileged containers
9ee66e3a5b45654235472711439f9db1766c82caMark Andrews# This library is free software; you can redistribute it and/or
9ee66e3a5b45654235472711439f9db1766c82caMark Andrews# modify it under the terms of the GNU Lesser General Public
9ee66e3a5b45654235472711439f9db1766c82caMark Andrews# License as published by the Free Software Foundation; either
8b2b41ba4f8cabed897f2d852a6c07abfb23231eMark Andrews# version 2.1 of the License, or (at your option) any later version.
47f8b47b8df05aade51e35b31c3df46fb121a098Mark Andrews# This library is distributed in the hope that it will be useful,
47f8b47b8df05aade51e35b31c3df46fb121a098Mark Andrews# but WITHOUT ANY WARRANTY; without even the implied warranty of
fcadf0b3205be950da14c80fedbf088fc8fd2190Evan Hunt# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fcadf0b3205be950da14c80fedbf088fc8fd2190Evan Hunt# Lesser General Public License for more details.
fcadf0b3205be950da14c80fedbf088fc8fd2190Evan Hunt# You should have received a copy of the GNU Lesser General Public
fcadf0b3205be950da14c80fedbf088fc8fd2190Evan Hunt# License along with this library; if not, write to the Free Software
47f8b47b8df05aade51e35b31c3df46fb121a098Mark Andrews# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
47f8b47b8df05aade51e35b31c3df46fb121a098Mark Andrews# This test assumes an Ubuntu host
31c7bf574e6e1b296c5cfa5699e4f2007fbd61cdMark Andrews echo "ERROR: Must run as root."
6f2752da7a1036cd59be17236ca66630d00f11cdMukund Sivaramanwhich newuidmap >/dev/null 2>&1 || { echo "'newuidmap' command is missing" >&2; exit 1; }
48ec547968d7da5b1240222c53a90efce25157a2Mark Andrews run_cmd lxc-stop -n c2 -k || true
48ec547968d7da5b1240222c53a90efce25157a2Mark Andrews run_cmd lxc-stop -n c1 -k || true
178dc0e1d617a6ef6387e9942ba9cdb370d1bde2Mark Andrews sed -i '/lxcunpriv/d' /run/lxc/nics /etc/lxc/lxc-usernet
178dc0e1d617a6ef6387e9942ba9cdb370d1bde2Mark Andrews sed -i '/^lxcunpriv:/d' /etc/subuid /etc/subgid
e51ba2650025460b26092fb2500e0b6dfbf6d548Mark Andrews if [ $DONE -eq 0 ]; then
af326c2e3f90d86a8966a1298d7aa157667f97cdEvan Hunt env http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
ce786900292468e465fb74df8712a625ce10e103Mukund Sivaraman# create a test user
2be9d18ee9bd1b4eec4720218e4f43352603291fMark Andrewsecho "$TUSER veth lxcbr0 2" >> /etc/lxc/lxc-usernet
4d506ae0d1671e5a1272ef1ef13986af01616ac4Mark Andrewsusermod -v 910000-919999 -w 910000-919999 $TUSER
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewslxc.network.type = veth
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewslxc.network.link = lxcbr0
f9e49fd80e2ac4fce0fef11d330b88ff3693ad99Witold Krecickilxc.id_map = u 0 910000 9999
f9e49fd80e2ac4fce0fef11d330b88ff3693ad99Witold Krecickilxc.id_map = g 0 910000 9999
6ce5279d0f30c8c760e27baf92bb44b3f4962354Evan Hunt cgm chown all $TUSER $(id -u $TUSER) $(id -g $TUSER)
f5898cf3484b1588d5239faa4062a2b2b606ce91Evan Hunt dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
f5898cf3484b1588d5239faa4062a2b2b606ce91Evan Hunt --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Create \
f5898cf3484b1588d5239faa4062a2b2b606ce91Evan Hunt dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
f5898cf3484b1588d5239faa4062a2b2b606ce91Evan Hunt --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Chown \
c27c710939766a7bb315bde1f12ab18d93c77cc8Mark Andrews string:$d string:$TUSER int32:$(id -u $TUSER) int32:$(id -g $TUSER) >/dev/null
c27c710939766a7bb315bde1f12ab18d93c77cc8Mark Andrews dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock \
4e9a1ad22618a46dab82eeb2d030190cec0afbc6Mukund Sivaraman --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.MovePid \
4e9a1ad22618a46dab82eeb2d030190cec0afbc6Mukund Sivaraman string:$d string:$TUSER int32:$$ >/dev/null
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews# Copy the download template cache if available
f3a4a5f8db3d9fd352a3e2eb6be779a78da03f52Mark Andrews cp -R /var/cache/lxc/download $HDIR/.cache/lxc && \
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrewsrun_cmd lxc-create -t download -n c1 -- -d ubuntu -r trusty -a $ARCH
2fb6d3782b548ba678cfb8ff09e0d1e49fafb84dMark Andrews[ "$p1" != "-1" ] || { echo "Failed to start container c1"; false; }
33f91e248b67afa96c5b855ba3ace20b5d89dbd0Mark Andrews[ "$p1" != "-1" ] || { echo "Failed to start container c2"; false; }
51227d6f16840ae359701b5d56970a5f3860db5aEvan Hunt echo "Testing containers under different cgroups per subsystem"
12b791ae2018561482f3b68dd6658c2ad1a4d934Mark Andrews [ "$p1" != "-1" ] || { echo "Failed to start container c1"; false; }
3a71cd8ca3c4970b71ef503553eda2666ce3d2b1Mark Andrews echo "Testing lxc-attach and lxc-cgroup from different cgroup"