]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/docker/frr-topotests.sh
tests: point topotests docker img to new location
[mirror_frr.git] / tests / topotests / docker / frr-topotests.sh
CommitLineData
1e9c095c
RZ
1#!/bin/bash
2#
3# Copyright 2018 Network Device Education Foundation, Inc. ("NetDEF")
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sublicense, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24
c12ec855 25set -e
1e9c095c 26
c12ec855
CF
27if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
28 cat >&2 <<-EOF
1e9c095c 29
c12ec855
CF
30 This script runs the FRRouting topotests on the FRR tree
31 in the current working directory.
1e9c095c 32
c12ec855
CF
33 Usage: $0 [args...]
34
9b5470a8
CF
35 If any arguments are provided and the first argument starts with / or ./
36 the arguments are interpreted as command and will be executed instead
37 of pytest.
38
39 Behavior can be further modified by the following environment variables:
c12ec855
CF
40
41 TOPOTEST_AUTOLOAD If set to 1, the script will try to load necessary
42 kernel modules without asking for confirmation first.
43
44 TOPOTEST_BUILDCACHE Docker volume used for caching multiple FRR builds
45 over container runs. By default a
46 \`topotest-buildcache\` volume will be created for
47 that purpose.
48
877d4e36
CF
49 TOPOTEST_CLEAN Clean all previous build artifacts prior to
50 building. Disabled by default, set to 1 to enable.
51
52 TOPOTEST_DOC Build the documentation associated with FRR.
53 Disabled by default, set to 1 to enable.
54
c12ec855
CF
55 TOPOTEST_FRR If set, don't test the FRR in the current working
56 directory, but the one at the given path.
57
58 TOPOTEST_LOGS If set, don't use \`/tmp/topotest_logs\` directory
59 but use the provided path instead.
60
61 TOPOTEST_OPTIONS These options are appended to the docker-run
62 command for starting the tests.
63
cffe9e34
CF
64 TOPOTEST_PULL If set to 0, don't try to pull the most recent
65 version of the docker image from dockerhub.
66
877d4e36
CF
67 TOPOTEST_SANITIZER Controls whether to use the address sanitizer.
68 Enabled by default, set to 0 to disable.
69
70 TOPOTEST_VERBOSE Show detailed build output.
71 Enabled by default, set to 0 to disable.
72
c12ec855
CF
73 EOF
74 exit 1
75fi
76
77#
78# These two modules are needed to run the MPLS tests.
79# They are often not automatically loaded.
1e9c095c 80#
c12ec855
CF
81# We cannot load them from the container since we don't
82# have host kernel modules available there. If we load
83# them from the host however, they can be used just fine.
1e9c095c 84#
c12ec855 85
464e85c8
CF
86export PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin"
87
c12ec855
CF
88for module in mpls-router mpls-iptunnel; do
89 if modprobe -n $module 2> /dev/null; then
90 :
91 else
92 # If the module doesn't exist, we cannot do anything about it
93 continue
94 fi
95
96 if [ $(grep -c ${module/-/_} /proc/modules) -ne 0 ]; then
97 # If the module is loaded, we don't have to do anything
98 continue
99 fi
100
101 if [ "$TOPOTEST_AUTOLOAD" != "1" ]; then
102 echo "To run all the possible tests, we need to load $module."
103 echo -n "Do you want to proceed? [y/n] "
104 read answer
105 if [ x"$answer" != x"y" ]; then
106 echo "Not loading."
107 continue
108 fi
109 fi
110
111 if [ x"$(whoami)" = x"root" ]; then
112 modprobe $module
113 else
114 sudo modprobe $module
115 fi
116done
117
118if [ -z "$TOPOTEST_LOGS" ]; then
119 mkdir -p /tmp/topotest_logs
120 TOPOTEST_LOGS="/tmp/topotest_logs"
1e9c095c
RZ
121fi
122
c12ec855 123if [ -z "$TOPOTEST_FRR" ]; then
3311145d
CF
124 TOPOTEST_FRR="$(git rev-parse --show-toplevel || true)"
125 if [ -z "$TOPOTEST_FRR" ]; then
126 echo "Could not determine base of FRR tree." >&2
127 echo "frr-topotests only works if you have your tree in git." >&2
128 exit 1
129 fi
c12ec855
CF
130fi
131
132if [ -z "$TOPOTEST_BUILDCACHE" ]; then
133 TOPOTEST_BUILDCACHE=topotest-buildcache
134 docker volume inspect "${TOPOTEST_BUILDCACHE}" &> /dev/null \
135 || docker volume create "${TOPOTEST_BUILDCACHE}"
136fi
137
cffe9e34 138if [ "${TOPOTEST_PULL:-1}" = "1" ]; then
2e73695a 139 docker pull frrouting/topotests:latest
cffe9e34
CF
140fi
141
5f1ac6d6 142set -- --rm -i \
7b75f8cc
CF
143 -v "$TOPOTEST_LOGS:/tmp" \
144 -v "$TOPOTEST_FRR:/root/host-frr:ro" \
145 -v "$TOPOTEST_BUILDCACHE:/root/persist" \
146 -e "TOPOTEST_CLEAN=$TOPOTEST_CLEAN" \
147 -e "TOPOTEST_VERBOSE=$TOPOTEST_VERBOSE" \
148 -e "TOPOTEST_DOC=$TOPOTEST_DOC" \
149 -e "TOPOTEST_SANITIZER=$TOPOTEST_SANITIZER" \
150 --privileged \
151 $TOPOTEST_OPTIONS \
2e73695a 152 frrouting/topotests:latest "$@"
7b75f8cc 153
5f1ac6d6
CF
154if [ -t 0 ]; then
155 set -- -t "$@"
156fi
157
7b75f8cc 158exec docker run "$@"