Skip to content

Commit b465243

Browse files
authored
[SAI-PTF]Add return value in the SAI-PTF log (#1683)
Why In order to track the SAI-API result and add the return value for each SAI_thrift api. How In sai_adapter, use the invocation_logger, log the return value when sai_thrift API returned Test: Unit test and DUT test Signed-off-by: richardyu-ms <[email protected]> Signed-off-by: richardyu-ms <[email protected]>
1 parent 65a95e8 commit b465243

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

meta/templates/sai_adapter_utils.tt

+4-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ def invocation_logger(func):
235235
logging.info("sai_adapter_invoke func:[{}] args: [{}]".format(func.__name__, args_dict))
236236

237237
args_values = args_dict.values()
238-
return func(*args, **kwargs)
238+
239+
retval = func(*args, **kwargs)
240+
logging.info("sai_adapter_return func:[{}] retval:[{}]".format(func.__name__, repr(retval)))
241+
return retval
239242

240243
return inner_logger
241244
[%- END -%]

ptf/utest/MockClient.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import logging
2+
try:
3+
from meta.sai_adapter import *
4+
except ImportError:
5+
from sai_thrift.sai_adapter import *
6+
17
class MockSuccessClient():
28

39
def sai_thrift_remove_acl_table(self, var):
10+
logging.info("sai_thrift_remove_acl_table invoked")
11+
# e = sai_thrift_exception()
12+
# e.status = -2
13+
# raise e
14+
415
return 0
516

617
def sai_thrift_create_switch(client,
@@ -88,4 +99,21 @@ def sai_thrift_create_switch(client,
8899
qos_tc_and_color_to_mpls_exp_map=None,
89100
failover_config_mode=None,
90101
tunnel_objects_list=None):
102+
logging.info("sai_thrift_create_switch invoked")
91103
return 0
104+
105+
106+
def sai_thrift_get_acl_table_attribute(client,
107+
oid,
108+
attr_list):
109+
logging.info("sai_thrift_get_acl_table_attribute invoked")
110+
attr_list = []
111+
attribute1 = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_STAGE)
112+
attribute1.value = sai_thrift_attribute_value_t()
113+
attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_STAGE, value=attribute1.value)
114+
attr_list.append(attribute)
115+
116+
117+
attr_lists = sai_thrift_attribute_list_t(attr_list=attr_list)
118+
attr_lists.attr_list = attr_list
119+
return attr_lists

ptf/utest/TemplateTest.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def test_logger(self):
4242
init_switch=True,
4343
hardware_access_bus="11:11:11:11:11:11")
4444
self.check_file_contains(LOG_FILE_PATH, 'hardware_access_bus')
45+
sai_thrift_get_acl_table_attribute(self.client, acl_table_oid=1, acl_stage=1)
46+
self.check_file_contains(LOG_FILE_PATH, 'SAI_ACL_TABLE_ATTR_ACL_STAGE')
4547

4648

4749
def check_file_contains(self, file, content):

0 commit comments

Comments
 (0)