From d5c60b96a3fd93916fc4af5c8d6d25625c28242e Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Fri, 22 Jun 2018 13:54:07 +0200 Subject: [PATCH] make test: fix broken interfaces Change-Id: I2e092774f81503e04b53cc6c6b5d357fe3fc52ab Signed-off-by: Klement Sekera --- test/framework.py | 10 ++++------ test/test_acl_plugin_l2l3.py | 2 +- test/test_acl_plugin_macip.py | 2 +- test/test_bfd.py | 6 +++--- test/test_container.py | 2 +- test/test_dvr.py | 12 ++++-------- test/test_gbp.py | 8 +++----- test/test_interface_crud.py | 4 ++-- test/test_ip4_irb.py | 2 +- test/test_ip_mcast.py | 4 +--- test/test_qos.py | 8 ++------ test/test_sctp.py | 2 +- test/test_session.py | 2 +- test/test_tcp.py | 2 +- test/test_udp.py | 8 ++++---- test/test_vcl.py | 8 ++++---- test/vpp_bond_interface.py | 5 ++--- test/vpp_gre_interface.py | 10 ++++------ test/vpp_lo_interface.py | 8 +++----- test/vpp_mpls_tunnel_interface.py | 5 ++--- test/vpp_pppoe_interface.py | 7 +++---- test/vpp_sub_interface.py | 25 +++++++++++-------------- test/vpp_vhost_interface.py | 5 ++--- 23 files changed, 61 insertions(+), 86 deletions(-) diff --git a/test/framework.py b/test/framework.py index be8c209f4ea..dd4774dc72b 100644 --- a/test/framework.py +++ b/test/framework.py @@ -558,18 +558,16 @@ class VppTestCase(unittest.TestCase): return result @classmethod - def create_loopback_interfaces(cls, interfaces): + def create_loopback_interfaces(cls, count): """ Create loopback interfaces. - :param interfaces: iterable indexes of the interfaces. + :param count: number of interfaces created. :returns: List of created interfaces. """ - result = [] - for i in interfaces: - intf = VppLoInterface(cls, i) + result = [VppLoInterface(cls) for i in range(count)] + for intf in result: setattr(cls, intf.name, intf) - result.append(intf) cls.lo_interfaces = result return result diff --git a/test/test_acl_plugin_l2l3.py b/test/test_acl_plugin_l2l3.py index b971610d5d4..26b562e8ad0 100644 --- a/test/test_acl_plugin_l2l3.py +++ b/test/test_acl_plugin_l2l3.py @@ -60,7 +60,7 @@ class TestIpIrb(VppTestCase): # create 3 pg interfaces, 1 loopback interface cls.create_pg_interfaces(range(3)) - cls.create_loopback_interfaces(range(1)) + cls.create_loopback_interfaces(1) cls.interfaces = list(cls.pg_interfaces) cls.interfaces.extend(cls.lo_interfaces) diff --git a/test/test_acl_plugin_macip.py b/test/test_acl_plugin_macip.py index a8df833cd26..8bcef25c49a 100644 --- a/test/test_acl_plugin_macip.py +++ b/test/test_acl_plugin_macip.py @@ -63,7 +63,7 @@ class MethodHolder(VppTestCase): try: # create 4 pg interfaces, 1 loopback interface cls.create_pg_interfaces(range(4)) - cls.create_loopback_interfaces(range(1)) + cls.create_loopback_interfaces(1) # create 2 subinterfaces cls.subifs = [ diff --git a/test/test_bfd.py b/test/test_bfd.py index 3b36f558a7e..3afe9428025 100644 --- a/test/test_bfd.py +++ b/test/test_bfd.py @@ -629,7 +629,7 @@ class BFD4TestCase(VppTestCase): cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces([0]) - cls.create_loopback_interfaces([0]) + cls.create_loopback_interfaces(1) cls.loopback0 = cls.lo_interfaces[0] cls.loopback0.config_ip4() cls.loopback0.admin_up() @@ -1439,7 +1439,7 @@ class BFD6TestCase(VppTestCase): cls.pg0.configure_ipv6_neighbors() cls.pg0.admin_up() cls.pg0.resolve_ndp() - cls.create_loopback_interfaces([0]) + cls.create_loopback_interfaces(1) cls.loopback0 = cls.lo_interfaces[0] cls.loopback0.config_ip6() cls.loopback0.admin_up() @@ -2557,7 +2557,7 @@ class BFDCLITestCase(VppTestCase): def test_set_del_udp_echo_source(self): """ set/del udp echo source """ - self.create_loopback_interfaces([0]) + self.create_loopback_interfaces(1) self.loopback0 = self.lo_interfaces[0] self.loopback0.admin_up() self.cli_verify_response("show bfd echo-source", diff --git a/test/test_container.py b/test/test_container.py index 99a527b8796..66357a7389a 100644 --- a/test/test_container.py +++ b/test/test_container.py @@ -73,7 +73,7 @@ class ContainerIntegrationTestCase(VppTestCase): def test_0050_loopback_prepare_test(self): """ Create loopbacks overlapping with remote addresses """ - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) for i in range(2): intf = self.lo_interfaces[i] intf.admin_up() diff --git a/test/test_dvr.py b/test/test_dvr.py index 5bdc3b2312e..9d8675832ea 100644 --- a/test/test_dvr.py +++ b/test/test_dvr.py @@ -1,18 +1,14 @@ #!/usr/bin/env python -import random -import socket import unittest from framework import VppTestCase, VppTestRunner -from vpp_sub_interface import VppSubInterface, VppDot1QSubint -from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto, VppIpMRoute, \ - VppMRoutePath, MRouteEntryFlags, MRouteItfFlags +from vpp_sub_interface import VppDot1QSubint +from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_papi_provider import L2_VTR_OP from scapy.packet import Raw -from scapy.layers.l2 import Ether, Dot1Q, ARP +from scapy.layers.l2 import Ether, Dot1Q from scapy.layers.inet import IP, UDP -from util import ppp from socket import AF_INET, inet_pton @@ -23,7 +19,7 @@ class TestDVR(VppTestCase): super(TestDVR, self).setUp() self.create_pg_interfaces(range(4)) - self.create_loopback_interfaces(range(1)) + self.create_loopback_interfaces(1) for i in self.pg_interfaces: i.admin_up() diff --git a/test/test_gbp.py b/test/test_gbp.py index fe19ae6a27f..7ee4d76550c 100644 --- a/test/test_gbp.py +++ b/test/test_gbp.py @@ -1,8 +1,6 @@ #!/usr/bin/env python import unittest -import socket -import struct from framework import VppTestCase, VppTestRunner from vpp_object import VppObject @@ -13,12 +11,12 @@ from scapy.packet import Raw from scapy.layers.l2 import Ether, ARP from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr, \ - ICMPv6NDOptDstLLAddr, ICMPv6ND_NA + ICMPv6ND_NA from scapy.utils6 import in6_getnsma, in6_getnsmac from socket import AF_INET, AF_INET6 from scapy.utils import inet_pton, inet_ntop -from util import Host, mactobinary +from util import mactobinary class VppGbpEndpoint(VppObject): @@ -300,7 +298,7 @@ class TestGBP(VppTestCase): super(TestGBP, self).setUp() self.create_pg_interfaces(range(9)) - self.create_loopback_interfaces(range(9)) + self.create_loopback_interfaces(9) self.router_mac = "00:11:22:33:44:55" diff --git a/test/test_interface_crud.py b/test/test_interface_crud.py index 63917047ed4..d78cb58be0b 100644 --- a/test/test_interface_crud.py +++ b/test/test_interface_crud.py @@ -79,7 +79,7 @@ class TestLoopbackInterfaceCRUD(VppTestCase): def test_crud(self): # create - loopbacks = self.create_loopback_interfaces(range(20)) + loopbacks = self.create_loopback_interfaces(20) for i in loopbacks: i.local_ip4_prefix_len = 32 i.config_ip4() @@ -121,7 +121,7 @@ class TestLoopbackInterfaceCRUD(VppTestCase): def test_down(self): # create - loopbacks = self.create_loopback_interfaces(range(20)) + loopbacks = self.create_loopback_interfaces(20) for i in loopbacks: i.local_ip4_prefix_len = 32 i.config_ip4() diff --git a/test/test_ip4_irb.py b/test/test_ip4_irb.py index bbec7ca709f..460cb43b726 100644 --- a/test/test_ip4_irb.py +++ b/test/test_ip4_irb.py @@ -54,7 +54,7 @@ class TestIpIrb(VppTestCase): # create 3 pg interfaces, 1 loopback interface cls.create_pg_interfaces(range(3)) - cls.create_loopback_interfaces(range(1)) + cls.create_loopback_interfaces(1) cls.interfaces = list(cls.pg_interfaces) cls.interfaces.extend(cls.lo_interfaces) diff --git a/test/test_ip_mcast.py b/test/test_ip_mcast.py index 017f0629cd2..9c216d5657d 100644 --- a/test/test_ip_mcast.py +++ b/test/test_ip_mcast.py @@ -3,15 +3,13 @@ import unittest from framework import VppTestCase, VppTestRunner -from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \ MRouteItfFlags, MRouteEntryFlags, VppIpTable, DpoProto from scapy.packet import Raw from scapy.layers.l2 import Ether -from scapy.layers.inet import IP, UDP, getmacbyip, ICMP +from scapy.layers.inet import IP, UDP, getmacbyip from scapy.layers.inet6 import IPv6, getmacbyip6 -from util import ppp # # The number of packets sent is set to 91 so that when we replicate more than 3 diff --git a/test/test_qos.py b/test/test_qos.py index a940bd3a64c..939cca5d8d1 100644 --- a/test/test_qos.py +++ b/test/test_qos.py @@ -1,17 +1,13 @@ #!/usr/bin/env python import unittest -import socket -import struct from framework import VppTestCase, VppTestRunner -from vpp_object import VppObject from vpp_papi_provider import QOS_SOURCE -from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsRoute -from vpp_sub_interface import VppSubInterface, VppDot1QSubint +from vpp_ip_route import VppIpRoute, VppRoutePath from scapy.packet import Raw -from scapy.layers.l2 import Ether, Dot1Q +from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6 from scapy.contrib.mpls import MPLS diff --git a/test/test_sctp.py b/test/test_sctp.py index 32068abf76e..9396f0514f3 100644 --- a/test/test_sctp.py +++ b/test/test_sctp.py @@ -16,7 +16,7 @@ class TestSCTP(VppTestCase): def setUp(self): super(TestSCTP, self).setUp() self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 0 diff --git a/test/test_session.py b/test/test_session.py index 047b8ca553a..55541b70527 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -17,7 +17,7 @@ class TestSession(VppTestCase): super(TestSession, self).setUp() self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 0 diff --git a/test/test_tcp.py b/test/test_tcp.py index 3b36bdf416b..4a5c9bc4ff3 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -16,7 +16,7 @@ class TestTCP(VppTestCase): def setUp(self): super(TestTCP, self).setUp() self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 0 diff --git a/test/test_udp.py b/test/test_udp.py index aabbbd3cdcf..230335ff169 100644 --- a/test/test_udp.py +++ b/test/test_udp.py @@ -1,11 +1,11 @@ #!/usr/bin/env python - +import unittest from framework import VppTestCase, VppTestRunner -from vpp_udp_encap import * +from vpp_udp_encap import VppUdpEncap from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, VppMplsLabel from scapy.packet import Raw -from scapy.layers.l2 import Ether, ARP +from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6 from scapy.contrib.mpls import MPLS @@ -233,7 +233,7 @@ class TestUDP(VppTestCase): def setUp(self): super(TestUDP, self).setUp() self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 0 diff --git a/test/test_vcl.py b/test/test_vcl.py index cba8c67b5c7..79eb75f364f 100644 --- a/test/test_vcl.py +++ b/test/test_vcl.py @@ -68,12 +68,12 @@ class VCLTestCase(VppTestCase): worker_client.join(self.timeout) try: self.validateResults(worker_client, worker_server, self.timeout) - except Exception, error: + except Exception as error: self.fail("Failed with %s" % error) def thru_host_stack_setup(self): self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 1 @@ -117,7 +117,7 @@ class VCLTestCase(VppTestCase): def thru_host_stack_ipv6_setup(self): self.vapi.session_enable_disable(is_enabled=1) - self.create_loopback_interfaces(range(2)) + self.create_loopback_interfaces(2) table_id = 1 @@ -182,7 +182,7 @@ class VCLTestCase(VppTestCase): try: self.validateResults(worker_client, worker_server, self.timeout) - except Exception, error: + except Exception as error: self.fail("Failed with %s" % error) def validateResults(self, worker_client, worker_server, timeout): diff --git a/test/vpp_bond_interface.py b/test/vpp_bond_interface.py index 4bd7cb8235c..153f1142c5c 100644 --- a/test/vpp_bond_interface.py +++ b/test/vpp_bond_interface.py @@ -9,7 +9,7 @@ class VppBondInterface(VppInterface): use_custom_mac=0, mac_address=''): """ Create VPP Bond interface """ - self._test = test + super(VppBondInterface, self).__init__(test) self.mode = mode self.lb = lb self.use_custom_mac = use_custom_mac @@ -20,8 +20,7 @@ class VppBondInterface(VppInterface): self.lb, self.use_custom_mac, self.mac_address) - self._sw_if_index = r.sw_if_index - super(VppBondInterface, self).__init__(self._test) + self.set_sw_if_index(r.sw_if_index) def remove_vpp_config(self): self.test.vapi.bond_delete(self.sw_if_index) diff --git a/test/vpp_gre_interface.py b/test/vpp_gre_interface.py index 3de3e5c4559..d5a40eeb03d 100644 --- a/test/vpp_gre_interface.py +++ b/test/vpp_gre_interface.py @@ -11,7 +11,7 @@ class VppGreInterface(VppInterface): def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, session=0): """ Create VPP GRE interface """ - self._test = test + super(VppGreInterface, self).__init__(test) self.t_src = src_ip self.t_dst = dst_ip self.t_outer_fib = outer_fib_id @@ -25,10 +25,9 @@ class VppGreInterface(VppInterface): outer_fib_id=self.t_outer_fib, tunnel_type=self.t_type, session_id=self.t_session) - self._sw_if_index = r.sw_if_index + self.set_sw_if_index(r.sw_if_index) self.generate_remote_hosts() self.test.registry.register(self, self.test.logger) - super(VppGreInterface, self).__init__(self.test) def remove_vpp_config(self): s = socket.inet_pton(socket.AF_INET, self.t_src) @@ -55,7 +54,7 @@ class VppGre6Interface(VppInterface): def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, session=0): """ Create VPP GRE interface """ - self._test = test + super(VppGre6Interface, self).__init__(test) self.t_src = src_ip self.t_dst = dst_ip self.t_outer_fib = outer_fib_id @@ -70,10 +69,9 @@ class VppGre6Interface(VppInterface): tunnel_type=self.t_type, session_id=self.t_session, is_ip6=1) - self._sw_if_index = r.sw_if_index + self.set_sw_if_index(r.sw_if_index) self.generate_remote_hosts() self.test.registry.register(self, self.test.logger) - super(VppGre6Interface, self).__init__(self.test) def remove_vpp_config(self): s = socket.inet_pton(socket.AF_INET6, self.t_src) diff --git a/test/vpp_lo_interface.py b/test/vpp_lo_interface.py index ae4111bec82..36f56bed8d7 100644 --- a/test/vpp_lo_interface.py +++ b/test/vpp_lo_interface.py @@ -5,16 +5,14 @@ from vpp_interface import VppInterface class VppLoInterface(VppInterface, VppObject): """VPP loopback interface.""" - def __init__(self, test, lo_index): + def __init__(self, test): """ Create VPP loopback interface """ - self._test = test - self.add_vpp_config() super(VppLoInterface, self).__init__(test) - self._lo_index = lo_index + self.add_vpp_config() def add_vpp_config(self): r = self.test.vapi.create_loopback() - self._sw_if_index = r.sw_if_index + self.set_sw_if_index(r.sw_if_index) def remove_vpp_config(self): self.test.vapi.delete_loopback(self.sw_if_index) diff --git a/test/vpp_mpls_tunnel_interface.py b/test/vpp_mpls_tunnel_interface.py index 2e0ed67ce83..995ffb7dd54 100644 --- a/test/vpp_mpls_tunnel_interface.py +++ b/test/vpp_mpls_tunnel_interface.py @@ -9,7 +9,7 @@ class VppMPLSTunnelInterface(VppInterface): def __init__(self, test, paths, is_multicast=0, is_l2=0): """ Create MPLS Tunnel interface """ - self._test = test + super(VppMPLSTunnelInterface, self).__init__(test) self.t_paths = paths self.is_multicast = is_multicast self.is_l2 = is_l2 @@ -31,8 +31,7 @@ class VppMPLSTunnelInterface(VppInterface): is_multicast=self.is_multicast, l2_only=self.is_l2) sw_if_index = reply.sw_if_index - self._sw_if_index = sw_if_index - super(VppMPLSTunnelInterface, self).__init__(self.test) + self.set_sw_if_index(sw_if_index) def remove_vpp_config(self): for path in self.t_paths: diff --git a/test/vpp_pppoe_interface.py b/test/vpp_pppoe_interface.py index fbb78bcc55f..507d8251442 100644 --- a/test/vpp_pppoe_interface.py +++ b/test/vpp_pppoe_interface.py @@ -12,7 +12,7 @@ class VppPppoeInterface(VppInterface): def __init__(self, test, client_ip, client_mac, session_id, decap_vrf_id=0): """ Create VPP PPPoE4 interface """ - self._test = test + super(VppPppoeInterface, self).__init__(test) self.client_ip = client_ip self.client_mac = client_mac self.session_id = session_id @@ -25,15 +25,14 @@ class VppPppoeInterface(VppInterface): cip, cmac, session_id=self.session_id, decap_vrf_id=self.decap_vrf_id) - self._sw_if_index = r.sw_if_index - super(VppPppoeInterface, self).__init__(self._test) + self.set_sw_if_index(r.sw_if_index) self.generate_remote_hosts() def remove_vpp_config(self): cip = socket.inet_pton(socket.AF_INET, self.client_ip) cmac = mactobinary(self.client_mac) self.unconfig() - r = self.test.vapi.pppoe_add_del_session( + self.test.vapi.pppoe_add_del_session( cip, cmac, session_id=self.session_id, decap_vrf_id=self.decap_vrf_id, diff --git a/test/vpp_sub_interface.py b/test/vpp_sub_interface.py index 38d24041e81..3c726b29d3f 100644 --- a/test/vpp_sub_interface.py +++ b/test/vpp_sub_interface.py @@ -35,10 +35,13 @@ class VppSubInterface(VppPGInterface): self._parent = parent self._parent.add_sub_if(self) self._sub_id = sub_id - self.set_vtr(L2_VTR_OP.L2_DISABLED) self.DOT1AD_TYPE = 0x88A8 self.DOT1Q_TYPE = 0x8100 + def set_sw_if_index(self, sw_if_index): + super(VppSubInterface, self).set_sw_if_index(sw_if_index) + self.set_vtr(L2_VTR_OP.L2_DISABLED) + @abstractmethod def create_arp_req(self): pass @@ -47,18 +50,12 @@ class VppSubInterface(VppPGInterface): def create_ndp_req(self): pass - def resolve_arp(self): - super(VppSubInterface, self).resolve_arp(self.parent) - - def resolve_ndp(self): - super(VppSubInterface, self).resolve_ndp(self.parent) - @abstractmethod def add_dot1_layer(self, pkt): pass def remove_vpp_config(self): - self.test.vapi.delete_subif(self._sw_if_index) + self.test.vapi.delete_subif(self.sw_if_index) def _add_tag(self, packet, vlan, tag_type): payload = packet.payload @@ -129,12 +126,12 @@ class VppDot1QSubint(VppSubInterface): return self._vlan def __init__(self, test, parent, sub_id, vlan=None): + super(VppDot1QSubint, self).__init__(test, parent, sub_id) if vlan is None: vlan = sub_id self._vlan = vlan r = test.vapi.create_vlan_subif(parent.sw_if_index, vlan) - self._sw_if_index = r.sw_if_index - super(VppDot1QSubint, self).__init__(test, parent, sub_id) + self.set_sw_if_index(r.sw_if_index) def create_arp_req(self): packet = VppPGInterface.create_arp_req(self) @@ -166,13 +163,13 @@ class VppDot1ADSubint(VppSubInterface): return self._inner_vlan def __init__(self, test, parent, sub_id, outer_vlan, inner_vlan): + super(VppDot1ADSubint, self).__init__(test, parent, sub_id) r = test.vapi.create_subif(parent.sw_if_index, sub_id, outer_vlan, inner_vlan, dot1ad=1, two_tags=1, exact_match=1) - self._sw_if_index = r.sw_if_index + self.set_sw_if_index(r.sw_if_index) self._outer_vlan = outer_vlan self._inner_vlan = inner_vlan - super(VppDot1ADSubint, self).__init__(test, parent, sub_id) def create_arp_req(self): packet = VppPGInterface.create_arp_req(self) @@ -193,12 +190,12 @@ class VppDot1ADSubint(VppSubInterface): class VppP2PSubint(VppSubInterface): def __init__(self, test, parent, sub_id, remote_mac): + super(VppP2PSubint, self).__init__(test, parent, sub_id) r = test.vapi.create_p2pethernet_subif(parent.sw_if_index, remote_mac, sub_id) - self._sw_if_index = r.sw_if_index + self.set_sw_if_index(r.sw_if_index) self.parent_sw_if_index = parent.sw_if_index self.p2p_remote_mac = remote_mac - super(VppP2PSubint, self).__init__(test, parent, sub_id) def add_dot1_layer(self, packet): return packet diff --git a/test/vpp_vhost_interface.py b/test/vpp_vhost_interface.py index 2249b062a64..e86be5d27b5 100644 --- a/test/vpp_vhost_interface.py +++ b/test/vpp_vhost_interface.py @@ -9,7 +9,7 @@ class VppVhostInterface(VppInterface): tag=''): """ Create VPP Vhost interface """ - self._test = test + super(VppVhostInterface, self).__init__(test) self.is_server = is_server self.sock_filename = sock_filename self.renumber = renumber @@ -26,8 +26,7 @@ class VppVhostInterface(VppInterface): self.use_custom_mac, self.mac_address, self.tag) - self._sw_if_index = r.sw_if_index - super(VppVhostInterface, self).__init__(self._test) + self.set_sw_if_index(r.sw_if_index) def remove_vpp_config(self): self.test.vapi.delete_vhost_user_if(self.sw_if_index) -- 2.16.6