]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/docker/frr-topotests.sh
Merge pull request #8956 from pguibert6WIND/bgp_loop_through_itself
[mirror_frr.git] / tests / topotests / docker / frr-topotests.sh
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
25 set -e
26
27 if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
28 cat >&2 <<-EOF
29
30 This script runs the FRRouting topotests on the FRR tree
31 in the current working directory.
32
33 Usage: $0 [args...]
34
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:
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_NOLOAD If set to 1, don't try to load necessary kernel
45 modules and don't even ask.
46
47 TOPOTEST_BUILDCACHE Docker volume used for caching multiple FRR builds
48 over container runs. By default a
49 \`topotest-buildcache\` volume will be created for
50 that purpose.
51
52 TOPOTEST_CLEAN Clean all previous build artifacts prior to
53 building. Disabled by default, set to 1 to enable.
54
55 TOPOTEST_DOC Build the documentation associated with FRR.
56 Disabled by default, set to 1 to enable.
57
58 TOPOTEST_FRR If set, don't test the FRR in the current working
59 directory, but the one at the given path.
60
61 TOPOTEST_LOGS If set, don't use \`/tmp/topotest_logs\` directory
62 but use the provided path instead.
63
64 TOPOTEST_OPTIONS These options are appended to the docker-run
65 command for starting the tests.
66
67 TOPOTEST_PULL If set to 0, don't try to pull the most recent
68 version of the docker image from dockerhub.
69
70 TOPOTEST_SANITIZER Controls whether to use the address sanitizer.
71 Enabled by default, set to 0 to disable.
72
73 TOPOTEST_VERBOSE Show detailed build output.
74 Enabled by default, set to 0 to disable.
75
76 EOF
77 exit 1
78 fi
79
80 #
81 # These two modules are needed to run the MPLS tests.
82 # They are often not automatically loaded.
83 #
84 # We cannot load them from the container since we don't
85 # have host kernel modules available there. If we load
86 # them from the host however, they can be used just fine.
87 #
88
89 export PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin"
90
91 if [ "$TOPOTEST_NOLOAD" != "1" ]; then
92 for module in mpls-router mpls-iptunnel; do
93 if modprobe -n $module 2> /dev/null; then
94 :
95 else
96 # If the module doesn't exist, we cannot do anything about it
97 continue
98 fi
99
100 if [ $(grep -c ${module/-/_} /proc/modules) -ne 0 ]; then
101 # If the module is loaded, we don't have to do anything
102 continue
103 fi
104
105 if [ "$TOPOTEST_AUTOLOAD" != "1" ]; then
106 echo "To run all the possible tests, we need to load $module."
107 echo -n "Do you want to proceed? [y/n] "
108 read answer
109 if [ x"$answer" != x"y" ]; then
110 echo "Not loading."
111 continue
112 fi
113 fi
114
115 if [ x"$(whoami)" = x"root" ]; then
116 modprobe $module
117 else
118 sudo modprobe $module
119 fi
120 done
121 fi
122
123 if [ -z "$TOPOTEST_LOGS" ]; then
124 mkdir -p /tmp/topotest_logs
125 TOPOTEST_LOGS="/tmp/topotest_logs"
126 fi
127
128 if [ -z "$TOPOTEST_FRR" ]; then
129 TOPOTEST_FRR="$(git rev-parse --show-toplevel || true)"
130 if [ -z "$TOPOTEST_FRR" ]; then
131 echo "Could not determine base of FRR tree." >&2
132 echo "frr-topotests only works if you have your tree in git." >&2
133 exit 1
134 fi
135 git -C "$TOPOTEST_FRR" ls-files -z > "${TOPOTEST_LOGS}/git-ls-files"
136 fi
137
138 if [ -z "$TOPOTEST_BUILDCACHE" ]; then
139 TOPOTEST_BUILDCACHE=topotest-buildcache
140 docker volume inspect "${TOPOTEST_BUILDCACHE}" &> /dev/null \
141 || docker volume create "${TOPOTEST_BUILDCACHE}"
142 fi
143
144 if [ "${TOPOTEST_PULL:-1}" = "1" ]; then
145 docker pull frrouting/topotests:latest
146 fi
147
148 if [[ -n "$TMUX" ]]; then
149 TMUX_OPTIONS="-v $(dirname $TMUX):$(dirname $TMUX) -e TMUX=$TMUX -e TMUX_PANE=$TMUX_PANE"
150 fi
151
152 if [[ -n "$STY" ]]; then
153 SCREEN_OPTIONS="-v /run/screen:/run/screen -e STY=$STY"
154 fi
155 set -- --rm -i \
156 -v "$HOME:$HOME:ro" \
157 -v "$TOPOTEST_LOGS:/tmp" \
158 -v "$TOPOTEST_FRR:/root/host-frr:ro" \
159 -v "$TOPOTEST_BUILDCACHE:/root/persist" \
160 -e "TOPOTEST_CLEAN=$TOPOTEST_CLEAN" \
161 -e "TOPOTEST_VERBOSE=$TOPOTEST_VERBOSE" \
162 -e "TOPOTEST_DOC=$TOPOTEST_DOC" \
163 -e "TOPOTEST_SANITIZER=$TOPOTEST_SANITIZER" \
164 --privileged \
165 $SCREEN_OPTINS \
166 $TMUX_OPTIONS \
167 $TOPOTEST_OPTIONS \
168 frrouting/topotests:latest "$@"
169
170 if [ -t 0 ]; then
171 set -- -t "$@"
172 fi
173
174 exec docker run "$@"