From 1ba774b35c97f4ab751798f5ef297e91b8a541e9 Mon Sep 17 00:00:00 2001 From: "Richard.Yu" Date: Thu, 22 Dec 2022 13:05:31 +0800 Subject: [PATCH] [SAI-PTF] API Logger - reformat dict in return value (#1688) Why Base on some requirement, when logging the return value is a dict, need return the value for each key as a string. For example, returning this. ``` "[{ 'client': , 'port_oid': 4294967303, 'hw_lane_list': sai_thrift_object_list_t(count=100, idlist=[1,2,34]) }]" ``` it returned as (see the ' around the value too below) ``` "[{ 'client': '', 'port_oid': '4294967303', 'hw_lane_list': 'sai_thrift_object_list_t(count=100, idlist=[1,2,34])' }]" ``` How Convert the dict value to string Test: Unit test and DUT test Signed-off-by: richardyu-ms Signed-off-by: richardyu-ms --- meta/templates/sai_adapter_utils.tt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meta/templates/sai_adapter_utils.tt b/meta/templates/sai_adapter_utils.tt index cc23bcddf..387025cb0 100644 --- a/meta/templates/sai_adapter_utils.tt +++ b/meta/templates/sai_adapter_utils.tt @@ -237,7 +237,14 @@ def invocation_logger(func): args_values = args_dict.values() retval = func(*args, **kwargs) - logging.info("sai_adapter_return func:[{}] retval:[{}]".format(func.__name__, repr(retval))) + # Base on some vendor's requirement, + # need to convert all the values in the dict to a string + retDict = eval(repr(retval)) + if type(retDict) is dict: + retDict = { key:str(value) for (key,value) in retDict.items()} + logging.info("sai_adapter_return func:[{}] retval:[{}]".format(func.__name__, retDict)) + else: + logging.info("sai_adapter_return func:[{}] retval:[{}]".format(func.__name__, repr(retval))) return retval return inner_logger