Skip to content

Commit e43a84b

Browse files
mkalcokalmusil
authored andcommitted
tests: Add macro for running UDP "echo" service.
Tests that required "UDP echo" service used custom logic to ensure that the "nc" process and all of its children got killed on the cleanup. This change extracts that custom logic into a reusable macro NETNS_START_UDP_ECHO. Signed-off-by: Martin Kalcok <martin.kalcok@gmail.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ales Musil <amusil@redhat.com> (cherry picked from commit 5767fe5)
1 parent 3888f89 commit e43a84b

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

tests/system-common-macros.at

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ m4_define([NETNS_START_DHCPD],
178178
]
179179
)
180180

181+
# NETNS_START_UDP_ECHO([namespace], [ip-version], [port], [pidfile])
182+
#
183+
# Start a "persistent" UDP echo server within 'namespace', listening on 'port'
184+
# and echoing back any data it receives. 'ip-version' is either "4" or "6".
185+
# The server keeps running across multiple client connections (nc's "-k").
186+
#
187+
# nc's "-k" makes it fork child processes that keep the listening port open, so
188+
# killing only the parent leaves those children running and hangs the whole
189+
# test cleanup (especially on failures). This macro therefore installs a
190+
# cleanup hook that kills the child processes (pkill -P) before the parent.
191+
#
192+
# The parent PID is recorded in the 'pidfile' and the user can employ the same
193+
# (pkill -P && kill) technique to cleanly stop the server at will during the
194+
# test.
195+
#
196+
m4_define([NETNS_START_UDP_ECHO],
197+
[ip netns exec $1 nc -$2 -k -l -u -p $3 -d 0.1 -c '/bin/cat' & echo $! > $4
198+
echo "pkill -P \`cat $4\` && kill \`cat $4\`" >> cleanup
199+
]
200+
)
201+
181202
# OVS_CHECK_CT_ZERO_SNAT()
182203
m4_define([OVS_CHECK_CT_ZERO_SNAT],
183204
[AT_SKIP_IF([! grep -q "Datapath supports ct_zero_snat" ovs-vswitchd.log])])

tests/system-ovn.at

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4565,19 +4565,12 @@ check ovn-nbctl --wait=hv lr-lb-add lr0 lb2
45654565
# Wait until udp service_monitor are set to offline.
45664566
wait_row_count Service_Monitor 2 status=offline protocol=udp
45674567

4568-
# We need to use "-k" argument because we keep receiving health check probes.
4569-
NETNS_DAEMONIZE([sw0-p1], [nc -4 -k -l -u -p 53 -d 0.1 -c '/bin/cat'], [udp1.pid])
4570-
NETNS_DAEMONIZE([sw0-p2], [nc -4 -k -l -u -p 53 -d 0.1 -c '/bin/cat'], [udp2.pid])
4568+
# Start persistent UDP service that keeps replying to the health-check probes.
4569+
NETNS_START_UDP_ECHO([sw0-p1], [4], [53], [udp1.pid])
4570+
NETNS_START_UDP_ECHO([sw0-p2], [4], [53], [udp2.pid])
45714571

4572-
# UDP nc with "-k" is bit tricky to cleanup, especially on test failures, due to its
4573-
# child processes keeping the listening port open. If they are not cleaned up properly,
4574-
# the whole test cleanup hangs.
45754572
udp1_pid=$(cat udp1.pid)
45764573
udp2_pid=$(cat udp2.pid)
4577-
echo "pkill -P $udp1_pid && kill $udp1_pid" >> cleanup
4578-
echo "pkill -P $udp2_pid && kill $udp2_pid" >> cleanup
4579-
:> udp1.pid
4580-
:> udp2.pid
45814574

45824575
wait_row_count Service_Monitor 2 status=online
45834576

@@ -4764,19 +4757,12 @@ check ovn-nbctl --wait=hv lr-lb-add lr0 lb2
47644757
# Wait until udp service_monitor are set to offline.
47654758
wait_row_count Service_Monitor 2 status=offline protocol=udp
47664759

4767-
# We need to use "-k" argument because we keep receiving health check probes.
4768-
NETNS_DAEMONIZE([sw0-p1], [nc -6 -k -l -u -p 53 -d 0.1 -c '/bin/cat'], [udp1.pid])
4769-
NETNS_DAEMONIZE([sw0-p2], [nc -6 -k -l -u -p 53 -d 0.1 -c '/bin/cat'], [udp2.pid])
4760+
# Start persistent UDP service that keeps replying to the health-check probes.
4761+
NETNS_START_UDP_ECHO([sw0-p1], [6], [53], [udp1.pid])
4762+
NETNS_START_UDP_ECHO([sw0-p2], [6], [53], [udp2.pid])
47704763

4771-
# UDP nc with "-k" is bit tricky to cleanup, especially on test failures, due to its
4772-
# child processes keeping the listening port open. If they are not cleaned up properly,
4773-
# the whole test cleanup hangs.
47744764
udp1_pid=$(cat udp1.pid)
47754765
udp2_pid=$(cat udp2.pid)
4776-
echo "pkill -P $udp1_pid && kill $udp1_pid" >> cleanup
4777-
echo "pkill -P $udp2_pid && kill $udp2_pid" >> cleanup
4778-
:> udp1.pid
4779-
:> udp2.pid
47804766

47814767
wait_row_count Service_Monitor 2 status=online
47824768

0 commit comments

Comments
 (0)