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