Skip to content

Commit 2d2749a

Browse files
authored
[xcvrd] add debug logs for y_cable change events/probes (sonic-net#195)
This PR adds support for logging required in debugging events for change/probe requests received by xcvrd from swss and linkmgr into state DB. a typical log would look like this: Jun 17 05:55:39.302379 NOTICE pmon#xcvrd[33]: Y_CABLE_DEBUG: trying to enable/disable debug logs Jun 17 05:55:39.302379 NOTICE pmon#xcvrd[33]: Y_CABLE_DEBUG: received an event for port transition Ethernet4 Jun 17 05:55:39.302575 NOTICE pmon#xcvrd[33]: Y_CABLE_DEBUG: xcvrd trying to transition port Ethernet4 from standby to active Jun 17 05:55:39.307872 NOTICE pmon#xcvrd[33]: Y_CABLE_DEBUG: Successful in toggling mux to ToR A for port 2 where both probe events and change events are logged inside xcvrd. Motivation and Context This is required for xcvrd to log the events which it receives from other modules when we want to see the completion of events as to what triggered the event and at which stage it failed without restarting pmon/xcvrd Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent b2c6102 commit 2d2749a

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def update_table_mux_status_for_response_tbl(table_name, status, logical_port_na
6868
fvs = swsscommon.FieldValuePairs([('response', status)])
6969
table_name.set(logical_port_name, fvs)
7070

71+
helper_logger.log_debug("Y_CABLE_DEBUG: Successful in returning probe port status {}".format(logical_port_name))
72+
7173

7274
def update_table_mux_status_for_statedb_port_tbl(table_name, status, read_side, active_side, logical_port_name):
7375
fvs = swsscommon.FieldValuePairs([('state', status),
@@ -78,6 +80,8 @@ def update_table_mux_status_for_statedb_port_tbl(table_name, status, read_side,
7880

7981
def y_cable_toggle_mux_torA(physical_port):
8082
update_status = y_cable.toggle_mux_to_torA(physical_port)
83+
84+
helper_logger.log_debug("Y_CABLE_DEBUG: Status of toggling mux to ToR A for port {} {}".format(physical_port, update_status))
8185
if update_status is True:
8286
return 1
8387
else:
@@ -88,6 +92,8 @@ def y_cable_toggle_mux_torA(physical_port):
8892

8993
def y_cable_toggle_mux_torB(physical_port):
9094
update_status = y_cable.toggle_mux_to_torB(physical_port)
95+
96+
helper_logger.log_debug("Y_CABLE_DEBUG: Status of toggling mux to ToR B for port {} {}".format(physical_port, update_status))
9197
if update_status is True:
9298
return 2
9399
else:
@@ -173,6 +179,8 @@ def update_appdb_port_mux_cable_response_table(logical_port_name, asic_index, ap
173179
helper_logger.log_warning(
174180
"Error: Could not get state for mux cable port probe command logical port {} and physical port {}".format(logical_port_name, physical_port))
175181

182+
helper_logger.log_debug("Y_CABLE_DEBUG: notifying a probe for port status {} {}".format(logical_port_name, status))
183+
176184
update_table_mux_status_for_response_tbl(y_cable_response_tbl[asic_index], status, logical_port_name)
177185

178186
else:
@@ -347,17 +355,21 @@ def init_ports_status_for_y_cable(platform_sfp, platform_chassis, y_cable_presen
347355
config_db, state_db, port_tbl, y_cable_tbl = {}, {}, {}, {}
348356
static_tbl, mux_tbl = {}, {}
349357
port_table_keys = {}
358+
xcvrd_log_tbl = {}
350359

351360
y_cable_platform_sfputil = platform_sfp
352361
y_cable_platform_chassis = platform_chassis
353362

363+
fvs_updated = swsscommon.FieldValuePairs([('enable_log', 'false')])
354364
# Get the namespaces in the platform
355365
namespaces = multi_asic.get_front_end_namespaces()
356366
for namespace in namespaces:
357367
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
358368
config_db[asic_id] = daemon_base.db_connect("CONFIG_DB", namespace)
359369
port_tbl[asic_id] = swsscommon.Table(config_db[asic_id], "MUX_CABLE")
360370
port_table_keys[asic_id] = port_tbl[asic_id].getKeys()
371+
xcvrd_log_tbl[asic_id] = swsscommon.Table(config_db[asic_id], "XCVRD_LOG")
372+
xcvrd_log_tbl[asic_id].set("Y_CABLE", fvs_updated )
361373

362374
# Init PORT_STATUS table if ports are on Y cable
363375
logical_port_list = y_cable_platform_sfputil.logical
@@ -996,10 +1008,11 @@ def __init__(self):
9961008
def task_worker(self):
9971009

9981010
# Connect to STATE_DB and APPL_DB and get both the HW_MUX_STATUS_TABLE info
999-
appl_db, state_db, status_tbl, y_cable_tbl = {}, {}, {}, {}
1011+
appl_db, state_db, config_db, status_tbl, y_cable_tbl = {}, {}, {}, {}, {}
10001012
y_cable_tbl_keys = {}
10011013
mux_cable_command_tbl, y_cable_command_tbl = {}, {}
10021014
mux_metrics_tbl = {}
1015+
xcvrd_log_tbl = {}
10031016

10041017
sel = swsscommon.Select()
10051018

@@ -1009,6 +1022,7 @@ def task_worker(self):
10091022
# Open a handle to the Application database, in all namespaces
10101023
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
10111024
appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace)
1025+
config_db[asic_id] = daemon_base.db_connect("CONFIG_DB", namespace)
10121026
status_tbl[asic_id] = swsscommon.SubscriberStateTable(
10131027
appl_db[asic_id], swsscommon.APP_HW_MUX_CABLE_TABLE_NAME)
10141028
mux_cable_command_tbl[asic_id] = swsscommon.SubscriberStateTable(
@@ -1020,9 +1034,12 @@ def task_worker(self):
10201034
state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME)
10211035
mux_metrics_tbl[asic_id] = swsscommon.Table(
10221036
state_db[asic_id], swsscommon.STATE_MUX_METRICS_TABLE_NAME)
1037+
xcvrd_log_tbl[asic_id] = swsscommon.SubscriberStateTable(
1038+
config_db[asic_id], "XCVRD_LOG")
10231039
y_cable_tbl_keys[asic_id] = y_cable_tbl[asic_id].getKeys()
10241040
sel.addSelectable(status_tbl[asic_id])
10251041
sel.addSelectable(mux_cable_command_tbl[asic_id])
1042+
sel.addSelectable(xcvrd_log_tbl[asic_id])
10261043

10271044
# Listen indefinitely for changes to the HW_MUX_CABLE_TABLE in the Application DB's
10281045
while True:
@@ -1048,9 +1065,12 @@ def task_worker(self):
10481065

10491066
while True:
10501067
(port, op, fvp) = status_tbl[asic_index].pop()
1068+
10511069
if not port:
10521070
break
10531071

1072+
helper_logger.log_debug("Y_CABLE_DEBUG: received an event for port transition {}".format(port))
1073+
10541074
# entering this section signifies a start for xcvrd state
10551075
# change request from swss so initiate recording in mux_metrics table
10561076
time_start = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
@@ -1075,6 +1095,7 @@ def task_worker(self):
10751095
old_status = mux_port_dict.get("state")
10761096
read_side = mux_port_dict.get("read_side")
10771097
# Now whatever is the state requested, toggle the mux appropriately
1098+
helper_logger.log_debug("Y_CABLE_DEBUG: xcvrd trying to transition port {} from {} to {}".format(port, old_status, new_status))
10781099
active_side = update_tor_active_side(read_side, new_status, port)
10791100
if active_side == -1:
10801101
helper_logger.log_warning("ERR: Got a change event for toggle but could not toggle the mux-direction for port {} state from {} to {}, writing unknown".format(
@@ -1085,6 +1106,7 @@ def task_worker(self):
10851106
('read_side', read_side),
10861107
('active_side', str(active_side))])
10871108
y_cable_tbl[asic_index].set(port, fvs_updated)
1109+
helper_logger.log_debug("Y_CABLE_DEBUG: xcvrd successful to transition port {} from {} to {} and write back to the DB".format(port, old_status, new_status))
10881110
helper_logger.log_info("Got a change event for toggle the mux-direction active side for port {} state from {} to {}".format(
10891111
port, old_status, new_status))
10901112
time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
@@ -1097,8 +1119,11 @@ def task_worker(self):
10971119

10981120
while True:
10991121
(port_m, op_m, fvp_m) = mux_cable_command_tbl[asic_index].pop()
1122+
11001123
if not port_m:
11011124
break
1125+
helper_logger.log_debug("Y_CABLE_DEBUG: received a probe for port status {}".format(port_m))
1126+
11021127
if fvp_m:
11031128

11041129
if port_m not in y_cable_tbl_keys[asic_index]:
@@ -1120,6 +1145,30 @@ def task_worker(self):
11201145
read_side = mux_port_dict.get("read_side")
11211146
update_appdb_port_mux_cable_response_table(port_m, asic_index, appl_db, int(read_side))
11221147

1148+
while True:
1149+
(key, op_m, fvp_m) = xcvrd_log_tbl[asic_index].pop()
1150+
1151+
if not key:
1152+
break
1153+
1154+
helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable debug logs")
1155+
if fvp_m:
1156+
1157+
if key is "Y_CABLE":
1158+
continue
1159+
1160+
fvp_dict = dict(fvp_m)
1161+
if "log_verbosity" in fvp_dict:
1162+
# check if xcvrd got a probe command
1163+
probe_identifier = fvp_dict["log_verbosity"]
1164+
1165+
if probe_identifier == "debug":
1166+
helper_logger.set_min_log_priority_debug()
1167+
1168+
elif probe_identifier == "notice":
1169+
helper_logger.set_min_log_priority_notice()
1170+
1171+
11231172
def task_run(self):
11241173
self.task_thread = threading.Thread(target=self.task_worker)
11251174
self.task_thread.start()

0 commit comments

Comments
 (0)