From 81d9dc6831fe0727c9b5b62d627bbbf379ced768 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Fri, 6 Dec 2024 10:47:32 +0100 Subject: [PATCH] Log packets captured by tcpdump on the nodes in case of test failure In the tests which are using tcpdump to check if traffic is going through the right node(s) there was only check if something was captured or not. But in case of failure we didn't know what was captured what caused issue. Now this patch adds logging of the packets captured on all of the nodes in case if the assertion in test failed. Hopefully that will help debugging issues like in the related bug. Related-bug: #OSPRH-11312 Change-Id: I1025ae0c9dbb50d187b2827a8a7c4de864e35875 --- .../common/tcpdump_capture.py | 3 +++ .../tests/scenario/base.py | 23 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py b/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py index 5b66f5f..8bfe330 100644 --- a/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py +++ b/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py @@ -97,6 +97,9 @@ class TcpdumpCapture(fixtures.Fixture): return repr(icmp.nexthopmtu) return None + def get_captured_records(self): + return [str(r) for r in rdpcap(self._open_capture_file())] + def _open_capture_file(self): if not self.capture_files: raise ValueError('No capture files available') diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index 67588d4..057021f 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -1129,6 +1129,17 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): if node.get('capture'): node['capture'].stop() + def _log_captured_packets(self): + for node in self.nodes: + capture = node.get('capture') + if capture is None or capture.is_empty(): + captured_packets = "No packets captured" + else: + captured_packets = "\n ".join( + capture.get_captured_records()) + LOG.debug("Node: %s; Packets captured: %s", + node["short_name"], captured_packets) + def check_east_west_icmp_flow( self, dst_ip, expected_routing_nodes, expected_macs, ssh_client): """Check that traffic routed as expected within a tenant network @@ -1172,7 +1183,11 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): not node['capture'].is_empty())] LOG.debug('Actual routing nodes: %s', ','.join(actual_routing_nodes)) - self.assertCountEqual(expected_routing_nodes, actual_routing_nodes) + try: + self.assertCountEqual(expected_routing_nodes, actual_routing_nodes) + except AssertionError: + self._log_captured_packets() + raise def check_north_south_icmp_flow( self, dst_ip, expected_routing_nodes, expected_mac, ssh_client, @@ -1217,7 +1232,11 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): not node['capture'].is_empty())] LOG.debug('Actual routing nodes: %s', ','.join(actual_routing_nodes)) - self.assertCountEqual(expected_routing_nodes, actual_routing_nodes) + try: + self.assertCountEqual(expected_routing_nodes, actual_routing_nodes) + except AssertionError: + self._log_captured_packets() + raise class BaseTempestTestCaseOvn(BaseTempestWhiteboxTestCase):