From 81853d468a1ff40b0e03343b73412aff96a46dd0 Mon Sep 17 00:00:00 2001 From: Jan Gelety Date: Wed, 6 Mar 2019 21:47:28 +0100 Subject: CSIT-1337: Migrate L2Util library from VAT to PAPI Change-Id: I22879c7bdd100d00216b9528663bf17406169826 Signed-off-by: Jan Gelety --- resources/tools/papi/vpp_papi_provider.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'resources/tools/papi') diff --git a/resources/tools/papi/vpp_papi_provider.py b/resources/tools/papi/vpp_papi_provider.py index 299cd2c962..cec8197329 100755 --- a/resources/tools/papi/vpp_papi_provider.py +++ b/resources/tools/papi/vpp_papi_provider.py @@ -96,7 +96,20 @@ def _convert_reply(api_r): reply_value = dict() for item in dir(api_r): if not item.startswith('_') and item not in unwanted_fields: - reply_value[item] = getattr(api_r, item) + attr_value = getattr(api_r, item) + if isinstance(attr_value, list) or isinstance(attr_value, dict): + value = attr_value + elif hasattr(attr_value, '__int__'): + value = int(attr_value) + elif hasattr(attr_value, '__str__'): + value = binascii.hexlify(str(attr_value)) + # Next handles parameters not supporting preferred integer or string + # representation to get it logged + elif hasattr(attr_value, '__repr__'): + value = repr(attr_value) + else: + value = attr_value + reply_value[item] = value reply_dict[reply_key] = reply_value return reply_dict @@ -182,7 +195,11 @@ def process_stats(args): data = stats.dump(directory) reply.append(data) - return json.dumps(reply) + try: + return json.dumps(reply) + except UnicodeDecodeError as err: + raise RuntimeError('PAPI reply {reply} error:\n{exc}'.format( + reply=reply, exc=repr(err))) def main(): -- cgit 1.2.3-korg