diff --git a/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py b/whitebox_neutron_tempest_plugin/common/tcpdump_capture.py index ffc24d2..6e1ee9a 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):