Commit ee395a5e authored by David Ahern's avatar David Ahern Committed by David S. Miller

selftests: fib_tests: Move admin of dummy0 to helpers

Move setup and teardown of testns and dummy0 to helpers.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1056691b
...@@ -28,12 +28,24 @@ log_test() ...@@ -28,12 +28,24 @@ log_test()
fi fi
} }
netns_create() setup()
{ {
local testns=$1 set -e
ip netns add testns
ip -netns testns link set dev lo up
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
set +e
}
ip netns add $testns cleanup()
ip netns exec $testns ip link set dev lo up {
ip -netns testns link del dev dummy0 &> /dev/null
ip netns del testns
} }
fib_unreg_unicast_test() fib_unreg_unicast_test()
...@@ -41,14 +53,7 @@ fib_unreg_unicast_test() ...@@ -41,14 +53,7 @@ fib_unreg_unicast_test()
echo echo
echo "Single path route test" echo "Single path route test"
set -e setup
netns_create "testns"
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
set +e
echo " Start point" echo " Start point"
ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
...@@ -66,7 +71,7 @@ fib_unreg_unicast_test() ...@@ -66,7 +71,7 @@ fib_unreg_unicast_test()
ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
log_test $? 2 "IPv6 fibmatch - no route" log_test $? 2 "IPv6 fibmatch - no route"
ip netns del testns cleanup
} }
fib_unreg_multipath_test() fib_unreg_multipath_test()
...@@ -75,18 +80,11 @@ fib_unreg_multipath_test() ...@@ -75,18 +80,11 @@ fib_unreg_multipath_test()
echo echo
echo "Multipath route test" echo "Multipath route test"
set -e setup
netns_create "testns"
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
set -e
ip -netns testns link add dummy1 type dummy ip -netns testns link add dummy1 type dummy
ip -netns testns link set dev dummy1 up ip -netns testns link set dev dummy1 up
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
ip -netns testns address add 192.0.2.1/24 dev dummy1 ip -netns testns address add 192.0.2.1/24 dev dummy1
ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1
...@@ -124,7 +122,7 @@ fib_unreg_multipath_test() ...@@ -124,7 +122,7 @@ fib_unreg_multipath_test()
ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
log_test $? 2 "IPv6 - no route" log_test $? 2 "IPv6 - no route"
ip netns del testns cleanup
} }
fib_unreg_test() fib_unreg_test()
...@@ -138,15 +136,7 @@ fib_down_unicast_test() ...@@ -138,15 +136,7 @@ fib_down_unicast_test()
echo echo
echo "Single path, admin down" echo "Single path, admin down"
set -e setup
netns_create "testns"
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
set +e
echo " Start point" echo " Start point"
ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
...@@ -164,9 +154,7 @@ fib_down_unicast_test() ...@@ -164,9 +154,7 @@ fib_down_unicast_test()
ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
log_test $? 2 "IPv6 fibmatch" log_test $? 2 "IPv6 fibmatch"
ip -netns testns link del dev dummy0 cleanup
ip netns del testns
} }
fib_down_multipath_test_do() fib_down_multipath_test_do()
...@@ -208,18 +196,12 @@ fib_down_multipath_test() ...@@ -208,18 +196,12 @@ fib_down_multipath_test()
echo echo
echo "Admin down multipath" echo "Admin down multipath"
set -e setup
netns_create "testns"
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
set -e
ip -netns testns link add dummy1 type dummy ip -netns testns link add dummy1 type dummy
ip -netns testns link set dev dummy1 up ip -netns testns link set dev dummy1 up
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
ip -netns testns address add 192.0.2.1/24 dev dummy1 ip -netns testns address add 192.0.2.1/24 dev dummy1
ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1
...@@ -264,8 +246,7 @@ fib_down_multipath_test() ...@@ -264,8 +246,7 @@ fib_down_multipath_test()
log_test $? 2 "IPv6 fibmatch" log_test $? 2 "IPv6 fibmatch"
ip -netns testns link del dev dummy1 ip -netns testns link del dev dummy1
ip -netns testns link del dev dummy0 cleanup
ip netns del testns
} }
fib_down_test() fib_down_test()
...@@ -280,16 +261,10 @@ fib_carrier_local_test() ...@@ -280,16 +261,10 @@ fib_carrier_local_test()
echo echo
echo "Local carrier tests - single path" echo "Local carrier tests - single path"
set -e setup
netns_create "testns"
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
set -e
ip -netns testns link set dev dummy0 carrier on ip -netns testns link set dev dummy0 carrier on
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
set +e set +e
echo " Start point" echo " Start point"
...@@ -340,9 +315,7 @@ fib_carrier_local_test() ...@@ -340,9 +315,7 @@ fib_carrier_local_test()
grep -q "linkdown" grep -q "linkdown"
log_test $? 1 "IPv6 linkdown flag set" log_test $? 1 "IPv6 linkdown flag set"
ip -netns testns link del dev dummy0 cleanup
ip netns del testns
} }
fib_carrier_unicast_test() fib_carrier_unicast_test()
...@@ -352,16 +325,10 @@ fib_carrier_unicast_test() ...@@ -352,16 +325,10 @@ fib_carrier_unicast_test()
echo echo
echo "Single path route carrier test" echo "Single path route carrier test"
netns_create "testns" setup
set -e set -e
ip -netns testns link add dummy0 type dummy
ip -netns testns link set dev dummy0 up
ip -netns testns link set dev dummy0 carrier on ip -netns testns link set dev dummy0 carrier on
ip -netns testns address add 198.51.100.1/24 dev dummy0
ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
set +e set +e
echo " Start point" echo " Start point"
...@@ -412,9 +379,7 @@ fib_carrier_unicast_test() ...@@ -412,9 +379,7 @@ fib_carrier_unicast_test()
grep -q "linkdown" grep -q "linkdown"
log_test $? 0 "IPv6 linkdown flag set" log_test $? 0 "IPv6 linkdown flag set"
ip -netns testns link del dev dummy0 cleanup
ip netns del testns
} }
fib_carrier_test() fib_carrier_test()
...@@ -446,6 +411,9 @@ if [ $? -ne 0 ]; then ...@@ -446,6 +411,9 @@ if [ $? -ne 0 ]; then
exit 0 exit 0
fi fi
# start clean
cleanup &> /dev/null
fib_test fib_test
exit $ret exit $ret
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment