make test: improve handling of packet captures
Perform accounting of expected packets based on created packet infos.
Use this accounting info to automatically expect (and verify) the
correct number of packets to be captured. Automatically retry the read
of the capture file if scapy raises an exception while doing so to
handle rare cases when capture file is read while only partially
written during busy wait. Don't fail assert_nothing_captured if only
junk packets arrived.
Change-Id: I16ec2e9410ef510d313ec16b7e13c57d0b2a63f5
Signed-off-by: Klement Sekera <ksekera@cisco.com>
diff --git a/test/test_l2bd.py b/test/test_l2bd.py
index 50720e6..30708a4 100644
--- a/test/test_l2bd.py
+++ b/test/test_l2bd.py
@@ -99,7 +99,7 @@
Clear trace and packet infos before running each test.
"""
super(TestL2bd, self).setUp()
- self.packet_infos = {}
+ self.reset_packet_infos()
def tearDown(self):
"""
@@ -158,8 +158,7 @@
dst_if = self.flows[src_if][i % 2]
dst_host = random.choice(self.hosts_by_pg_idx[dst_if.sw_if_index])
src_host = random.choice(self.hosts_by_pg_idx[src_if.sw_if_index])
- pkt_info = self.create_packet_info(
- src_if.sw_if_index, dst_if.sw_if_index)
+ pkt_info = self.create_packet_info(src_if, dst_if)
payload = self.info_to_payload(pkt_info)
p = (Ether(dst=dst_host.mac, src=src_host.mac) /
IP(src=src_host.ip4, dst=dst_host.ip4) /