lxc-test-usernic revision 45e854dc86514a472ff1496d01321c77c12c0aa4
# lxc: linux Container library
# Authors:
# Serge Hallyn <serge.hallyn@ubuntu.com>
#
# This is a test script for the lxc-user-nic program
# 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
rm -rf /tmp/usernic-test
exit $1
}
# create a test user
export XDG_RUNTIME_DIR=/run/user/$uid
EOF
echo XXX[
sleep 20
#
lxc.network.type = empty
lxc.id_map = u 0 911000 10000
lxc.id_map = g 0 911000 10000
EOF
# Create two test bridges
LXC_USERNIC_PATH=$(ls -1 /usr/lib/*/lxc/lxc-user-nic | head -1)
# Create three containers
su -l usernic-user -c "lxc-create -P /tmp/usernic-test/lxcbase -t busybox -n b1 -f /tmp/lxc-usernic.conf"
# Assign one veth, should fail as no allowed entries yet
if [ $? -eq 0 ]; then
echo "FAIL: able to create nic with no entries"
cleanup 1
fi
# Give him a quota of two
# Assign one veth to second bridge, should fail
if [ $? -eq 0 ]; then
echo "FAIL: able to create nic with no entries"
cleanup 1
fi
# Assign two veths, should succeed
if [ $? -ne 0 ]; then
echo "FAIL: unable to create first nic"
cleanup 1
fi
if [ $? -ne 0 ]; then
echo "FAIL: unable to create second nic"
cleanup 1
fi
# Assign one more veth, should fail.
if [ $? -eq 0 ]; then
echo "FAIL: able to create third nic"
cleanup 1
fi
# Shut down and restart the container, should be able to assign more nics
if [ $? -ne 0 ]; then
echo "FAIL: unable to create nic after destroying the old"
cleanup 1
fi
# Create a root-owned ns
# assign veth to it - should fail
ret=$?
echo "FAIL: able to attach nic to root-owned container"
cleanup 1
fi
echo "All tests passed"