-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SAI-PTF] add invocation logger (#1651)
* add invocation logger Signed-off-by: richardyu-ms <richard.yu@microsoft.com> * reformat code Signed-off-by: richardyu-ms <richard.yu@microsoft.com> Signed-off-by: richardyu-ms <richard.yu@microsoft.com> Co-authored-by: richardyu <richardyu@contoso.com>
- Loading branch information
1 parent
bb50de8
commit 80ebb3f
Showing
12 changed files
with
384 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
import os | ||
import sys | ||
from logging.handlers import RotatingFileHandler | ||
|
||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
LOG_FILE_DIR = os.path.join(ROOT_DIR, 'logs') | ||
LOG_FILE_PATH = os.path.join(LOG_FILE_DIR, 'output.log') | ||
|
||
|
||
def set_logging(loggerName='main'): | ||
"""Set the logger. | ||
""" | ||
|
||
# Create formatters and add it to handlers | ||
c_debug_format = '%(name)s - %(filename)s - %(levelname)s - %(message)s' | ||
c_error_format = '%(filename)s - %(levelname)s - %(message)s' | ||
f_format = '%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(message)s' | ||
datafmt = '%m/%d/%Y %I:%M:%S %p' | ||
|
||
if not os.path.exists(LOG_FILE_DIR): | ||
os.mkdir(LOG_FILE_DIR) | ||
|
||
# Create a custom logger | ||
logger = logging.getLogger() | ||
logger.name = loggerName | ||
logger.setLevel(logging.INFO) | ||
|
||
file_formatter = logging.Formatter(f_format, datafmt) | ||
|
||
# Create handlers | ||
# Add a new file handler | ||
file_handler = logging.FileHandler(LOG_FILE_PATH) | ||
file_handler.setLevel(logging.DEBUG) | ||
file_handler.setFormatter(file_formatter) | ||
logger.addHandler(file_handler) | ||
|
||
|
||
# Add a new stream handler | ||
console_formatter = logging.Formatter( | ||
c_error_format, datafmt) | ||
stream_handler = logging.StreamHandler() | ||
stream_handler.setLevel(logging.ERROR) | ||
stream_handler.setFormatter(console_formatter) | ||
logger.addHandler(stream_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import unittest | ||
import inspect | ||
|
||
import LogConfig | ||
|
||
""" | ||
Base class of the unit test | ||
""" | ||
|
||
class BasicMockedTest(unittest.TestCase): | ||
"""Basic test case, use to simualate the sai_base_test class | ||
""" | ||
|
||
def setUp(self): | ||
unittest.TestCase.setUp(self) | ||
|
||
def set_logger_name(self): | ||
""" | ||
Set Logger name as filename:classname | ||
""" | ||
|
||
file_name = inspect.getfile(self.__class__) | ||
class_name = self.__class__.__name__ | ||
logger_name = "{}:{}".format(file_name, class_name) | ||
LogConfig.set_logging(loggerName = logger_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
import os | ||
import sys | ||
from logging.handlers import RotatingFileHandler | ||
|
||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
LOG_FILE_DIR = os.path.join(ROOT_DIR, 'logs') | ||
LOG_FILE_PATH = os.path.join(LOG_FILE_DIR, 'output.log') | ||
|
||
|
||
def set_logging(loggerName='main'): | ||
"""Set the logger. | ||
""" | ||
|
||
# Create formatters and add it to handlers | ||
c_debug_format = '%(name)s - %(filename)s - %(levelname)s - %(message)s' | ||
c_error_format = '%(filename)s - %(levelname)s - %(message)s' | ||
f_format = '%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(message)s' | ||
datafmt = '%m/%d/%Y %I:%M:%S %p' | ||
|
||
if not os.path.exists(LOG_FILE_DIR): | ||
os.mkdir(LOG_FILE_DIR) | ||
|
||
# Create a custom logger | ||
logger = logging.getLogger() | ||
logger.name = loggerName | ||
logger.setLevel(logging.INFO) | ||
|
||
file_formatter = logging.Formatter(f_format, datafmt) | ||
|
||
# Create handlers | ||
# Add a new file handler | ||
file_handler = logging.FileHandler(LOG_FILE_PATH) | ||
file_handler.setLevel(logging.DEBUG) | ||
file_handler.setFormatter(file_formatter) | ||
logger.addHandler(file_handler) | ||
|
||
|
||
# Add a new stream handler | ||
console_formatter = logging.Formatter( | ||
c_error_format, datafmt) | ||
stream_handler = logging.StreamHandler() | ||
stream_handler.setLevel(logging.ERROR) | ||
stream_handler.setFormatter(console_formatter) | ||
logger.addHandler(stream_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
class MockSuccessClient(): | ||
|
||
def sai_thrift_remove_acl_table(self, var): | ||
return 0 | ||
|
||
def sai_thrift_create_switch(client, | ||
init_switch=None, | ||
hardware_access_bus=None, | ||
platfrom_context=None, | ||
register_read=None, | ||
register_write=None, | ||
switch_id=None, | ||
max_system_cores=None, | ||
system_port_config_list=None, | ||
ingress_acl=None, | ||
egress_acl=None, | ||
restart_warm=None, | ||
warm_recover=None, | ||
switching_mode=None, | ||
bcast_cpu_flood_enable=None, | ||
mcast_cpu_flood_enable=None, | ||
src_mac_address=None, | ||
max_learned_addresses=None, | ||
fdb_aging_time=None, | ||
fdb_unicast_miss_packet_action=None, | ||
fdb_broadcast_miss_packet_action=None, | ||
fdb_multicast_miss_packet_action=None, | ||
ecmp_default_hash_algorithm=None, | ||
ecmp_default_hash_seed=None, | ||
ecmp_default_symmetric_hash=None, | ||
ecmp_hash_ipv4=None, | ||
ecmp_hash_ipv4_in_ipv4=None, | ||
ecmp_hash_ipv6=None, | ||
lag_default_hash_algorithm=None, | ||
lag_default_hash_seed=None, | ||
lag_default_symmetric_hash=None, | ||
lag_hash_ipv4=None, | ||
lag_hash_ipv4_in_ipv4=None, | ||
lag_hash_ipv6=None, | ||
counter_refresh_interval=None, | ||
qos_default_tc=None, | ||
qos_dot1p_to_tc_map=None, | ||
qos_dot1p_to_color_map=None, | ||
qos_dscp_to_tc_map=None, | ||
qos_dscp_to_color_map=None, | ||
qos_tc_to_queue_map=None, | ||
qos_tc_and_color_to_dot1p_map=None, | ||
qos_tc_and_color_to_dscp_map=None, | ||
switch_shell_enable=None, | ||
switch_profile_id=None, | ||
switch_hardware_info=None, | ||
firmware_path_name=None, | ||
switch_state_change_notify=None, | ||
switch_shutdown_request_notify=None, | ||
fdb_event_notify=None, | ||
port_state_change_notify=None, | ||
packet_event_notify=None, | ||
fast_api_enable=None, | ||
mirror_tc=None, | ||
queue_pfc_deadlock_notify=None, | ||
pfc_dlr_packet_action=None, | ||
pfc_tc_dld_interval=None, | ||
pfc_tc_dlr_interval=None, | ||
tpid_outer_vlan=None, | ||
tpid_inner_vlan=None, | ||
crc_check_enable=None, | ||
crc_recalculation_enable=None, | ||
bfd_session_state_change_notify=None, | ||
ecn_ect_threshold_enable=None, | ||
vxlan_default_router_mac=None, | ||
vxlan_default_port=None, | ||
uninit_data_plane_on_removal=None, | ||
tam_object_id=None, | ||
tam_event_notify=None, | ||
pre_shutdown=None, | ||
nat_zone_counter_object_id=None, | ||
nat_enable=None, | ||
firmware_download_broadcast=None, | ||
firmware_load_method=None, | ||
firmware_load_type=None, | ||
firmware_download_execute=None, | ||
firmware_broadcast_stop=None, | ||
firmware_verify_and_init_switch=None, | ||
type=None, | ||
macsec_object_id=None, | ||
qos_mpls_exp_to_tc_map=None, | ||
qos_mpls_exp_to_color_map=None, | ||
qos_tc_and_color_to_mpls_exp_map=None, | ||
failover_config_mode=None, | ||
tunnel_objects_list=None): | ||
return 0 |
Oops, something went wrong.