All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH conntrack-tools] tests: conntrackd: move basic netns scenario setup to shell script
@ 2021-02-01 17:00 Pablo Neira Ayuso
  2021-02-02 10:23 ` Arturo Borrero Gonzalez
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2021-02-01 17:00 UTC (permalink / raw)
  To: netfilter-devel; +Cc: arturo

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@netfilter.org>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH conntrack-tools] tests: conntrackd: move basic netns scenario setup to shell script
  2021-02-01 17:00 [PATCH conntrack-tools] tests: conntrackd: move basic netns scenario setup to shell script Pablo Neira Ayuso
@ 2021-02-02 10:23 ` Arturo Borrero Gonzalez
  0 siblings, 0 replies; 2+ messages in thread
From: Arturo Borrero Gonzalez @ 2021-02-02 10:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel

On 2/1/21 6:00 PM, Pablo Neira Ayuso wrote:
> 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@netfilter.org>
> ---
>   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
> 

Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-02 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 17:00 [PATCH conntrack-tools] tests: conntrackd: move basic netns scenario setup to shell script Pablo Neira Ayuso
2021-02-02 10:23 ` Arturo Borrero Gonzalez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.