]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: cleanup creating dummy interfaces in tests
authorThomas Haller <thaller@redhat.com>
Fri, 15 Sep 2023 15:54:00 +0000 (17:54 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 18 Sep 2023 10:11:00 +0000 (12:11 +0200)
In "tests/shell/testcases/chains/netdev_chain_0", calling "trap ...
EXIT" multiple times does not work. Fix it, by calling one cleanup
function.

Note that we run in separate namespaces, so the cleanup is usually not
necessary. Still do it, we might want to run without unshare (via
NFT_TEST_UNSHARE_CMD=""). Without unshare, it's important that the
cleanup always works. In practice it might not, for example, "trap ...
EXIT" does not run for SIGTERM. A leaked interface might break the
follow up test and tests interfere with each other.

Try to workaround that by first trying to delete the interface.

Also failures to create the interfaces are not considered fatal. I don't
understand under what circumstances this might fail, note that there are
other tests that create dummy interface and don't "exit 77" on failure.
We want to know when something odd is going on.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/testcases/chains/dumps/netdev_chain_0.nft
tests/shell/testcases/chains/netdev_chain_0
tests/shell/testcases/flowtable/0012flowtable_variable_0
tests/shell/testcases/flowtable/dumps/0012flowtable_variable_0.nft
tests/shell/testcases/json/netdev
tests/shell/testcases/listing/0020flowtable_0

index bc02dc18692daea4d906746782a57f19a6d9f2f4..aa571e00885fe18e03eb5550b5a2e248361a938c 100644 (file)
@@ -1,5 +1,2 @@
 table netdev x {
-       chain y {
-               type filter hook ingress devices = { d0, d1 } priority filter; policy accept;
-       }
 }
index 41e724413528528ca181fae44e7cdead0c526009..88bbc437d47143196a7b96641d7b84003606bcb0 100755 (executable)
@@ -1,24 +1,18 @@
 #!/bin/bash
 
-ip link add d0 type dummy || {
-        echo "Skipping, no dummy interface available"
-        exit 77
-}
-trap "ip link del d0" EXIT
-
-ip link add d1 type dummy || {
-        echo "Skipping, no dummy interface available"
-        exit 77
-}
-trap "ip link del d1" EXIT
+set -e
 
-ip link add d2 type dummy || {
-        echo "Skipping, no dummy interface available"
-        exit 77
+iface_cleanup() {
+       ip link del d0 &>/dev/null || :
+       ip link del d1 &>/dev/null || :
+       ip link del d2 &>/dev/null || :
 }
-trap "ip link del d2" EXIT
+trap 'iface_cleanup' EXIT
+iface_cleanup
 
-set -e
+ip link add d0 type dummy
+ip link add d1 type dummy
+ip link add d2 type dummy
 
 RULESET="table netdev x {
        chain y {
index 8e334224ac66f2039b02f9f38a1f8f724954c29c..080059d249357fa2d270355e3a7973c19373d388 100755 (executable)
@@ -2,6 +2,12 @@
 
 set -e
 
+iface_cleanup() {
+       ip link del dummy1 &>/dev/null || :
+}
+trap 'iface_cleanup' EXIT
+iface_cleanup
+
 ip link add name dummy1 type dummy
 
 EXPECTED="define if_main = { lo, dummy1 }
index 1cbb2f1103f03eb07b4fb0974283caa798c8e3e1..df1c51a247033aa58aaf96d841bac7783953a3ee 100644 (file)
@@ -1,14 +1,14 @@
 table ip filter1 {
        flowtable Main_ft1 {
                hook ingress priority filter
-               devices = { dummy1, lo }
+               devices = { lo }
                counter
        }
 }
 table ip filter2 {
        flowtable Main_ft2 {
                hook ingress priority filter
-               devices = { dummy1, lo }
+               devices = { lo }
                counter
        }
 }
index dad7afcdc020f1d545a81b6c6777f1c09dd6659b..8c16cf42baa069d4059fc9ea133db69f3f3441f5 100755 (executable)
@@ -1,12 +1,14 @@
 #!/bin/bash
 
-ip link add d0 type dummy || {
-        echo "Skipping, no dummy interface available"
-        exit 77
+set -e
+
+iface_cleanup() {
+       ip link del d0 &>/dev/null || :
 }
-trap "ip link del d0" EXIT
+trap 'iface_cleanup' EXIT
+iface_cleanup
 
-set -e
+ip link add d0 type dummy
 
 $NFT flush ruleset
 $NFT add table inet test
index 210289d70415c2427849f410921d6b504eecbef4..6eb82cfeabc35c2ebad1ef61275e70a7ca46b22a 100755 (executable)
@@ -2,6 +2,8 @@
 
 # list only the flowtable asked for with table
 
+set -e
+
 FLOWTABLES="flowtable f {
        hook ingress priority filter
        devices = { lo }
@@ -41,13 +43,13 @@ EXPECTED3="table ip filter {
        }
 }"
 
-ip link add d0 type dummy || {
-       echo "Skipping, no dummy interface available"
-       exit 77
+iface_cleanup() {
+       ip link del d0 &>/dev/null || :
 }
-trap "ip link del d0" EXIT
+trap 'iface_cleanup' EXIT
+iface_cleanup
 
-set -e
+ip link add d0 type dummy
 
 $NFT -f - <<< "$RULESET"