summaryrefslogtreecommitdiffstats
path: root/test/hook.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2018-12-12 01:04:20 -0800
committerDave Barach <openvpp@barachs.net>2018-12-13 14:32:10 +0000
commit1314ec6170a1ef713b27c9428271a111368e9790 (patch)
tree37efaaa102b7792af24ab87ca8eb42db9c653408 /test/hook.py
parente91e6de8402d0c7ee3585e6144beb1e897d6b463 (diff)
test/hook.py. Add human-friendly annotations to log msgs.
* Add human-friendly annotations to packed data values in the logs. Examples: vpp-unittest-TestNAT66-_JdbMS/log.txt:22:31:29,152 API: ip_neighbor_add_del (is_static=0, is_no_adj_fib=0, is_add=1, sw_if_index=2, dst_address='\xfd\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02 (fd01:2::2)', mac_address='\x02\x02\x00\x00\xff\x02 (02:02:00:00:ff:02)', is_ipv6=1) vpp-unittest-TestACL_dot1ad_bridged-xEdhrj/log.txt:22:31:17,130 API: ip_neighbor_add_del (is_static=0, is_no_adj_fib=0, is_add=1, sw_if_index=5, dst_address='\xfd\x01\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc9 (fd01:5::c9)', mac_address='\x02\x05\xc9\x00\xff\xc9 (02:05:c9:00:ff:c9)', is_ipv6=1) vpp-unittest-TestACL_dot1ad_bridged-xEdhrj/log.txt:22:31:17,240 API: sw_interface_add_del_address (address_length=24, del_all=0, is_add=1, sw_if_index=6, address='\xac\x10\x06\x01 (172.16.6.1)', is_ipv6=0) vpp-unittest-TestACL_dot1ad_bridged-xEdhrj/log.txt:22:31:17,314 API: sw_interface_add_del_address (address_length=64, del_all=0, is_add=1, sw_if_index=6, address='\xfd\x01\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01 (fd01:6::1)', is_ipv6=1) Change-Id: Id6991569ee0ff853f76fae8fac941e8a26468a19 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/hook.py')
-rw-r--r--test/hook.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/hook.py b/test/hook.py
index 29c4cd9435c..a8f37c7a35b 100644
--- a/test/hook.py
+++ b/test/hook.py
@@ -3,6 +3,7 @@ import os
import sys
import traceback
from log import RED, single_line_delim, double_line_delim
+import ipaddress
from subprocess import check_output, CalledProcessError
from util import check_core_path, get_core_path
@@ -23,8 +24,23 @@ class Hook(object):
@param api_name: name of the API
@param api_args: tuple containing the API arguments
"""
+
+ def _friendly_format(val):
+ if not isinstance(val, str):
+ return val
+ if len(val) == 6:
+ return '{!s} ({!s})'.format(val, ':'.join(['{:02x}'.format(
+ ord(x)) for x in val]))
+ try:
+ return '{!s} ({!s})'.format(val, str(
+ ipaddress.ip_address(val)))
+ except ipaddress.AddressValueError:
+ return val
+
+ _args = ', '.join("{!s}={!r}".format(key, _friendly_format(val)) for
+ (key, val) in api_args.items())
self.logger.debug("API: %s (%s)" %
- (api_name, api_args), extra={'color': RED})
+ (api_name, _args), extra={'color': RED})
def after_api(self, api_name, api_args):
"""
@@ -94,8 +110,8 @@ class PollHook(Hook):
s = signaldict[abs(self.testcase.vpp.returncode)]
else:
s = "unknown"
- msg = "VPP subprocess died unexpectedly with returncode %d [%s]" %\
- (self.testcase.vpp.returncode, s)
+ msg = "VPP subprocess died unexpectedly with returncode %d [%s]." \
+ % (self.testcase.vpp.returncode, s)
self.logger.critical(msg)
core_path = get_core_path(self.testcase.tempdir)
if os.path.isfile(core_path):