Skip to content

[muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table#3857

Merged
prgeor merged 2 commits intosonic-net:masterfrom
mihirpat1:muxcable_transceiver_info
Apr 22, 2025
Merged

[muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table#3857
prgeor merged 2 commits intosonic-net:masterfrom
mihirpat1:muxcable_transceiver_info

Conversation

@mihirpat1
Copy link
Copy Markdown
Contributor

@mihirpat1 mihirpat1 commented Apr 16, 2025

What I did

xcvrd will now move the status field from the TRANSCEIVER_STATUS table to the TRANSCEIVER_STATUS_SW table. This is being done via the below PRs

Update CMIS diagnostics monitoring HLD with TRANSCEIVER_STATUS_SW table by mihirpat1 · Pull Request #1964 · sonic-net/SONiC
[xcvrd] Re-organize transceiver DOM and STATUS tables by mihirpat1 · Pull Request #604 · sonic-net/sonic-platform-daemons

Therefore, the corresponding CLIs that rely on the TRANSCEIVER_STATUS table for retrieving transceiver presence need to be changed.

However, a more robust method to retrieve transceiver presence is by checking if the TRANSCEIVER_INFO table is present. Thus, the relevant code change will be made to address this.

How I did it

The CLI handler now looks at the TRANSCEIVER_INFO table to find transceiver presence

How to verify it

No change in output when command is executed after putting the change manaully

admin@sonic:~$ show mux grpc mux
Port        Direction    Presence    PeerDirection    ConnectivityState
----------  -----------  ----------  ---------------  -------------------
Ethernet4   unknown      True        unknown          unknown
Ethernet8   unknown      True        unknown          unknown
Ethernet12  unknown      True        unknown          unknown
Ethernet16  unknown      True        unknown          unknown
Ethernet20  unknown      True        unknown          unknown
Ethernet24  unknown      True        unknown          unknown
Ethernet28  unknown      True        unknown          unknown

For the case where TRANSCEIVER_INFO table is missing by manually deleteing it for example on Port Ethernet4

admin@sonic:~$ redis-cli -n 6 DEL "TRANSCEIVER_INFO|Ethernet4"
(integer) 1
admin@sonic:~$ show mux grpc mux
Port        Direction    Presence    PeerDirection    ConnectivityState
----------  -----------  ----------  ---------------  -------------------
Ethernet4   standby      False       standby          READY
Ethernet8   standby      True        standby          READY

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

MSFT ADO - 32337615

@mihirpat1 mihirpat1 requested a review from Copilot April 16, 2025 04:41
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • tests/mock_tables/state_db.json: Language not supported

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mihirpat1 mihirpat1 requested review from prgeor and vdahiya12 April 16, 2025 04:42
@mihirpat1 mihirpat1 changed the title [muxcable] Add grpc CLI support for transceiver presence retrieval fr… [muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table Apr 16, 2025
prgeor
prgeor previously approved these changes Apr 16, 2025
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.

show/muxcable.py Outdated
@@ -2187,9 +2187,8 @@ def get_grpc_cached_version_mux_direction_per_port(db, port):

trans_dir = {}
trans_dir = trans_info_full_dict[asic_index]
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.

shall we add a get call here, that would be easier to read the code below

trans_dir = trans_info_full_dict.get(asic_index, None)

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 Makes sense. Added it now.

@vdahiya12
Copy link
Copy Markdown
Contributor

Do we have a negative test case, to give presence as False if table not populated?

please check.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mihirpat1 mihirpat1 requested a review from Copilot April 18, 2025 00:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds gRPC CLI support for transceiver presence retrieval by switching from the TRANSCEIVER_STATUS table to checking the TRANSCEIVER_INFO table.

  • The CLI handler now retrieves transceiver data from TRANSCEIVER_INFO.
  • Test expectations have been updated to reflect the revised presence evaluation.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/muxcable_test.py Expected output updated: presence for Ethernet0 changed from False to True.
show/muxcable.py Modified get_grpc_cached_version_mux_direction_per_port to use TRANSCEIVER_INFO.
Files not reviewed (1)
  • tests/mock_tables/state_db.json: Language not supported

Comment on lines +2191 to 2192
presence = "True" if trans_dir else "False"

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.
@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to msft-202412: Azure/sonic-utilities.msft#171

mihirpat1 added a commit to mihirpat1/sonic-utilities that referenced this pull request May 6, 2025
…om TRANSCEIVER_INFO table (sonic-net#3857)

* [muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table

Signed-off-by: Mihir Patel <[email protected]>

* Using .get method to initialize trans_dir

---------

Signed-off-by: Mihir Patel <[email protected]>
stepanblyschak pushed a commit to stepanblyschak/sonic-utilities that referenced this pull request May 20, 2025
…ted changes (sonic-net#170)

* [muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table (sonic-net#3857)

* [muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table

Signed-off-by: Mihir Patel <[email protected]>

* Using .get method to initialize trans_dir

---------

Signed-off-by: Mihir Patel <[email protected]>

* Transceiver CLI changes to support DOM and STATUS table related changes

Signed-off-by: Mihir Patel <[email protected]>

---------

Signed-off-by: Mihir Patel <[email protected]>
nmoray pushed a commit to nmoray/sonic-utilities that referenced this pull request Jun 25, 2025
…om TRANSCEIVER_INFO table (sonic-net#3857)

* [muxcable] Add grpc CLI support for transceiver presence retrieval from TRANSCEIVER_INFO table

Signed-off-by: Mihir Patel <[email protected]>

* Using .get method to initialize trans_dir

---------

Signed-off-by: Mihir Patel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants