tests: improve vpp_papi_provider exception output 30/26830/1
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Sat, 2 May 2020 14:40:33 +0000 (10:40 -0400)
committerPaul Vinciguerra <pvinci@vinciconsulting.com>
Sun, 3 May 2020 17:52:46 +0000 (13:52 -0400)
saves time debugging tests by replacing 'API call' with
the actual function signature:

  vpp_papi_provider.UnexpectedApiReturnValueError: API call failed, expected 0 return value instead of -2 in vxlan_add_del_tunnel_reply(_0=247, context=5052, retval=-2, sw_if_index=4294967295)

  vpp_papi_provider.UnexpectedApiReturnValueError: vxlan_add_del_tunnel(is_add=0, src_address=172.16.1.1, dst_address=239.1.1.209, vni=209, sw_if_index=26, mcast_sw_if_index=1, encap_vrf_id=None, instance=None, decap_next_index=None) failed, expected 0 return value instead of -2 in vxlan_add_del_tunnel_reply(_0=247, context=5052, retval=-2, sw_if_index=4294967295)

Type: test

Change-Id: Ie3b6a5fdb4e1d427d60c51f7a7bf815af0bb3de6
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
test/vpp_papi_provider.py

index aa95010..7354412 100644 (file)
@@ -115,6 +115,10 @@ defaultmapping = {
 }
 
 
+def as_fn_signature(d):
+    return ", ".join(f"{k}={v}" for k, v in d.items())
+
+
 class CliFailedCommandError(Exception):
     """ cli command failed."""
 
@@ -289,15 +293,19 @@ class VppPapiProvider(object):
         reply = api_fn(**api_args)
         if self._expect_api_retval == self._negative:
             if hasattr(reply, 'retval') and reply.retval >= 0:
-                msg = "API call passed unexpectedly: expected negative " \
+                msg = "%s(%s) passed unexpectedly: expected negative " \
                       "return value instead of %d in %s" % \
-                      (reply.retval, moves.reprlib.repr(reply))
+                      (api_fn.__name__, as_fn_signature(api_args),
+                       reply.retval,
+                       moves.reprlib.repr(reply))
                 self.test_class.logger.info(msg)
                 raise UnexpectedApiReturnValueError(msg)
         elif self._expect_api_retval == self._zero:
             if hasattr(reply, 'retval') and reply.retval != expected_retval:
-                msg = "API call failed, expected %d return value instead " \
-                      "of %d in %s" % (expected_retval, reply.retval,
+                msg = "%s(%s) failed, expected %d return value instead " \
+                      "of %d in %s" % (api_fn.__name__,
+                                       as_fn_signature(api_args),
+                                       expected_retval, reply.retval,
                                        repr(reply))
                 self.test_class.logger.info(msg)
                 raise UnexpectedApiReturnValueError(msg)