Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ def get_grpc_cached_version_mux_direction_per_port(db, port):
mux_info_full_dict[asic_index] = state_db[asic_index].get_all(
state_db[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port))
trans_info_full_dict[asic_index] = state_db[asic_index].get_all(
state_db[asic_index].STATE_DB, 'TRANSCEIVER_STATUS|{}'.format(port))
state_db[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) or {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the or condition here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vdahiya12 The or condition is just to ensure that an empty dictionary is returned rather None to avoid a crash.


res_dir = {}
res_dir = mux_info_full_dict[asic_index]
Expand All @@ -2186,10 +2186,9 @@ def get_grpc_cached_version_mux_direction_per_port(db, port):
mux_info_dict["grpc_connection_status"] = res_dir.get("grpc_connection_status", None)

trans_dir = {}
trans_dir = trans_info_full_dict[asic_index]

status = trans_dir.get("status", "0")
presence = "True" if status == "1" else "False"
trans_dir = trans_info_full_dict.get(asic_index, None)

presence = "True" if trans_dir else "False"

Comment on lines +2191 to 2192
Copy link

Copilot AI Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the logic for determining transceiver presence correctly handles cases where the TRANSCEIVER_INFO table exists but returns an empty dictionary. If an empty dictionary should imply absence, the current condition is valid; otherwise, please adjust the condition accordingly.

Suggested change
presence = "True" if trans_dir else "False"
if trans_dir is not None: # Table exists
presence = "True" # Treat empty dictionary as presence
else:
presence = "False" # Table does not exist

Copilot uses AI. Check for mistakes.
mux_info_dict["presence"] = presence

Expand Down
17 changes: 17 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,23 @@
"status": "67",
"error": "Blocking Error|High temperature"
},
"TRANSCEIVER_INFO|Ethernet4": {
"type": "SFP28 25G Pluggable Transceiver",
"hardware_rev": "X.X",
"serial": "0123456789",
"manufacturer": "XXXX",
"model": "XXX",
"connector": "LC",
"encoding": "N/A",
"ext_identifier": "Power Class 1 (0.5W Max)",
"ext_rateselect_compliance": "N/A",
"cable_type": "Length Cable Assembly(m)",
"cable_length": "0.0",
"nominal_bit_rate": "0",
"specification_compliance": "sm_media_interface",
"vendor_date": "2021-11-19",
"vendor_oui": "XX-XX-XX"
},
"TRANSCEIVER_STATUS|Ethernet4": {
"status": "1",
"error": "N/A",
Expand Down
4 changes: 2 additions & 2 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@
show_muxcable_grpc_muxdirection_active_expected_all_output = """\
Port Direction Presence PeerDirection ConnectivityState
--------- ----------- ---------- --------------- -------------------
Ethernet0 active False active READY
Ethernet0 active True active READY
"""

show_muxcable_grpc_muxdirection_active_expected_all_output_json = """\
{
"HWMODE": {
"Ethernet0": {
"Direction": "active",
"Presence": "False",
"Presence": "True",
"PeerDirection": "active",
"ConnectivityState": "READY"
}
Expand Down
Loading