]> git.proxmox.com Git - mirror_frr.git/commitdiff
docker: Run container with its own network namespace
authorChristian Franke <chris@opensourcerouting.org>
Wed, 17 Oct 2018 17:35:15 +0000 (19:35 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Thu, 29 Nov 2018 15:51:27 +0000 (16:51 +0100)
For normal operation, there is no need for the container to run
in the host network environment or to have access to the users
X Session.

To accomodate usecases which need this, there is now a `TOPOTEST_OPTIONS`
environment variable to provide additional options to the docker run
command.

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
tests/topotests/docker/motd.txt
tests/topotests/docker/topotests_run.sh

index 1427fafcff51227745a593c9a637f26c7b83276c..cb02540f5cf843a403b45b17578675ab63716c16 100644 (file)
@@ -14,7 +14,3 @@ Here are some useful tips:
 
 * The topotests log directory can be found on your host machine on
   `/tmp/topotests_logs`.
-
-* You may open an `xterm` inside the container. We do our best to detect
-  the X session on your host machine
-
index 07e9f28b2f4110580e1cfbd0b54470af7b912b25..8bca756b89ec866a426368aaca6da777bb263e65 100755 (executable)
 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+set -e
 
-# Source folders
-FRR_DIR=$HOME/src/frr
-TOPOTESTS_DIR=$HOME/src/topotests
+if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
+       cat >&2 <<-EOF
 
+       This script runs the FRRouting topotests on the FRR tree
+       in the current working directory.
 
+       Usage: $0 [args...]
+
+       Its behavior can be modified by the following environment variables:
+
+       TOPOTEST_AUTOLOAD       If set to 1, the script will try to load necessary
+                               kernel modules without asking for confirmation first.
+
+       TOPOTEST_BUILDCACHE     Docker volume used for caching multiple FRR builds
+                               over container runs. By default a
+                               \`topotest-buildcache\` volume will be created for
+                               that purpose.
+
+       TOPOTEST_FRR            If set, don't test the FRR in the current working
+                               directory, but the one at the given path.
+
+       TOPOTEST_LOGS           If set, don't use \`/tmp/topotest_logs\` directory
+                               but use the provided path instead.
+
+       TOPOTEST_OPTIONS        These options are appended to the docker-run
+                               command for starting the tests.
+
+       TOPOTEST_PATH           If set, don't use the tests built into the image
+                               but the ones at the given path.
+
+       To get information about the commands available inside of the container,
+       run \`$0 help\`.
+       EOF
+       exit 1
+fi
+
+#
+# These two modules are needed to run the MPLS tests.
+# They are often not automatically loaded.
 #
-# Script begin
+# We cannot load them from the container since we don't
+# have host kernel modules available there. If we load
+# them from the host however, they can be used just fine.
 #
-CMD=$1
-if [ -z $1 ]; then
-  CMD=bash
+
+for module in mpls-router mpls-iptunnel; do
+       if modprobe -n $module 2> /dev/null; then
+               :
+       else
+               # If the module doesn't exist, we cannot do anything about it
+               continue
+       fi
+
+       if [ $(grep -c ${module/-/_} /proc/modules) -ne 0 ]; then
+               # If the module is loaded, we don't have to do anything
+               continue
+       fi
+
+       if [ "$TOPOTEST_AUTOLOAD" != "1" ]; then
+               echo "To run all the possible tests, we need to load $module."
+               echo -n "Do you want to proceed? [y/n] "
+               read answer
+               if [ x"$answer" != x"y" ]; then
+                       echo "Not loading."
+                       continue
+               fi
+       fi
+
+       if [ x"$(whoami)" = x"root" ]; then
+               modprobe $module
+       else
+               sudo modprobe $module
+       fi
+done
+
+if [ -z "$TOPOTEST_LOGS" ]; then
+       mkdir -p /tmp/topotest_logs
+       TOPOTEST_LOGS="/tmp/topotest_logs"
 fi
 
-docker run --rm -ti \
-  -v "/lib/modules:/lib/modules" \
-  -v "/tmp/topotests_logs:/tmp" \
-  -v "$FRR_DIR:/root/frr:ro" \
-  -v "$TOPOTESTS_DIR:/root/topotests:ro" \
-  -v "/tmp/.X11-unix:/tmp/.X11-unix" \
-  -v "$HOME/.Xauthority:/root/.Xauthority" \
-  -e DISPLAY=$DISPLAY \
-  --net=host \
-  --privileged \
-  topotests
-
-exit 0
+if [ -z "$TOPOTEST_FRR" ]; then
+       TOPOTEST_FRR="$(pwd)"
+fi
+
+if [ -z "$TOPOTEST_BUILDCACHE" ]; then
+       TOPOTEST_BUILDCACHE=topotest-buildcache
+       docker volume inspect "${TOPOTEST_BUILDCACHE}" &> /dev/null \
+               || docker volume create "${TOPOTEST_BUILDCACHE}"
+fi
+
+if [ -z "$TOPOTEST_PATH" ]; then
+       docker run --rm -ti \
+               -v "$TOPOTEST_LOGS:/tmp" \
+               -v "$TOPOTEST_FRR:/root/frr:ro" \
+               -v "$TOPOTEST_BUILDCACHE:/root/frr-build" \
+               --privileged \
+               $TOPOTEST_OPTIONS \
+               frrouting/topotests "$@"
+else
+       docker run --rm -ti \
+               -v "$TOPOTEST_LOGS:/tmp" \
+               -v "$TOPOTEST_FRR:/root/frr:ro" \
+               -v "$TOPOTEST_BUILDCACHE:/root/frr-build" \
+               -v "$TOPOTEST_PATH:/root/topotests:ro" \
+               --privileged \
+               $TOPOTEST_OPTIONS \
+               frrouting/topotests "$@"
+fi