summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorKlement Sekera <klement.sekera@gmail.com>2022-04-14 16:29:07 +0200
committerDave Wallace <dwallacelf@gmail.com>2022-05-03 15:07:41 +0000
commit77c821ccc6b72d18a247e95816ac1013b4dc664d (patch)
tree06028c888750ca5181e5468443f2c5b3d8e05f14 /test
parent2ca88ff97884ec9ed20a853b13cee6d86f9c9d0f (diff)
tests: handle removed interface
Catch exception if sw_if_index is invalid when querying interface binding config. If the interface is not there, it's surely not bound to any table ... Type: improvement Change-Id: I1f3e04a631653feb5c2350662b6a041adccefa1f Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/vpp_ip_route.py13
-rw-r--r--test/vpp_papi_exceptions.py15
-rw-r--r--test/vpp_papi_provider.py23
3 files changed, 29 insertions, 22 deletions
diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py
index b6059485275..f5e5a8801e4 100644
--- a/test/vpp_ip_route.py
+++ b/test/vpp_ip_route.py
@@ -5,10 +5,10 @@
"""
from vpp_object import VppObject
-from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
from vpp_ip import DpoProto, INVALID_INDEX, VppIpAddressUnion, \
VppIpMPrefix
from ipaddress import ip_network, ip_address, IPv4Network, IPv6Network
+from vpp_papi_exceptions import UnexpectedApiReturnValueError
# from vnet/vnet/mpls/mpls_types.h
MPLS_IETF_MAX_LABEL = 0xfffff
@@ -340,9 +340,14 @@ class VppIpInterfaceBind(VppObject):
def query_vpp_config(self):
if 0 == self.table.table_id:
return False
- return self._test.vapi.sw_interface_get_table(
- self.intf.sw_if_index,
- self.table.is_ip6).vrf_id == self.table.table_id
+ try:
+ return self._test.vapi.sw_interface_get_table(
+ self.intf.sw_if_index,
+ self.table.is_ip6).vrf_id == self.table.table_id
+ except UnexpectedApiReturnValueError as e:
+ if e.retval == -2: # INVALID_SW_IF_INDEX
+ return False
+ raise
def object_id(self):
return "interface-bind-%s-%s" % (self.intf, self.table)
diff --git a/test/vpp_papi_exceptions.py b/test/vpp_papi_exceptions.py
new file mode 100644
index 00000000000..2f7da963f70
--- /dev/null
+++ b/test/vpp_papi_exceptions.py
@@ -0,0 +1,15 @@
+class CliFailedCommandError(Exception):
+ """ cli command failed."""
+
+
+class CliSyntaxError(Exception):
+ """ cli command had a syntax error."""
+
+
+class UnexpectedApiReturnValueError(Exception):
+ """ exception raised when the API return value is unexpected """
+
+ def __init__(self, retval, message):
+ self.retval = retval
+ self.message = message
+ super().__init__(message)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index c0e88f826e0..9ff616c18e8 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -7,13 +7,13 @@
import os
import time
-from collections import deque
import queue
from six import moves, iteritems
from config import config
-from vpp_papi import VPPApiClient, mac_pton
+from vpp_papi import VPPApiClient
from hook import Hook
-from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
+from vpp_papi_exceptions import CliFailedCommandError, CliSyntaxError,\
+ UnexpectedApiReturnValueError
#
# Dictionary keyed on message name to override default values for
@@ -106,19 +106,6 @@ def as_fn_signature(d):
return ", ".join(f"{k}={v}" for k, v in d.items())
-class CliFailedCommandError(Exception):
- """ cli command failed."""
-
-
-class CliSyntaxError(Exception):
- """ cli command had a syntax error."""
-
-
-class UnexpectedApiReturnValueError(Exception):
- """ exception raised when the API return value is unexpected """
- pass
-
-
class VppPapiProvider(object):
"""VPP-api provider using vpp-papi
@@ -287,7 +274,7 @@ class VppPapiProvider(object):
reply.retval,
moves.reprlib.repr(reply))
self.test_class.logger.info(msg)
- raise UnexpectedApiReturnValueError(msg)
+ raise UnexpectedApiReturnValueError(reply.retval, msg)
elif self._expect_api_retval == self._zero:
if hasattr(reply, 'retval') and reply.retval != expected_retval:
msg = "%s(%s) failed, expected %d return value instead " \
@@ -296,7 +283,7 @@ class VppPapiProvider(object):
expected_retval, reply.retval,
repr(reply))
self.test_class.logger.info(msg)
- raise UnexpectedApiReturnValueError(msg)
+ raise UnexpectedApiReturnValueError(reply.retval, msg)
else:
raise Exception("Internal error, unexpected value for "
"self._expect_api_retval %s" %