mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
test: Introduce a standardized test environment
This commit is contained in:
committed by
Joachim Wiberg
parent
d81ca8fcd1
commit
0f76b07625
@@ -3,4 +3,5 @@
|
||||
/.ccache
|
||||
/dl
|
||||
/output*
|
||||
/test/.venv
|
||||
/local.mk
|
||||
|
||||
@@ -4,3 +4,6 @@
|
||||
[submodule "9pm"]
|
||||
path = 9pm
|
||||
url = ../9pm
|
||||
[submodule "qeneth"]
|
||||
path = qeneth
|
||||
url = ../qeneth.git
|
||||
|
||||
Submodule
+1
Submodule qeneth added at 5b45ecf0d9
@@ -0,0 +1,27 @@
|
||||
FROM alpine:3.18.0
|
||||
|
||||
RUN apk add --no-cache \
|
||||
e2fsprogs \
|
||||
gcc \
|
||||
graphviz \
|
||||
iproute2 \
|
||||
iputils \
|
||||
libc-dev \
|
||||
libyang-dev \
|
||||
python3-dev \
|
||||
qemu-img \
|
||||
qemu-system-x86_64 \
|
||||
ruby-mustache \
|
||||
squashfs-tools
|
||||
|
||||
# Alpine's QEMU package does not bundle this for some reason, copied
|
||||
# from Ubuntu
|
||||
COPY qemu-ifup /etc
|
||||
|
||||
# Needed to let qeneth find mustache(1)
|
||||
ENV PATH="${PATH}:/usr/lib/ruby/gems/3.2.0/bin"
|
||||
|
||||
# Install all python packages used by the tests
|
||||
COPY init-venv.sh /root
|
||||
COPY pip-requirements.txt /root
|
||||
RUN ~/init-venv.sh ~/pip-requirements.txt
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
python3 -m venv ~/.infix-test-venv
|
||||
. ~/.infix-test-venv/bin/activate
|
||||
|
||||
python3 -m pip install --upgrade pip
|
||||
python3 -m pip install -r "$1"
|
||||
@@ -0,0 +1,5 @@
|
||||
libyang==2.7.1
|
||||
netconf_client==2.2.0
|
||||
networkx==3.1
|
||||
pydot==1.4.2
|
||||
pyyaml==5.4.1
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#! /bin/sh
|
||||
# Script to bring a network (tap) device for qemu up.
|
||||
# The idea is to add the tap device to the same bridge
|
||||
# as we have default routing to.
|
||||
|
||||
# in order to be able to find brctl
|
||||
PATH=$PATH:/sbin:/usr/sbin
|
||||
ip=$(which ip)
|
||||
|
||||
if [ -n "$ip" ]; then
|
||||
ip link set "$1" up
|
||||
else
|
||||
brctl=$(which brctl)
|
||||
if [ ! "$ip" -o ! "$brctl" ]; then
|
||||
echo "W: $0: not doing any bridge processing: neither ip nor brctl utility not found" >&2
|
||||
exit 0
|
||||
fi
|
||||
ifconfig "$1" 0.0.0.0 up
|
||||
fi
|
||||
|
||||
switch=$(ip route ls | \
|
||||
awk '/^default / {
|
||||
for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
|
||||
}'
|
||||
)
|
||||
|
||||
# only add the interface to default-route bridge if we
|
||||
# have such interface (with default route) and if that
|
||||
# interface is actually a bridge.
|
||||
# It is possible to have several default routes too
|
||||
for br in $switch; do
|
||||
if [ -d /sys/class/net/$br/bridge/. ]; then
|
||||
if [ -n "$ip" ]; then
|
||||
ip link set "$1" master "$br"
|
||||
else
|
||||
brctl addif $br "$1"
|
||||
fi
|
||||
exit # exit with status of the previous command
|
||||
fi
|
||||
done
|
||||
|
||||
echo "W: $0: no bridge for guest interface found" >&2
|
||||
@@ -0,0 +1,128 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
INFIX_TEST=ghcr.io/kernelkit/infix-test:0.2
|
||||
|
||||
extract_yang()
|
||||
{
|
||||
local imgfile="$1"
|
||||
|
||||
[ "$imgfile" ] || { true && return; }
|
||||
|
||||
unsquashfs -q -n -f \
|
||||
-d $envdir/yangdir \
|
||||
"$imgfile" \
|
||||
/usr/share/yang
|
||||
|
||||
INFAMY_ARGS="$INFAMY_ARGS -y $envdir/yangdir"
|
||||
}
|
||||
|
||||
start_topology()
|
||||
{
|
||||
local qenethdir="$1"
|
||||
local imgfile="$2"
|
||||
|
||||
[ "$qenethdir" ] || { true && return; }
|
||||
|
||||
rm -rf $envdir/qeneth
|
||||
cp -a "$qenethdir" $envdir/qeneth
|
||||
if [ "$imgfile" ]; then
|
||||
local imgname=$(basename "$imgfile")
|
||||
imgfile=$(readlink -f "$imgfile")
|
||||
|
||||
ln -sf "$imgfile" $envdir/qeneth/"$imgname"
|
||||
fi
|
||||
|
||||
(cd $envdir/qeneth/ && $qeneth generate && $qeneth start)
|
||||
INFAMY_ARGS="$INFAMY_ARGS $envdir/qeneth/topology.dot"
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF
|
||||
usage: test/env [-C] [-f <IMAGE>] [-q <QENETH-DIR>] <COMMAND> [<ARGS>...]
|
||||
|
||||
Run <COMMAND> in a pre-packaged container with all the packages
|
||||
required for running the test suite installed.
|
||||
|
||||
Option:
|
||||
|
||||
-C
|
||||
Don't containerize the command, run it directly in the current
|
||||
namespaces
|
||||
|
||||
-f <IMAGE>
|
||||
Infix image to test
|
||||
|
||||
-q <QENETH-DIR>
|
||||
Directory containing a topology.dot.in, suitable for consumption
|
||||
by qeneth
|
||||
EOF
|
||||
}
|
||||
|
||||
testdir=$(dirname $(readlink -f "$0"))
|
||||
ixdir=$(readlink -f "$testdir/..")
|
||||
envdir="$HOME/.infix-test-venv"
|
||||
qeneth="$ixdir/qeneth/qeneth"
|
||||
|
||||
# Global options
|
||||
containerize=yes
|
||||
while getopts "Cf:q:" opt; do
|
||||
case ${opt} in
|
||||
C)
|
||||
containerize=
|
||||
;;
|
||||
f)
|
||||
imgfile="$OPTARG"
|
||||
;;
|
||||
q)
|
||||
qenethdir="$OPTARG"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$containerize" ]; then
|
||||
if which podman >/dev/null; then
|
||||
runner=podman
|
||||
elif which docker >/dev/null; then
|
||||
runner=docker
|
||||
else
|
||||
echo "Error: Neither podman nor docker is installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kvm=
|
||||
if [ -c /dev/kvm ]; then
|
||||
kvm="--device=/dev/kvm"
|
||||
fi
|
||||
|
||||
exec $runner run \
|
||||
--cap-add=NET_ADMIN \
|
||||
--device=/dev/net/tun \
|
||||
--interactive \
|
||||
--rm \
|
||||
--security-opt seccomp=unconfined \
|
||||
--sysctl net.ipv6.conf.all.disable_ipv6=0 \
|
||||
--tty \
|
||||
--volume "$ixdir":"$ixdir" \
|
||||
--workdir $(pwd) \
|
||||
$kvm \
|
||||
$INFIX_TEST \
|
||||
"$0" -C "$@"
|
||||
fi
|
||||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
usage && exit 1
|
||||
fi
|
||||
|
||||
. "$envdir/bin/activate"
|
||||
export PYTHONPATH="$testdir"
|
||||
|
||||
extract_yang "$imgfile"
|
||||
start_topology "$qenethdir" "$imgfile"
|
||||
export INFAMY_ARGS
|
||||
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user