diff options
author | Klement Sekera <ksekera@cisco.com> | 2016-12-12 08:36:58 +0100 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2016-12-16 08:09:40 +0000 |
commit | 9225dee9655ce607130f9bab5472441b72e25858 (patch) | |
tree | 6438ea39bf2b14eeca70770890165497ee146d30 /test/test_snat.py | |
parent | cc53285baf2c3a45b95e22dd66c8592d634568ee (diff) |
make test: improve robustness and performance
Introduce an API which asserts empty capture for interface.
Throw exception in old API if the capture does not exist, thus
making it clear if the test expects packets to arrive or not.
Improve performance by not doing sleeps after starting the packet
generator, rather lazily deleting captures when needed.
Fix wrong usage of packet.show() in various tests.
Change-Id: I456cb23316eef99b3f35f80344fe595c4db9a21c
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/test_snat.py')
-rw-r--r-- | test/test_snat.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/test/test_snat.py b/test/test_snat.py index 5cc76f6c7da..fdd81f02e75 100644 --- a/test/test_snat.py +++ b/test/test_snat.py @@ -2,12 +2,12 @@ import socket import unittest -from logging import * from framework import VppTestCase, VppTestRunner from scapy.layers.inet import IP, TCP, UDP, ICMP from scapy.layers.l2 import Ether +from util import ppp class TestSNAT(VppTestCase): @@ -88,7 +88,7 @@ class TestSNAT(VppTestCase): :param dst_ip: Destination IP address (Default use global SNAT address) """ if dst_ip is None: - dst_ip=self.snat_addr + dst_ip = self.snat_addr pkts = [] # TCP p = (Ether(dst=out_if.local_mac, src=out_if.remote_mac) / @@ -145,8 +145,8 @@ class TestSNAT(VppTestCase): self.assertNotEqual(packet[ICMP].id, self.icmp_id_in) self.icmp_id_out = packet[ICMP].id except: - error("Unexpected or invalid packet (outside network):") - error(packet.show()) + self.logger.error(ppp("Unexpected or invalid packet " + "(outside network):", packet)) raise def verify_capture_in(self, capture, in_if, packet_num=3): @@ -168,8 +168,8 @@ class TestSNAT(VppTestCase): else: self.assertEqual(packet[ICMP].id, self.icmp_id_in) except: - error("Unexpected or invalid packet (inside network):") - error(packet.show()) + self.logger.error(ppp("Unexpected or invalid packet " + "(inside network):", packet)) raise def clear_snat(self): @@ -410,11 +410,10 @@ class TestSNAT(VppTestCase): self.pg0.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() - capture = self.pg3.get_capture() - self.verify_capture_out(capture, packet_num=0) + self.pg3.assert_nothing_captured() def test_multiple_inside_interfaces(self): - """ SNAT multiple inside interfaces with non-overlapping address space """ + """SNAT multiple inside interfaces with non-overlapping address space""" self.snat_add_address(self.snat_addr) self.vapi.snat_interface_add_del_feature(self.pg0.sw_if_index) @@ -566,8 +565,7 @@ class TestSNAT(VppTestCase): self.assertEqual(tcp.dport, server_in_port) host_out_port = tcp.sport except: - error("Unexpected or invalid packet:") - error(p.show()) + self.logger.error(ppp("Unexpected or invalid packet:", p)) raise # send reply from server to host @@ -588,11 +586,9 @@ class TestSNAT(VppTestCase): self.assertEqual(tcp.sport, server_out_port) self.assertEqual(tcp.dport, host_in_port) except: - error("Unexpected or invalid packet:") - error(p.show()) + self.logger.error(ppp("Unexpected or invalid packet:"), p) raise - def tearDown(self): super(TestSNAT, self).tearDown() if not self.vpp_dead: |