aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-02-28 20:20:47 +0100
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-04 14:31:08 +0000
commitf159f58dbfc85f616b029c36196961915d7e52d2 (patch)
tree979f191da4b816aa7cb1accc4a79bcdf9c563c46 /test
parent84b83776d3843b5eaf50dbd40007987d77ad2490 (diff)
test framework: add factory function and default parameters
This is the first step to be able to remove all the API message wrappers in vpp_papi_provider.py. This allows to remove all functions that do not override parameters (different from zero), and a separate dictionary for messages requiring different defaults. The general requirement is that all new tests should use named arguments directly. Not positional arguments through the wrapper. Note when removing functions, the calls in vpp_papi_provider wrappers do not necessarily follow message order. Change-Id: If64916c07f8622c138db3a9d7c4a98b93a058e68 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_map.py22
-rw-r--r--test/test_nat.py8
-rw-r--r--test/test_syslog.py7
-rw-r--r--test/vpp_papi_provider.py111
4 files changed, 59 insertions, 89 deletions
diff --git a/test/test_map.py b/test/test_map.py
index 70d9fa08b28..952a737c1ac 100644
--- a/test/test_map.py
+++ b/test/test_map.py
@@ -77,10 +77,12 @@ class TestMAP(VppTestCase):
map_dst = '2001::/64'
map_src = '3000::1/128'
client_pfx = '192.168.0.0/16'
- self.vapi.map_add_domain(map_dst, map_src, client_pfx)
+ self.vapi.map_add_domain(map_dst, client_pfx, map_src)
# Enable MAP on interface.
- self.vapi.map_if_enable_disable(1, self.pg0.sw_if_index, 0)
+ self.vapi.map_if_enable_disable(is_enable=1,
+ sw_if_index=self.pg0.sw_if_index,
+ is_translation=0)
# Ensure MAP doesn't steal all packets!
v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
@@ -104,7 +106,9 @@ class TestMAP(VppTestCase):
self.send_and_assert_encapped(v4, "3000::1", "2001::c0a8:0:0")
# Enable MAP on interface.
- self.vapi.map_if_enable_disable(1, self.pg1.sw_if_index, 0)
+ self.vapi.map_if_enable_disable(is_enable=1,
+ sw_if_index=self.pg1.sw_if_index,
+ is_translation=0)
# Ensure MAP doesn't steal all packets
v6 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
@@ -198,12 +202,16 @@ class TestMAP(VppTestCase):
map_src = '1234:5678:90ab:cdef::/64'
ip4_pfx = '192.168.0.0/24'
- self.vapi.map_add_domain(map_dst, map_src, ip4_pfx,
- 16, 6, 4)
+ self.vapi.map_add_domain(map_dst, ip4_pfx, map_src,
+ 16, 6, 4, mtu=1500)
# Enable MAP-T on interfaces.
- self.vapi.map_if_enable_disable(1, self.pg0.sw_if_index, 1)
- self.vapi.map_if_enable_disable(1, self.pg1.sw_if_index, 1)
+ self.vapi.map_if_enable_disable(is_enable=1,
+ sw_if_index=self.pg0.sw_if_index,
+ is_translation=1)
+ self.vapi.map_if_enable_disable(is_enable=1,
+ sw_if_index=self.pg1.sw_if_index,
+ is_translation=1)
# Ensure MAP doesn't steal all packets!
v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
diff --git a/test/test_nat.py b/test/test_nat.py
index fce7efe36ee..4fb462c36b7 100644
--- a/test/test_nat.py
+++ b/test/test_nat.py
@@ -2838,7 +2838,7 @@ class TestNAT44(MethodHolder):
def test_syslog_apmap(self):
""" Test syslog address and port mapping creation and deletion """
self.vapi.syslog_set_filter(SYSLOG_SEVERITY.INFO)
- self.vapi.syslog_set_sender(self.pg3.remote_ip4n, self.pg3.local_ip4n)
+ self.vapi.syslog_set_sender(self.pg3.local_ip4n, self.pg3.remote_ip4n)
self.nat44_add_address(self.nat_addr)
self.vapi.nat44_interface_add_del_feature(self.pg0.sw_if_index)
self.vapi.nat44_interface_add_del_feature(self.pg1.sw_if_index,
@@ -6382,7 +6382,7 @@ class TestNAT44EndpointDependent(MethodHolder):
def test_syslog_sess(self):
""" Test syslog session creation and deletion """
self.vapi.syslog_set_filter(SYSLOG_SEVERITY.INFO)
- self.vapi.syslog_set_sender(self.pg2.remote_ip4n, self.pg2.local_ip4n)
+ self.vapi.syslog_set_sender(self.pg2.local_ip4n, self.pg2.remote_ip4n)
self.nat44_add_address(self.nat_addr)
self.vapi.nat44_interface_add_del_feature(self.pg0.sw_if_index)
self.vapi.nat44_interface_add_del_feature(self.pg1.sw_if_index,
@@ -8407,7 +8407,7 @@ class TestNAT64(MethodHolder):
self.vapi.nat64_add_del_interface(self.pg0.sw_if_index)
self.vapi.nat64_add_del_interface(self.pg1.sw_if_index, is_inside=0)
self.vapi.syslog_set_filter(SYSLOG_SEVERITY.INFO)
- self.vapi.syslog_set_sender(self.pg3.remote_ip4n, self.pg3.local_ip4n)
+ self.vapi.syslog_set_sender(self.pg3.local_ip4n, self.pg3.remote_ip4n)
p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
IPv6(src=self.pg0.remote_ip6, dst=remote_host_ip6) /
@@ -8562,7 +8562,7 @@ class TestDSlite(MethodHolder):
aftr_ip6 = '2001:db8:85a3::8a2e:370:1'
aftr_ip6_n = socket.inet_pton(socket.AF_INET6, aftr_ip6)
self.vapi.dslite_set_aftr_addr(aftr_ip6_n, aftr_ip4_n)
- self.vapi.syslog_set_sender(self.pg2.remote_ip4n, self.pg2.local_ip4n)
+ self.vapi.syslog_set_sender(self.pg2.local_ip4n, self.pg2.remote_ip4n)
# UDP
p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
diff --git a/test/test_syslog.py b/test/test_syslog.py
index 5c697ee1e44..67a7ef13ea7 100644
--- a/test/test_syslog.py
+++ b/test/test_syslog.py
@@ -95,7 +95,8 @@ class TestSyslog(VppTestCase):
def test_syslog(self):
""" Syslog Protocol test """
- self.vapi.syslog_set_sender(self.pg0.remote_ip4n, self.pg0.local_ip4n)
+ self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4n,
+ collector_address=self.pg0.remote_ip4n)
config = self.vapi.syslog_get_sender()
self.assertEqual(str(config.collector_address),
self.pg0.remote_ip4)
@@ -167,8 +168,8 @@ class TestSyslog(VppTestCase):
sd1,
msg)
- self.vapi.syslog_set_sender(self.pg0.remote_ip4n,
- self.pg0.local_ip4n,
+ self.vapi.syslog_set_sender(self.pg0.local_ip4n,
+ self.pg0.remote_ip4n,
collector_port=12345)
config = self.vapi.syslog_get_sender()
self.assertEqual(config.collector_port, 12345)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index f6069e3d049..7b5709ed8ac 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -2,7 +2,7 @@ import os
import time
from collections import deque
-from six import moves
+from six import moves, iteritems
from vpp_papi import VPP, mac_pton
from hook import Hook
from vpp_l2 import L2_PORT_TYPE
@@ -41,6 +41,14 @@ class SYSLOG_SEVERITY:
INFO = 6
DBG = 7
+#
+# Dictionary keyed on message name to override default values for
+# named parameters
+#
+defaultmapping = {'map_add_domain': {'mtu': 1280},
+ 'syslog_set_sender': {'collector_port': 514,
+ 'max_msg_size': 480}}
+
class UnexpectedApiReturnValueError(Exception):
""" exception raised when the API return value is unexpected """
@@ -145,6 +153,33 @@ class VppPapiProvider(object):
self.test_class.logger.debug("New event: %s: %s" % (name, event))
self._events.append(event)
+ def factory(self, name, apifn):
+ def f(*a, **ka):
+ fields = apifn._func.msg.fields
+
+ # add positional and kw arguments
+ d = ka
+ for i, o in enumerate(fields[3:]):
+ try:
+ d[o] = a[i]
+ except:
+ break
+
+ # Default override
+ if name in defaultmapping:
+ for k, v in iteritems(defaultmapping[name]):
+ if k in d:
+ continue
+ d[k] = v
+ return self.api(apifn, d)
+ return f
+
+ def __getattr__(self, name):
+ try:
+ return getattr(self, name)
+ except:
+ return self.factory(name, getattr(self.papi, name))
+
def connect(self):
"""Connect the API to VPP"""
self.vpp.connect(self.name, self.shm_prefix)
@@ -2754,43 +2789,6 @@ class VppPapiProvider(object):
'vni': vni
})
- def map_add_domain(self,
- ip6_prefix,
- ip6_src,
- ip4_prefix,
- ea_bits_len=0,
- psid_offset=0,
- psid_length=0,
- mtu=1280):
-
- return self.api(
- self.papi.map_add_domain,
- {
- 'ip6_prefix': ip6_prefix,
- 'ip4_prefix': ip4_prefix,
- 'ip6_src': ip6_src,
- 'ea_bits_len': ea_bits_len,
- 'psid_offset': psid_offset,
- 'psid_length': psid_length,
- 'mtu': mtu
- })
-
- def map_if_enable_disable(self, is_enable, sw_if_index, is_translation):
- return self.api(
- self.papi.map_if_enable_disable,
- {
- 'is_enable': is_enable,
- 'sw_if_index': sw_if_index,
- 'is_translation': is_translation,
- })
-
- def map_param_set_tcp(self, tcp_mss):
- return self.api(
- self.papi.map_param_set_tcp,
- {
- 'tcp_mss': tcp_mss,
- })
-
def gtpu_add_del_tunnel(
self,
src_addr,
@@ -4163,40 +4161,3 @@ class VppPapiProvider(object):
def svs_dump(self):
return self.api(self.papi.svs_dump, {})
-
- def syslog_set_sender(
- self,
- collector,
- src,
- collector_port=514,
- vrf_id=0,
- max_msg_size=480):
- """Set syslog sender configuration
-
- :param collector: colector IP address
- :param src: source IP address
- :param collector_port: collector UDP port (Default value = 514)
- :param vrf_id: VRF id (Default value = 0)
- :param max_msg_size: maximum message length (Default value = 480)
- """
- return self.api(self.papi.syslog_set_sender,
- {'collector_address': collector,
- 'src_address': src,
- 'collector_port': collector_port,
- 'vrf_id': vrf_id,
- 'max_msg_size': max_msg_size})
-
- def syslog_get_sender(self):
- """Return syslog sender configuration"""
- return self.api(self.papi.syslog_get_sender, {})
-
- def syslog_set_filter(self, severity):
- """Set syslog filter parameters
-
- :param severity: severity filter (specified severity and greater match)
- """
- return self.api(self.papi.syslog_set_filter, {'severity': severity})
-
- def syslog_get_filter(self):
- """Return syslog filter parameters"""
- return self.api(self.papi.syslog_get_filter, {})