From: Christian Franke Date: Thu, 18 Oct 2018 09:56:20 +0000 (+0200) Subject: Docker: Call the run script frr-topotests.sh X-Git-Tag: frr-7.1-dev~144^2~13 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d9e887de2a24635677672a9d57c9da3ccd1acc65;p=matthieu%2Ffrr.git Docker: Call the run script frr-topotests.sh Signed-off-by: Christian Franke --- diff --git a/tests/topotests/docker/README.md b/tests/topotests/docker/README.md index d126ca4559..b506fd6fb1 100644 --- a/tests/topotests/docker/README.md +++ b/tests/topotests/docker/README.md @@ -1,23 +1,21 @@ # Topotests in Docker -This is folder contains auxiliary scripts to automate or help deploying -topology tests under Docker on a standardized Ubuntu environment. +## Usage -Files description: +If you have Docker installed, you can run the topotests in Docker. +The easiest way to do this, is to use the `frr-topotests.sh` script +from this repository: -* _funcs.sh_: shared bash code -* _docker.sh_: builds docker image to run topotests -* _compile_frr.sh_: compile FRR sources (should be used by `topotests_run.sh`) -* _topotests_run.sh_: runs topotest image with the selected command +```console +wget -O /usr/local/bin/frr-topotests \ + https://raw.githubusercontent.com/frrouting/topotests/master/docker/frr-topotests.sh +chmod +x /usr/local/bin/frr-topotests +``` -## Running Topotests in Docker +Once this script is in place, simply run it while you are inside your FRR repository: -All you need to run topotests in Docker is: +``` +frr-topotests +``` -* Have Docker installed (tested against docker-ce[1]) -* Build the topotest images -* Have the FRR/Topotest sources cloned in your machine - -Review and configure your sources folder in `topotests_run.sh`. - -[1]: https://docs.docker.com/install/linux/docker-ce/ubuntu/ +It should build FRR inside of the container and run the topotests on it. diff --git a/tests/topotests/docker/frr-topotests.sh b/tests/topotests/docker/frr-topotests.sh new file mode 100755 index 0000000000..e5e91156a5 --- /dev/null +++ b/tests/topotests/docker/frr-topotests.sh @@ -0,0 +1,133 @@ +#!/bin/bash +# +# Copyright 2018 Network Device Education Foundation, Inc. ("NetDEF") +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +set -e + +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. +# +# 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. +# + +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 + +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 + +set -- --rm -ti \ + -v "$TOPOTEST_LOGS:/tmp" \ + -v "$TOPOTEST_FRR:/root/host-frr:ro" \ + -v "$TOPOTEST_BUILDCACHE:/root/persist" \ + -e "TOPOTEST_CLEAN=$TOPOTEST_CLEAN" \ + -e "TOPOTEST_VERBOSE=$TOPOTEST_VERBOSE" \ + -e "TOPOTEST_DOC=$TOPOTEST_DOC" \ + -e "TOPOTEST_SANITIZER=$TOPOTEST_SANITIZER" \ + --privileged \ + $TOPOTEST_OPTIONS \ + frrouting/topotests "$@" + +if [ -n "TOPOTEST_PATH" ]; then + set -- -v "$TOPOTEST_PATH:/root/topotests:ro" "$@" +fi + +exec docker run "$@" diff --git a/tests/topotests/docker/topotests_run.sh b/tests/topotests/docker/topotests_run.sh deleted file mode 100755 index e5e91156a5..0000000000 --- a/tests/topotests/docker/topotests_run.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash -# -# Copyright 2018 Network Device Education Foundation, Inc. ("NetDEF") -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -set -e - -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. -# -# 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. -# - -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 - -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 - -set -- --rm -ti \ - -v "$TOPOTEST_LOGS:/tmp" \ - -v "$TOPOTEST_FRR:/root/host-frr:ro" \ - -v "$TOPOTEST_BUILDCACHE:/root/persist" \ - -e "TOPOTEST_CLEAN=$TOPOTEST_CLEAN" \ - -e "TOPOTEST_VERBOSE=$TOPOTEST_VERBOSE" \ - -e "TOPOTEST_DOC=$TOPOTEST_DOC" \ - -e "TOPOTEST_SANITIZER=$TOPOTEST_SANITIZER" \ - --privileged \ - $TOPOTEST_OPTIONS \ - frrouting/topotests "$@" - -if [ -n "TOPOTEST_PATH" ]; then - set -- -v "$TOPOTEST_PATH:/root/topotests:ro" "$@" -fi - -exec docker run "$@"