# 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
# This test assumes an Ubuntu host
DONE=0
KNOWN_RELEASES="precise trusty xenial yakkety zesty"
LXC_USER_NIC="@LIBEXECDIR@/lxc/lxc-user-nic"
set +e
(
run_cmd "lxc-stop -n b1 -k"
echo "PASS"
exit 0
fi
echo "FAIL"
exit 1
}
env http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
}
ARCH=$(dpkg --print-architecture)
fi
set -eu
# create a test user
lxc.network.type = empty
lxc.id_map = u 0 910000 10000
lxc.id_map = g 0 910000 10000
EOF
done
else
done
fi
# Copy the download template cache if available
run_cmd "mkdir -p /home/usernic-user/.cache/lxc"
# Create two test bridges
ARCH=$(dpkg --print-architecture)
fi
# default release is trusty, or the systems release if recognized
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
done
fi
# Create three containers
run_cmd "lxc-start -n b1 -d"
# Assign one veth, should fail as no allowed entries yet
if run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br0 xx1"; then
echo "FAIL: able to create nic with no entries"
exit 1
fi
# Give him a quota of two
# Assign one veth to second bridge, should fail
if run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br1 xx1"; then
echo "FAIL: able to create nic with no entries"
exit 1
fi
# Assign two veths, should succeed
if ! run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br0 xx2"; then
echo "FAIL: unable to create first nic"
exit 1
fi
if ! run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br0 xx3"; then
echo "FAIL: unable to create second nic"
exit 1
fi
# Assign one more veth, should fail.
if run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br0 xx4"; then
echo "FAIL: able to create third nic"
exit 1
fi
# Shut down and restart the container, should be able to assign more nics
run_cmd "lxc-stop -n b1 -k"
run_cmd "lxc-start -n b1 -d"
if ! run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p1 veth usernic-br0 xx5"; then
echo "FAIL: unable to create nic after destroying the old"
cleanup 1
fi
run_cmd "lxc-stop -n b1 -k"
# Create a root-owned ns
# assign veth to it - should fail
if run_cmd "$LXC_USER_NIC $lxcpath $lxcname $p2 veth usernic-br0 xx6"; then
echo "FAIL: able to attach nic to root-owned container"
cleanup 1
fi
echo "All tests passed"
DONE=1