From 40ad4568a4739776d42fedfa3dc1b7cdaf0aeea5 Mon Sep 17 00:00:00 2001 From: jcaiMR Date: Mon, 14 Aug 2023 15:09:03 +0000 Subject: [PATCH 1/4] fix tcpdump issue in bgp update timer testing --- tests/bgp/test_bgp_update_timer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_update_timer.py b/tests/bgp/test_bgp_update_timer.py index 9de2487508e..74cc595efe4 100644 --- a/tests/bgp/test_bgp_update_timer.py +++ b/tests/bgp/test_bgp_update_timer.py @@ -42,6 +42,11 @@ NEIGHBOR_PORT1 = 11001 WAIT_TIMEOUT = 120 +def is_tcpdump_running(duthost, cmd): + check_cmd = "ps u -C tcpdump | grep '%s'" % cmd + if cmd in duthost.shell(check_cmd)['stdout']: + return True + return False @contextlib.contextmanager def log_bgp_updates(duthost, iface, save_path, ns): @@ -58,10 +63,13 @@ def log_bgp_updates(duthost, iface, save_path, ns): duthost.asic_instance_from_namespace(ns).ns_arg, start_pcap, ) - start_pcap = "nohup {}{} &".format( + start_pcap_cmd = "nohup {}{} &".format( duthost.asic_instance_from_namespace(ns).ns_arg, start_pcap ) - duthost.shell(start_pcap) + duthost.shell(start_pcap_cmd) + if not wait_until(WAIT_TIMEOUT, 5, 20, lambda: is_tcpdump_running(duthost, start_pcap),): + pytest.fail("Could not start tcpdump") + try: yield finally: From 0dd77d982c24aefb5725ee73518341c288ebae25 Mon Sep 17 00:00:00 2001 From: jcaiMR Date: Mon, 14 Aug 2023 15:22:29 +0000 Subject: [PATCH 2/4] fix format issue --- tests/bgp/test_bgp_update_timer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bgp/test_bgp_update_timer.py b/tests/bgp/test_bgp_update_timer.py index 74cc595efe4..eeb6caf74db 100644 --- a/tests/bgp/test_bgp_update_timer.py +++ b/tests/bgp/test_bgp_update_timer.py @@ -42,12 +42,14 @@ NEIGHBOR_PORT1 = 11001 WAIT_TIMEOUT = 120 + def is_tcpdump_running(duthost, cmd): check_cmd = "ps u -C tcpdump | grep '%s'" % cmd if cmd in duthost.shell(check_cmd)['stdout']: return True return False + @contextlib.contextmanager def log_bgp_updates(duthost, iface, save_path, ns): """Capture bgp packets to file.""" From dda4e323117063335e85ba668f3d7bf122e30927 Mon Sep 17 00:00:00 2001 From: jcaiMR Date: Tue, 15 Aug 2023 05:35:38 +0000 Subject: [PATCH 3/4] fix comments --- tests/bgp/test_bgp_update_timer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/bgp/test_bgp_update_timer.py b/tests/bgp/test_bgp_update_timer.py index eeb6caf74db..ddc953e6194 100644 --- a/tests/bgp/test_bgp_update_timer.py +++ b/tests/bgp/test_bgp_update_timer.py @@ -41,6 +41,7 @@ NEIGHBOR_PORT0 = 11000 NEIGHBOR_PORT1 = 11001 WAIT_TIMEOUT = 120 +TCPDUMP_WAIT_TIMEOUT = 20 def is_tcpdump_running(duthost, cmd): @@ -69,8 +70,11 @@ def log_bgp_updates(duthost, iface, save_path, ns): duthost.asic_instance_from_namespace(ns).ns_arg, start_pcap ) duthost.shell(start_pcap_cmd) - if not wait_until(WAIT_TIMEOUT, 5, 20, lambda: is_tcpdump_running(duthost, start_pcap),): + # wait until tcpdump process created + if not wait_until(WAIT_TIMEOUT, 5, 1, lambda: is_tcpdump_running(duthost, start_pcap),): pytest.fail("Could not start tcpdump") + # sleep and waiting for tcpdump start to work (schedualed) + time.sleep(TCPDUMP_WAIT_TIMEOUT) try: yield From 540f9526a80f1b2e0bfe3b421e08f255d0520662 Mon Sep 17 00:00:00 2001 From: jcaiMR Date: Tue, 15 Aug 2023 05:51:01 +0000 Subject: [PATCH 4/4] fix comments --- tests/bgp/test_bgp_update_timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bgp/test_bgp_update_timer.py b/tests/bgp/test_bgp_update_timer.py index ddc953e6194..18f81a46a60 100644 --- a/tests/bgp/test_bgp_update_timer.py +++ b/tests/bgp/test_bgp_update_timer.py @@ -73,7 +73,7 @@ def log_bgp_updates(duthost, iface, save_path, ns): # wait until tcpdump process created if not wait_until(WAIT_TIMEOUT, 5, 1, lambda: is_tcpdump_running(duthost, start_pcap),): pytest.fail("Could not start tcpdump") - # sleep and waiting for tcpdump start to work (schedualed) + # sleep and wait for tcpdump ready to sniff packets time.sleep(TCPDUMP_WAIT_TIMEOUT) try: