summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-03-14 20:39:40 +0100
committerNeale Ranns <nranns@cisco.com>2018-03-15 14:59:08 +0000
commit46c1c11ba08512a5e37392de1ddb306b139a5bcf (patch)
treeb95b967b9f0dccdfc528c5cb3a319240fb7dc43e
parentb9ca61be1af028a3c7d7004373e8447cae766132 (diff)
IPIP: Linter on test_*.py
Change-Id: Icd491e382a2da0e5d55a673458605bc37e39b669 Signed-off-by: Ole Troan <ot@cisco.com>
-rw-r--r--test/Makefile2
-rw-r--r--test/test_ipip.py93
-rw-r--r--test/test_sixrd.py120
3 files changed, 78 insertions, 137 deletions
diff --git a/test/Makefile b/test/Makefile
index add306ac2bb..b570e50a8d5 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -54,7 +54,7 @@ PYTHON_EXTRA_DEPENDS=
endif
PYTHON_VENV_PATH=$(VPP_PYTHON_PREFIX)/virtualenv
-PYTHON_DEPENDS=$(PYTHON_EXTRA_DEPENDS) faulthandler six scapy==2.3.3 pexpect pycrypto subprocess32 cffi git+https://github.com/klement/py-lispnetworking@setup py2-ipaddress
+PYTHON_DEPENDS=$(PYTHON_EXTRA_DEPENDS) faulthandler six scapy==2.3.3 pexpect pycrypto subprocess32 cffi git+https://github.com/klement/py-lispnetworking@setup
SCAPY_SOURCE=$(shell find $(PYTHON_VENV_PATH) -name site-packages)
BUILD_COV_DIR=$(BR)/test-cov
diff --git a/test/test_ipip.py b/test/test_ipip.py
index 1ae4de0adf8..3a0c401f8af 100644
--- a/test/test_ipip.py
+++ b/test/test_ipip.py
@@ -1,17 +1,11 @@
-#
-# IP{4,6} over IP{v,6} tunnel functional tests
-#
+#!/usr/bin/env python
+"""IP{4,6} over IP{v,6} tunnel functional tests"""
import unittest
-from scapy.layers.inet import IP, UDP, ICMP
-from scapy.layers.inet6 import IPv6
-from scapy.layers.l2 import Ether, GRE
-from scapy.packet import Raw
-
-from framework import VppTestCase
+from scapy.layers.inet6 import IPv6, Ether, IP, UDP
+from framework import VppTestCase, VppTestRunner
from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
-from util import ppp
-from ipaddress import *
+from socket import AF_INET, AF_INET6, inet_pton
""" Testipip is a subclass of VPPTestCase classes.
@@ -26,48 +20,29 @@ class TestIPIP(VppTestCase):
@classmethod
def setUpClass(cls):
super(TestIPIP, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.interfaces = list(cls.pg_interfaces)
- except Exception:
- super(TestIPIP, cls).tearDownClass()
- raise
+ cls.create_pg_interfaces(range(2))
+ cls.interfaces = list(cls.pg_interfaces)
def setUp(cls):
super(TestIPIP, cls).setUp()
- try:
- for i in cls.interfaces:
- i.admin_up()
- i.config_ip4()
- i.config_ip6()
- i.disable_ipv6_ra()
- i.resolve_arp()
- i.resolve_ndp()
- except Exception:
- super(TestIPIP, cls).tearDown()
- raise
+ for i in cls.interfaces:
+ i.admin_up()
+ i.config_ip4()
+ i.config_ip6()
+ i.disable_ipv6_ra()
+ i.resolve_arp()
+ i.resolve_ndp()
def tearDown(self):
super(TestIPIP, self).tearDown()
if not self.vpp_dead:
- self.vapi.cli("show hardware")
- for i in self.pg_interfaces:
- i.unconfig_ip4()
- i.unconfig_ip6()
- i.admin_down()
- self.vapi.cli("show error")
+ for i in self.pg_interfaces:
+ i.unconfig_ip4()
+ i.unconfig_ip6()
+ i.admin_down()
def validate(self, rx, expected):
- expected = expected.__class__(str(expected))
- if rx != expected:
- print('RX packet:')
- print(rx.show())
- print('EXPECTED packet:')
- print(expected.show())
- self.assertDictEqual(rx, expected)
-
- def payload(self, len):
- return 'x' * len
+ self.assertEqual(rx, expected.__class__(str(expected)))
def test_ipip4(self):
""" ip{v4,v6} over ip4 test """
@@ -78,19 +53,16 @@ class TestIPIP(VppTestCase):
# IPv4 transport
rv = self.vapi.ipip_add_tunnel(
- src_address=str(ip_address(self.pg0.local_ip4).packed),
- dst_address=str(ip_address(self.pg1.remote_ip4).packed),
+ src_address=self.pg0.local_ip4n,
+ dst_address=self.pg1.remote_ip4n,
is_ipv6=0)
- self.assertEqual(rv.retval, 0)
sw_if_index = rv.sw_if_index
# Set interface up and enable IP on it
- rv = self.vapi.sw_interface_set_flags(sw_if_index, 1)
- self.assertEqual(rv.retval, 0)
- rv = self.vapi.sw_interface_set_unnumbered(
+ self.vapi.sw_interface_set_flags(sw_if_index, 1)
+ self.vapi.sw_interface_set_unnumbered(
ip_sw_if_index=self.pg0.sw_if_index,
sw_if_index=sw_if_index)
- self.assertEqual(rv.retval, 0)
# Add IPv4 and IPv6 routes via tunnel interface
ip4_via_tunnel = VppIpRoute(
@@ -162,17 +134,14 @@ class TestIPIP(VppTestCase):
# IPv6 transport
rv = self.vapi.ipip_add_tunnel(
- src_address=str(ip_address(self.pg0.local_ip6).packed),
- dst_address=str(ip_address(self.pg1.remote_ip6).packed))
- self.assertEqual(rv.retval, 0)
+ src_address=self.pg0.local_ip6n,
+ dst_address=self.pg1.remote_ip6n)
sw_if_index = rv.sw_if_index
- rv = self.vapi.sw_interface_set_flags(sw_if_index, 1)
- self.assertEqual(rv.retval, 0)
- rv = self.vapi.sw_interface_set_unnumbered(
+ self.vapi.sw_interface_set_flags(sw_if_index, 1)
+ self.vapi.sw_interface_set_unnumbered(
ip_sw_if_index=self.pg0.sw_if_index, sw_if_index=sw_if_index)
- self.assertEqual(rv.retval, 0)
# Add IPv4 and IPv6 routes via tunnel interface
ip4_via_tunnel = VppIpRoute(
@@ -236,12 +205,10 @@ class TestIPIP(VppTestCase):
def test_ipip_create(self):
""" ipip create / delete interface test """
rv = self.vapi.ipip_add_tunnel(
- src_address=str(ip_address('1.2.3.4').packed),
- dst_address=str(ip_address('2.3.4.5').packed), is_ipv6=0)
- self.assertEqual(rv.retval, 0)
+ src_address=inet_pton(AF_INET, '1.2.3.4'),
+ dst_address=inet_pton(AF_INET, '2.3.4.5'), is_ipv6=0)
sw_if_index = rv.sw_if_index
- rv = self.vapi.ipip_del_tunnel(sw_if_index)
- self.assertEqual(rv.retval, 0)
+ self.vapi.ipip_del_tunnel(sw_if_index)
if __name__ == '__main__':
diff --git a/test/test_sixrd.py b/test/test_sixrd.py
index ac5061474d5..c6b3c088516 100644
--- a/test/test_sixrd.py
+++ b/test/test_sixrd.py
@@ -1,17 +1,13 @@
-#
-# 6RD RFC5969 functional tests
-#
+#!/usr/bin/env python
+""" 6RD RFC5969 functional tests """
import unittest
-from scapy.layers.inet import IP, UDP, ICMP
+from scapy.layers.inet import IP, UDP, Ether
from scapy.layers.inet6 import IPv6
-from scapy.layers.l2 import Ether, GRE
from scapy.packet import Raw
-
-from framework import VppTestCase
+from framework import VppTestCase, VppTestRunner
from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
-from util import ppp
-from ipaddress import *
+from socket import AF_INET, AF_INET6, inet_pton
""" Test6rd is a subclass of VPPTestCase classes.
@@ -26,43 +22,31 @@ class Test6RD(VppTestCase):
@classmethod
def setUpClass(cls):
super(Test6RD, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.interfaces = list(cls.pg_interfaces)
- except Exception:
- super(Test6RD, cls).tearDownClass()
- raise
+ cls.create_pg_interfaces(range(2))
+ cls.interfaces = list(cls.pg_interfaces)
def setUp(cls):
super(Test6RD, cls).setUp()
- try:
- for i in cls.interfaces:
- i.admin_up()
- i.config_ip4()
- i.config_ip6()
- i.disable_ipv6_ra()
- i.resolve_arp()
- i.resolve_ndp()
- except Exception:
- super(Test6RD, cls).tearDown()
- raise
+ for i in cls.interfaces:
+ i.admin_up()
+ i.config_ip4()
+ i.config_ip6()
+ i.disable_ipv6_ra()
+ i.resolve_arp()
+ i.resolve_ndp()
def tearDown(self):
super(Test6RD, self).tearDown()
if not self.vpp_dead:
- self.vapi.cli("show hardware")
- for i in self.pg_interfaces:
- i.unconfig_ip4()
- i.unconfig_ip6()
- i.admin_down()
- if type(self.tunnel_index) is list:
- for sw_if_index in self.tunnel_index:
- rv = self.vapi.ipip_6rd_del_tunnel(sw_if_index)
- self.assertEqual(rv.retval, 0)
- else:
- rv = self.vapi.ipip_6rd_del_tunnel(self.tunnel_index)
- self.assertEqual(rv.retval, 0)
- self.vapi.cli("show error")
+ for i in self.pg_interfaces:
+ i.unconfig_ip4()
+ i.unconfig_ip6()
+ i.admin_down()
+ if type(self.tunnel_index) is list:
+ for sw_if_index in self.tunnel_index:
+ self.vapi.ipip_6rd_del_tunnel(sw_if_index)
+ else:
+ self.vapi.ipip_6rd_del_tunnel(self.tunnel_index)
def validate_6in4(self, rx, expected):
if IP not in rx:
@@ -95,11 +79,9 @@ class Test6RD(VppTestCase):
p_ip6 = IPv6(src="1::1", dst="2002:AC10:0202::1", nh='UDP')
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed), 16,
- str(ip_address('0.0.0.0').packed), 0,
- str(ip_address(self.pg0.local_ip4).packed), True)
-
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'), 16,
+ inet_pton(AF_INET, '0.0.0.0'), 0,
+ self.pg0.local_ip4n, True)
self.tunnel_index = rv.sw_if_index
self.vapi.cli("show ip6 fib")
@@ -128,19 +110,16 @@ class Test6RD(VppTestCase):
""" ip4 -> ip6 (decap) 6rd test """
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg0.local_ip4).packed), True)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg0.local_ip4n, True)
self.tunnel_index = rv.sw_if_index
rv = self.vapi.ipip_6rd_del_tunnel(rv.sw_if_index)
- self.assertEqual(rv.retval, 0)
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg0.local_ip4).packed), True)
+ 0, inet_pton(AF_INET6, '2002::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg0.local_ip4n, True)
self.tunnel_index = rv.sw_if_index
- self.assertEqual(rv.retval, 0)
p_ip6 = (IPv6(src="2002:AC10:0202::1", dst=self.pg1.remote_ip6) /
UDP(sport=1234, dport=1234))
@@ -161,17 +140,15 @@ class Test6RD(VppTestCase):
self.tunnel_index = []
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg0.local_ip4).packed), True)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg0.local_ip4n, True)
self.tunnel_index.append(rv.sw_if_index)
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2003::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg1.local_ip4).packed), True)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2003::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg1.local_ip4n, True)
self.tunnel_index.append(rv.sw_if_index)
self.vapi.cli("show ip6 fib")
@@ -196,10 +173,9 @@ class Test6RD(VppTestCase):
""" ip4 -> ip6 (decap) 6rd test """
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed), 16,
- str(ip_address('172.0.0.0').packed), 8,
- str(ip_address(self.pg0.local_ip4).packed), True)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'), 16,
+ inet_pton(AF_INET, '172.0.0.0'), 8,
+ self.pg0.local_ip4n, True)
self.tunnel_index = rv.sw_if_index
@@ -218,10 +194,9 @@ class Test6RD(VppTestCase):
""" ip4 -> ip6 (decap) security check 6rd test """
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg0.local_ip4).packed), True)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg0.local_ip4n, True)
self.tunnel_index = rv.sw_if_index
self.vapi.cli("show ip6 fib")
@@ -251,10 +226,9 @@ class Test6RD(VppTestCase):
""" 6rd BGP tunnel """
rv = self.vapi.ipip_6rd_add_tunnel(
- 0, str(ip_address('2002::').packed),
- 16, str(ip_address('0.0.0.0').packed),
- 0, str(ip_address(self.pg0.local_ip4).packed), False)
- self.assertEqual(rv.retval, 0)
+ 0, inet_pton(AF_INET6, '2002::'),
+ 16, inet_pton(AF_INET, '0.0.0.0'),
+ 0, self.pg0.local_ip4n, False)
self.tunnel_index = rv.sw_if_index
default_route = VppIpRoute(