Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show][interface] Add changes for show interface errors command #3721

Merged
merged 13 commits into from
Jan 23, 2025

Conversation

vdahiya12
Copy link
Contributor

@vdahiya12 vdahiya12 commented Jan 17, 2025

MSFT ADO 30169175

What I did

This pull request introduces a new subcommand to the show interfaces command, allowing users to view error statistics for network interfaces. The new errors subcommand displays a table of potential interface errors, including error types, counts, and the last timestamp (in UTC) when the error occurred. If an error has not been encountered, the count defaults to 0, and the timestamp is displayed as Never. This change helps users easily identify any issues with their network interfaces and track error occurrences.

How I did it

To implement the errors subcommand, added a new command handler to the show/interfaces/init.py file. The handler retrieves the error data for a specified interface from the PORT_OPERR_TABLE in the database. The error types are predefined in a list, and for each type, the count and timestamp are pulled from the table. The results are then formatted into a table using the tabulate library, sorted alphabetically by error type.

How to verify it

UT and running the changes on a testbed

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)


admin@sonic$ show int errors Ethernet76
Port Errors                     Count  Last timestamp(UTC)
----------------------------  -------  ---------------------
code group error                    0  Never
crc rate                            0  Never
data unit crc error                 0  Never
data unit misalignment error        0  Never
data unit size                      0  Never
fec alignment loss                  0  Never
fec sync loss                       0  Never
high ber error                      0  Never
high ser error                      0  Never
mac local fault                     0  Never
mac remote fault                 7908  2025-01-17 19:34:13
no rx reachability                  0  Never
oper error status                   0  Never
signal local error                  0  Never

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vdahiya12 vdahiya12 changed the title [show][interface] Add changes for interface errors command [show][interface] Add changes for show interface errors command Jan 17, 2025
Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vdahiya12 vdahiya12 requested a review from prgeor January 17, 2025 20:29
Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

show/interfaces/__init__.py Outdated Show resolved Hide resolved
Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

body.append([error.replace('_', ' '), count, timestamp])

# Sort the body for consistent display
body.sort(key=lambda x: x[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

@vdahiya12 can you double check if there is enough space the columns as displayed in the CLI command document?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checked with the sample test output, we should be good

Comment on lines 426 to 435
db = SonicV2Connector(host=REDIS_HOSTIP)
db.connect(db.STATE_DB)

# Retrieve the errors data from the PORT_OPERR_TABLE
port_operr_table = db.get_all(db.STATE_DB, 'PORT_OPERR_TABLE|{}'.format(interfacename))
db.close(db.STATE_DB)

# Ensure port_operr_table is a dictionary
port_operr_table = port_operr_table or {}

Copy link
Contributor

Choose a reason for hiding this comment

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

@vdahiya12 maybe we can capture this in a function get_all_port_errors()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

port_operr_table = db.get_all(db.STATE_DB, 'PORT_OPERR_TABLE|{}'.format(interfacename))
db.close(db.STATE_DB)

# Ensure port_operr_table is a dictionary
Copy link
Contributor

Choose a reason for hiding this comment

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

@vdahiya12 not sure why we need this. The db value is always a key /value pari

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prgeor prgeor merged commit ddccabe into sonic-net:master Jan 23, 2025
7 checks passed
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.

3 participants