[PATCH conntrack-tools] tests: conntrackd: move basic netns scenario setup to shell script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows for running the script away from the test infrastructure,
which is convenient when developing new tests. This also allows for
reusing the same netns setup from new tests.

Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
---
 tests/conntrackd/scenarios.yaml               | 29 +--------
 .../scenarios/basic/network-setup.sh          | 59 +++++++++++++++++++
 2 files changed, 61 insertions(+), 27 deletions(-)
 create mode 100755 tests/conntrackd/scenarios/basic/network-setup.sh

diff --git a/tests/conntrackd/scenarios.yaml b/tests/conntrackd/scenarios.yaml
index 798d9ebafece..6c425d04c64e 100644
--- a/tests/conntrackd/scenarios.yaml
+++ b/tests/conntrackd/scenarios.yaml
@@ -20,29 +20,7 @@
 
 - name: basic_2_peer_network_tcp_notrack
   start:
-    - ip netns add ns1
-    - ip netns add ns2
-    - ip netns add nsr1
-    - ip netns add nsr2
-    - ip link add veth0 netns ns1 type veth peer name veth1 netns nsr1
-    - ip link add veth0 netns nsr1 type veth peer name veth0 netns ns2
-    - ip link add veth2 netns nsr1 type veth peer name veth0 netns nsr2
-    - ip -net ns1 addr add 192.168.10.2/24 dev veth0
-    - ip -net ns1 link set up dev veth0
-    - ip -net ns1 ro add 10.0.1.0/24 via 192.168.10.1 dev veth0
-    - ip -net nsr1 addr add 10.0.1.1/24 dev veth0
-    - ip -net nsr1 addr add 192.168.10.1/24 dev veth1
-    - ip -net nsr1 link set up dev veth0
-    - ip -net nsr1 link set up dev veth1
-    - ip -net nsr1 route add default via 192.168.10.2
-    - ip netns exec nsr1 sysctl -q net.ipv4.ip_forward=1
-    - ip -net nsr1 addr add 192.168.100.2/24 dev veth2
-    - ip -net nsr1 link set up dev veth2
-    - ip -net nsr2 addr add 192.168.100.3/24 dev veth0
-    - ip -net nsr2 link set up dev veth0
-    - ip -net ns2 addr add 10.0.1.2/24 dev veth0
-    - ip -net ns2 link set up dev veth0
-    - ip -net ns2 route add default via 10.0.1.1
+    - scenarios/basic/./network-setup.sh start
     - |
       cat << EOF > /tmp/ruleset.nft
       table ip filter {
@@ -114,7 +92,4 @@
     - $CONNTRACKD -C /tmp/nsr2.conf -k 2>/dev/null
     - rm -f /tmp/ruleset.nft /tmp/nsr2.conf /tmp/nsr1.conf
     - rm -f /var/lock/conntrack-nsr1.lock /var/lock/conntrack-nsr2.lock
-    - ip netns del ns1 || true
-    - ip netns del ns2 || true
-    - ip netns del nsr1 || true
-    - ip netns del nsr2 || true
+    - scenarios/basic/./network-setup.sh stop
diff --git a/tests/conntrackd/scenarios/basic/network-setup.sh b/tests/conntrackd/scenarios/basic/network-setup.sh
new file mode 100755
index 000000000000..ff8df26d6a1e
--- /dev/null
+++ b/tests/conntrackd/scenarios/basic/network-setup.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+if [ $UID -ne 0 ]
+then
+	echo "You must be root to run this test script"
+	exit 0
+fi
+
+start () {
+	ip netns add ns1
+	ip netns add ns2
+	ip netns add nsr1
+	ip netns add nsr2
+
+	ip link add veth0 netns ns1 type veth peer name veth1 netns nsr1
+	ip link add veth0 netns nsr1 type veth peer name veth0 netns ns2
+	ip link add veth2 netns nsr1 type veth peer name veth0 netns nsr2
+
+	ip -net ns1 addr add 192.168.10.2/24 dev veth0
+	ip -net ns1 link set up dev veth0
+	ip -net ns1 ro add 10.0.1.0/24 via 192.168.10.1 dev veth0
+
+	ip -net nsr1 addr add 10.0.1.1/24 dev veth0
+	ip -net nsr1 addr add 192.168.10.1/24 dev veth1
+	ip -net nsr1 link set up dev veth0
+	ip -net nsr1 link set up dev veth1
+	ip -net nsr1 route add default via 192.168.10.2
+	ip netns exec nsr1 sysctl net.ipv4.ip_forward=1
+
+	ip -net nsr1 addr add 192.168.100.2/24 dev veth2
+	ip -net nsr1 link set up dev veth2
+	ip -net nsr2 addr add 192.168.100.3/24 dev veth0
+	ip -net nsr2 link set up dev veth0
+
+	ip -net ns2 addr add 10.0.1.2/24 dev veth0
+	ip -net ns2 link set up dev veth0
+	ip -net ns2 route add default via 10.0.1.1
+}
+
+stop () {
+	ip netns del ns1
+	ip netns del ns2
+	ip netns del nsr1
+	ip netns del nsr2
+}
+
+case $1 in
+start)
+	start
+	;;
+stop)
+	stop
+	;;
+*)
+	echo "$0 [start|stop]"
+	;;
+esac
+
+exit 0
-- 
2.20.1




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux