Re: [ovs-dev] [PATCH ovn branch-23.09 1/2] tests: Add helper for tcpdump.

2024-03-20 Thread Mark Michelson

Thanks Ales, I pushed this and patch 2 to branch-23.09.

On 3/20/24 06:16, Ales Musil wrote:

The way how tcpdump was called in tests was inconsistent,
a lot fo the tests didn't even wait for the tcpdump to properly
start, some of them didn't redirect the stderr which could cause
leak into the test stderr and fail the test.

To prevent that add macro that starts tcpdump and properly
waits for the "listening" state, at the same time redirects
the stderr into separate file.

Signed-off-by: Ales Musil 
Signed-off-by: Dumitru Ceara 
(cherry picked from commit e8ac18104df0bbd6579d8c62fd4282939631b878)
---
  tests/system-common-macros.at |  29 ++--
  tests/system-ovn-kmod.at  |  26 +--
  tests/system-ovn.at   | 312 ++
  3 files changed, 154 insertions(+), 213 deletions(-)

diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at
index 8fe93cbdb..683f15fe3 100644
--- a/tests/system-common-macros.at
+++ b/tests/system-common-macros.at
@@ -271,6 +271,18 @@ m4_define([OVS_START_L7],
 ]
  )
  
+# NETNS_START_TCPDUMP([namespace], [params], [name])

+#
+# Helper to properly start tcpdump and wait for the startup.
+# The tcpdump output is available in .tcpdump file.
+m4_define([NETNS_START_TCPDUMP],
+[
+ NETNS_DAEMONIZE([$1], [tcpdump -l $2 >$3.tcpdump 2>$3.stderr], [$3.pid])
+ OVS_WAIT_UNTIL([grep -q "listening" $3.stderr])
+]
+)
+
+
  # OVS_CHECK_VXLAN()
  #
  # Do basic check for vxlan functionality, skip the test if it's not there.
@@ -437,8 +449,7 @@ chown root:dhcpd /var/lib/dhcp /var/lib/dhcp/dhcpd6.leases
  chmod 775 /var/lib/dhcp
  chmod 664 /var/lib/dhcp/dhcpd6.leases
  
-NS_CHECK_EXEC([server], [tcpdump -nni s1 > pkt.pcap &])

-
+NETNS_START_TCPDUMP([server], [-nni s1], [server])
  NETNS_DAEMONIZE([server], [dhcpd -6 -f s1 > dhcpd.log 2>&1], [dhcpd.pid])
  ovn-nbctl --wait=hv sync
  
@@ -456,17 +467,17 @@ prefix=$(ovn-nbctl list logical_router_port rp-public | awk -F/ '/ipv6_prefix/{p

  ovn-nbctl list logical_router_port rp-public > /tmp/rp-public
  
  # Wait for 2 renew on each port.

-NS_CHECK_EXEC([server], [tcpdump -c 4 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix} > renew.pcap &])
+NETNS_START_TCPDUMP([server], [-c 4 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix}], [renew])
  # Reply message with Status OK
-NS_CHECK_EXEC([server], [tcpdump -c 4 -nni s1 ip6[[48:1]]=0x07 and 
ip6[[81:4]]=0x${prefix} > reply.pcap &])
+NETNS_START_TCPDUMP([server], [-c 4 -nni s1 ip6[[48:1]]=0x07 and 
ip6[[81:4]]=0x${prefix}], [reply])
  
  OVS_WAIT_UNTIL([

-total_pkts=$(cat renew.pcap | wc -l)
+total_pkts=$(cat renew.tcpdump | wc -l)
  test "${total_pkts}" = "4"
  ])
  
  OVS_WAIT_UNTIL([

-total_pkts=$(cat reply.pcap | wc -l)
+total_pkts=$(cat reply.tcpdump | wc -l)
  test "${total_pkts}" = "4"
  ])
  
@@ -474,7 +485,7 @@ ovn-nbctl set logical_router_port rp-public options:prefix=false

  ovn-nbctl set logical_router_port rp-sw0 options:prefix=false
  ovn-nbctl --wait=hv set logical_router_port rp-sw1 options:prefix=true
  sleep_sb
-NS_CHECK_EXEC([server], [tcpdump -c 2 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix} > renew.pcap &])
+NETNS_START_TCPDUMP([server], [-c 2 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix}], [renew2])
  
  # Sleep enough to have solicit and renew being sent, then wait for 2 renew.

  # The reply to the request will usually be received as sb is sleeping.
@@ -482,12 +493,10 @@ NS_CHECK_EXEC([server], [tcpdump -c 2 -nni s1 
ip6[[48:1]]=0x05 and ip6[[113:4]]=
  sleep 10
  wake_up_sb
  OVS_WAIT_UNTIL([
-total_pkts=$(cat renew.pcap | wc -l)
+total_pkts=$(cat renew2.tcpdump | wc -l)
  test "${total_pkts}" = "2"
  ])
  
-kill $(pidof tcpdump)

-
  ovn-nbctl set logical_router_port rp-sw0 options:prefix=false
  ovn-nbctl clear logical_router_port rp-sw0 ipv6_prefix
  OVS_WAIT_WHILE([test "$(ovn-nbctl get logical_router_port rp-sw0 ipv6_prefix | cut 
-c3-16)" = "[2001:1db8:]"])
diff --git a/tests/system-ovn-kmod.at b/tests/system-ovn-kmod.at
index 3a533d5e6..254a4b0a0 100644
--- a/tests/system-ovn-kmod.at
+++ b/tests/system-ovn-kmod.at
@@ -664,14 +664,11 @@ ovn-nbctl --wait=hv sync
  NETNS_DAEMONIZE([server], [nc -l -u 172.16.1.2 4242 > /dev/null], 
[server.pid])
  
  # Collect ICMP packets on client side

-NETNS_DAEMONIZE([client], [tcpdump -l -U -i client -vnne \
-icmp > client.pcap 2>client_err], [tcpdump0.pid])
-OVS_WAIT_UNTIL([grep "listening" client_err])
+NETNS_START_TCPDUMP([client], [-U -i client -vnne icmp], [tcpdump-client])
  
  # Collect UDP packets on server side

-NETNS_DAEMONIZE([server], [tcpdump -l -U -i server -vnne \
-'udp and ip[[6:2]] > 0 and not ip[[6]] = 64' > server.pcap 2>server_err], 
[tcpdump1.pid])
-OVS_WAIT_UNTIL([grep "listening" server_err])
+NETNS_START_TCPDUMP([server], [-U -i server -vnne \
+'udp and ip[[6:2]] > 0 and not ip[[6]] = 64'], [tcpdump-server])
  
  check ip netns exec client python3 << EOF

  import os
@@ 

Re: [ovs-dev] [PATCH ovn branch-23.09 1/2] tests: Add helper for tcpdump.

2024-03-20 Thread 0-day Robot
Bleep bloop.  Greetings Ales Musil, I am a robot and I have tried out your 
patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Unexpected sign-offs from developers who are not authors or co-authors 
or committers: Dumitru Ceara 
Lines checked: 1100, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email 
acon...@redhat.com

Thanks,
0-day Robot
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH ovn branch-23.09 1/2] tests: Add helper for tcpdump.

2024-03-20 Thread Ales Musil
The way how tcpdump was called in tests was inconsistent,
a lot fo the tests didn't even wait for the tcpdump to properly
start, some of them didn't redirect the stderr which could cause
leak into the test stderr and fail the test.

To prevent that add macro that starts tcpdump and properly
waits for the "listening" state, at the same time redirects
the stderr into separate file.

Signed-off-by: Ales Musil 
Signed-off-by: Dumitru Ceara 
(cherry picked from commit e8ac18104df0bbd6579d8c62fd4282939631b878)
---
 tests/system-common-macros.at |  29 ++--
 tests/system-ovn-kmod.at  |  26 +--
 tests/system-ovn.at   | 312 ++
 3 files changed, 154 insertions(+), 213 deletions(-)

diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at
index 8fe93cbdb..683f15fe3 100644
--- a/tests/system-common-macros.at
+++ b/tests/system-common-macros.at
@@ -271,6 +271,18 @@ m4_define([OVS_START_L7],
]
 )
 
+# NETNS_START_TCPDUMP([namespace], [params], [name])
+#
+# Helper to properly start tcpdump and wait for the startup.
+# The tcpdump output is available in .tcpdump file.
+m4_define([NETNS_START_TCPDUMP],
+[
+ NETNS_DAEMONIZE([$1], [tcpdump -l $2 >$3.tcpdump 2>$3.stderr], [$3.pid])
+ OVS_WAIT_UNTIL([grep -q "listening" $3.stderr])
+]
+)
+
+
 # OVS_CHECK_VXLAN()
 #
 # Do basic check for vxlan functionality, skip the test if it's not there.
@@ -437,8 +449,7 @@ chown root:dhcpd /var/lib/dhcp /var/lib/dhcp/dhcpd6.leases
 chmod 775 /var/lib/dhcp
 chmod 664 /var/lib/dhcp/dhcpd6.leases
 
-NS_CHECK_EXEC([server], [tcpdump -nni s1 > pkt.pcap &])
-
+NETNS_START_TCPDUMP([server], [-nni s1], [server])
 NETNS_DAEMONIZE([server], [dhcpd -6 -f s1 > dhcpd.log 2>&1], [dhcpd.pid])
 ovn-nbctl --wait=hv sync
 
@@ -456,17 +467,17 @@ prefix=$(ovn-nbctl list logical_router_port rp-public | 
awk -F/ '/ipv6_prefix/{p
 ovn-nbctl list logical_router_port rp-public > /tmp/rp-public
 
 # Wait for 2 renew on each port.
-NS_CHECK_EXEC([server], [tcpdump -c 4 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix} > renew.pcap &])
+NETNS_START_TCPDUMP([server], [-c 4 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix}], [renew])
 # Reply message with Status OK
-NS_CHECK_EXEC([server], [tcpdump -c 4 -nni s1 ip6[[48:1]]=0x07 and 
ip6[[81:4]]=0x${prefix} > reply.pcap &])
+NETNS_START_TCPDUMP([server], [-c 4 -nni s1 ip6[[48:1]]=0x07 and 
ip6[[81:4]]=0x${prefix}], [reply])
 
 OVS_WAIT_UNTIL([
-total_pkts=$(cat renew.pcap | wc -l)
+total_pkts=$(cat renew.tcpdump | wc -l)
 test "${total_pkts}" = "4"
 ])
 
 OVS_WAIT_UNTIL([
-total_pkts=$(cat reply.pcap | wc -l)
+total_pkts=$(cat reply.tcpdump | wc -l)
 test "${total_pkts}" = "4"
 ])
 
@@ -474,7 +485,7 @@ ovn-nbctl set logical_router_port rp-public 
options:prefix=false
 ovn-nbctl set logical_router_port rp-sw0 options:prefix=false
 ovn-nbctl --wait=hv set logical_router_port rp-sw1 options:prefix=true
 sleep_sb
-NS_CHECK_EXEC([server], [tcpdump -c 2 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix} > renew.pcap &])
+NETNS_START_TCPDUMP([server], [-c 2 -nni s1 ip6[[48:1]]=0x05 and 
ip6[[113:4]]=0x${prefix}], [renew2])
 
 # Sleep enough to have solicit and renew being sent, then wait for 2 renew.
 # The reply to the request will usually be received as sb is sleeping.
@@ -482,12 +493,10 @@ NS_CHECK_EXEC([server], [tcpdump -c 2 -nni s1 
ip6[[48:1]]=0x05 and ip6[[113:4]]=
 sleep 10
 wake_up_sb
 OVS_WAIT_UNTIL([
-total_pkts=$(cat renew.pcap | wc -l)
+total_pkts=$(cat renew2.tcpdump | wc -l)
 test "${total_pkts}" = "2"
 ])
 
-kill $(pidof tcpdump)
-
 ovn-nbctl set logical_router_port rp-sw0 options:prefix=false
 ovn-nbctl clear logical_router_port rp-sw0 ipv6_prefix
 OVS_WAIT_WHILE([test "$(ovn-nbctl get logical_router_port rp-sw0 ipv6_prefix | 
cut -c3-16)" = "[2001:1db8:]"])
diff --git a/tests/system-ovn-kmod.at b/tests/system-ovn-kmod.at
index 3a533d5e6..254a4b0a0 100644
--- a/tests/system-ovn-kmod.at
+++ b/tests/system-ovn-kmod.at
@@ -664,14 +664,11 @@ ovn-nbctl --wait=hv sync
 NETNS_DAEMONIZE([server], [nc -l -u 172.16.1.2 4242 > /dev/null], [server.pid])
 
 # Collect ICMP packets on client side
-NETNS_DAEMONIZE([client], [tcpdump -l -U -i client -vnne \
-icmp > client.pcap 2>client_err], [tcpdump0.pid])
-OVS_WAIT_UNTIL([grep "listening" client_err])
+NETNS_START_TCPDUMP([client], [-U -i client -vnne icmp], [tcpdump-client])
 
 # Collect UDP packets on server side
-NETNS_DAEMONIZE([server], [tcpdump -l -U -i server -vnne \
-'udp and ip[[6:2]] > 0 and not ip[[6]] = 64' > server.pcap 2>server_err], 
[tcpdump1.pid])
-OVS_WAIT_UNTIL([grep "listening" server_err])
+NETNS_START_TCPDUMP([server], [-U -i server -vnne \
+'udp and ip[[6:2]] > 0 and not ip[[6]] = 64'], [tcpdump-server])
 
 check ip netns exec client python3 << EOF
 import os
@@ -679,7 +676,7 @@ import socket
 import sys
 import time
 
-FILE="client.pcap"
+FILE="tcpdump-client.tcpdump"
 
 
 def contains_string(file, str):
@@ -707,8