diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2018-11-24 22:19:12 -0800 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2018-11-30 07:43:05 +0000 |
commit | 978aa643ca32ab220be940290039eb11e068bb73 (patch) | |
tree | 4573250d3c0fe7a814cdd55647f2e1d86ebf770e /test/test_nat.py | |
parent | fa76a76bf3388f09d55d0c83e7aea507c44f9619 (diff) |
Tests: Fix traceback.
self.assertTrue(packet.haslayer(msg_type))
File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue
raise self.failureException(msg)
AssertionError: 0 is not true
* Scapy packet.haslayer() returns 1 or 0.
Replace with assertEqual(packet.haslayer(), 1) to fix tracebacks.
* Scapy has multiple layers called TCP/UDP
Specify the module name to prevent namespace collisions.
* Remove duplicate import.
Change-Id: I600f9f330075cd40e1da50f8b2ceb24f645f2c20
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/test_nat.py')
-rw-r--r-- | test/test_nat.py | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/test/test_nat.py b/test/test_nat.py index b7b80c95c2a..c03cf08323b 100644 --- a/test/test_nat.py +++ b/test/test_nat.py @@ -10,12 +10,11 @@ from framework import VppTestCase, VppTestRunner, running_extended_tests from scapy.layers.inet import IP, TCP, UDP, ICMP from scapy.layers.inet import IPerror, TCPerror, UDPerror, ICMPerror from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, ICMPv6EchoReply, \ - ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr + ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, fragment6 from scapy.layers.inet6 import ICMPv6DestUnreach, IPerror6, IPv6ExtHdrFragment from scapy.layers.l2 import Ether, ARP, GRE from scapy.data import IP_PROTOS from scapy.packet import bind_layers, Raw -from scapy.all import fragment6 from util import ppp from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder from time import sleep @@ -579,7 +578,7 @@ class MethodHolder(VppTestCase): for packet in capture: try: self.assertEqual(packet[IP].src, src_ip) - self.assertTrue(packet.haslayer(ICMP)) + self.assertEqual(packet.haslayer(ICMP), 1) icmp = packet[ICMP] self.assertEqual(icmp.type, icmp_type) self.assertTrue(icmp.haslayer(IPerror)) @@ -609,7 +608,7 @@ class MethodHolder(VppTestCase): for packet in capture: try: self.assertEqual(packet[IP].dst, in_if.remote_ip4) - self.assertTrue(packet.haslayer(ICMP)) + self.assertEqual(packet.haslayer(ICMP), 1) icmp = packet[ICMP] self.assertEqual(icmp.type, icmp_type) self.assertTrue(icmp.haslayer(IPerror)) @@ -3073,7 +3072,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, nat_ip) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3093,7 +3092,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, self.pg1.remote_ip4) self.assertEqual(packet[IP].dst, self.pg0.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3128,7 +3127,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, host_nat_ip) self.assertEqual(packet[IP].dst, server.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3148,7 +3147,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, server_nat_ip) self.assertEqual(packet[IP].dst, host.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4428,7 +4427,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4448,7 +4447,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.pg1.remote_ip4) self.assertEqual(packet[IP].dst, self.pg0.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4492,7 +4491,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, server.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4512,7 +4511,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, server_nat_ip) self.assertEqual(packet[IP].dst, host.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -6693,7 +6692,7 @@ class TestNAT64(MethodHolder): packet = capture[0] try: self.assertEqual(packet[IPv6].src, self.pg5.local_ip6) - self.assertTrue(packet.haslayer(ICMPv6ND_NS)) + self.assertEqual(packet.haslayer(ICMPv6ND_NS), 1) tgt = packet[ICMPv6ND_NS].tgt except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -6721,7 +6720,7 @@ class TestNAT64(MethodHolder): try: self.assertEqual(packet[IPv6].src, self.pg5.local_ip6) self.assertEqual(packet[IPv6].dst, self.pg5.remote_ip6) - self.assertTrue(packet.haslayer(ICMPv6EchoReply)) + self.assertEqual(packet.haslayer(ICMPv6EchoReply), 1) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) raise @@ -7300,7 +7299,7 @@ class TestNAT64(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) |