diff mbox series

[iproute2,v2,4/4] testsuite: remove gre kmods if the test loads them

Message ID 20181216134727.8342-4-bluca@debian.org
State Superseded, archived
Delegated to: stephen hemminger
Headers show
Series [iproute2,v2,1/4] Makefile: have check target depend on all | expand

Commit Message

Luca Boccassi Dec. 16, 2018, 1:47 p.m. UTC
The tunnel test leaves behind link devices created by the GRE kernel
modules:

$ ip -br link
...
gre0@NONE    DOWN 0.0.0.0 <NOARP>
gretap0@NONE DOWN 00:00:00:00:00:00 <BROADCAST,MULTICAST>
erspan0@NONE DOWN 00:00:00:00:00:00 <BROADCAST,MULTICAST>
ip6tnl0@NONE DOWN :: <NOARP>
ip6gre0@NONE DOWN 00:00:00:00:

$ lsmod | grep gre
ip6_gre      40960  0
ip6_tunnel   40960  1 ip6_gre
ip_gre       32768  0
ip_tunnel    24576  1 ip_gre
gre          16384  2 ip6_gre,ip_gre

Check beforehand if the gre kernel module is loaded, and if not unload
them all at the end of the test. This should avoid causing problems if
a user is already using GRE for other purposes.

Signed-off-by: Luca Boccassi <bluca@debian.org>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
v2: applied suggestions from Petr to simplify the modules parsing/unloading

 testsuite/tests/ip/tunnel/add_tunnel.t | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Petr Vorel Dec. 16, 2018, 8:21 p.m. UTC | #1
Hi Luca,

Reviewed-by: Petr Vorel <pvorel@suse.cz>
LGTM, but I'd suggest 2 small changes (see bellow).

> +++ b/testsuite/tests/ip/tunnel/add_tunnel.t

>  TUNNEL_NAME="tunnel_test_ip"
I'd put KMODS here:
KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"

The reason is maintenance of this script - maybe one day there will be other
modules needed to be added, take this list as a configuration (which is usually
in shell scripts in the top).
BTW Maintenance was reason why I didn't like duplicity in modules you had in v1.

> +# unload kernel modules to remove dummy interfaces only if they were not in use beforehand
> +KMODS_REMOVE=
As a side effect, this could be lower case (showing it's not a configuration
variable, but just normal variable).

> +# note that checkbashism reports command -v, but dash supports it and it's POSIX 2008 compliant
> +if command -v lsmod >/dev/null 2>&1 && command -v rmmod >/dev/null 2>&1; then
> +    KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"
> +    for i in $KMODS; do
> +        lsmod | grep -q "^$i" || KMODS_REMOVE="$KMODS_REMOVE $i";
> +    done
> +fi
> +
>  ts_log "[Testing add/del tunnels]"

>  ts_ip "$0" "Add GRE tunnel over IPv4" tunnel add name $TUNNEL_NAME mode gre local 1.1.1.1 remote 2.2.2.2
> @@ -12,3 +22,6 @@ ts_ip "$0" "Del GRE tunnel over IPv4" tunnel del $TUNNEL_NAME
>  ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2
>  ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME

> +for mod in $KMODS_REMOVE; do
> +    sudo rmmod "$mod"
> +done

Kind regards,
Petr
Luca Boccassi Dec. 16, 2018, 8:57 p.m. UTC | #2
On Sun, 2018-12-16 at 21:21 +0100, Petr Vorel wrote:
> Hi Luca,
> 
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> LGTM, but I'd suggest 2 small changes (see bellow).
> 
> > +++ b/testsuite/tests/ip/tunnel/add_tunnel.t
> >  TUNNEL_NAME="tunnel_test_ip"
> 
> I'd put KMODS here:
> KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"
> 
> The reason is maintenance of this script - maybe one day there will
> be other
> modules needed to be added, take this list as a configuration (which
> is usually
> in shell scripts in the top).
> BTW Maintenance was reason why I didn't like duplicity in modules you
> had in v1.
> 
> > +# unload kernel modules to remove dummy interfaces only if they
> > were not in use beforehand
> > +KMODS_REMOVE=
> 
> As a side effect, this could be lower case (showing it's not a
> configuration
> variable, but just normal variable).

Ok, thanks, done both in v3.
diff mbox series

Patch

diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t
index 3f5a9d3c..78c1e463 100755
--- a/testsuite/tests/ip/tunnel/add_tunnel.t
+++ b/testsuite/tests/ip/tunnel/add_tunnel.t
@@ -4,6 +4,16 @@ 
 
 TUNNEL_NAME="tunnel_test_ip"
 
+# unload kernel modules to remove dummy interfaces only if they were not in use beforehand
+KMODS_REMOVE=
+# note that checkbashism reports command -v, but dash supports it and it's POSIX 2008 compliant
+if command -v lsmod >/dev/null 2>&1 && command -v rmmod >/dev/null 2>&1; then
+    KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"
+    for i in $KMODS; do
+        lsmod | grep -q "^$i" || KMODS_REMOVE="$KMODS_REMOVE $i";
+    done
+fi
+
 ts_log "[Testing add/del tunnels]"
 
 ts_ip "$0" "Add GRE tunnel over IPv4" tunnel add name $TUNNEL_NAME mode gre local 1.1.1.1 remote 2.2.2.2
@@ -12,3 +22,6 @@  ts_ip "$0" "Del GRE tunnel over IPv4" tunnel del $TUNNEL_NAME
 ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2
 ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME
 
+for mod in $KMODS_REMOVE; do
+    sudo rmmod "$mod"
+done