Skip to content

Added detailed reason for assert failure for bgp,sonic,sfp#18777

Merged
StormLiangMS merged 8 commits intosonic-net:masterfrom
bachalla:assert_add
Jun 21, 2025
Merged

Added detailed reason for assert failure for bgp,sonic,sfp#18777
StormLiangMS merged 8 commits intosonic-net:masterfrom
bachalla:assert_add

Conversation

@bachalla
Copy link
Copy Markdown
Contributor

@bachalla bachalla commented Jun 3, 2025

Description of PR

Added detailed Reason for Assert failure

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
  • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

@bachalla bachalla requested a review from ZhaohuiS June 3, 2025 15:51
"- Output: {}\n"
).format(
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
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.

Not sure how many keys in routes_json, but for this assert, it's better to print out routes_json['totalPrefixCounter']

"- Output: {}\n"
).format(
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
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.

for this assert, it's better to print out routes_json['totalPrefixCounter']

"- Output: {}\n"
).format(
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
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.

for this assert, it's better to print out routes_json['totalPrefixCounter']

).format(
routes_json['totalPrefixCounter'],
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
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.

Don't print routes_json out, just printing out routes_json['totalPrefixCounter'] is enough

"- Output: {}\n"
).format(
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
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.

Please just print out routes_json['totalPrefixCounter']

"Expected: {expected}, Actual: {actual}. "
"- Command: {cmd}\n"
).format(
expected=original_ipv4_route_adv_filter_count,
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.

why do you use another format to print the variables, please keep the format same consistently.

).format(
bgp_nbr_recv_cmd if 'bgp_nbr_recv_cmd' in locals() else 'N/A',
routes_json
)
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.

Pls print out routes_json['totalPrefixCounter']

r.status_code,
url,
data,
r.text
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.

Does r have text? If you are not sure, please remove it, otherwise it will cause exception and fail the case

"Check the process status with 'ps -ef | grep orchagent', review DUT logs, "
"and ensure no supervisor is restarting the process."
).format(duthost.hostname)

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.

For those ones have failed reason, I don't suggest to change it. That's the author intention.

disable_dom_result = self.duthost.command(self.cmd_disable_dom)
assert disable_dom_result["rc"] == 0, \
"Disable DOM polling failed for {}".format(self.logical_intf)
assert disable_dom_result["rc"] == 0, (
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.

For those ones have failed reason, I don't suggest to change it. That's the author intention.

shutdown_result = self.duthost.command(self.cmd_down)
assert shutdown_result["rc"] == 0, "Shutdown {} failed".format(self.logical_intf)
assert check_interface_status(self.duthost, [self.logical_intf], expect_up=False)
assert shutdown_result["rc"] == 0, (
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.

For those ones have failed reason, I don't suggest to change it. That's the author intention.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

assert sfp_presence['rc'] == 0, "Run command '{}' failed".format(cmd_sfp_presence)
assert sfp_presence['rc'] == 0, (
"Run command '{}' failed with return code {}. "
"This means the 'sfputil show presence' command did not execute successfully on the DUT. "
Copy link
Copy Markdown
Contributor

@ZhaohuiS ZhaohuiS Jun 6, 2025

Choose a reason for hiding this comment

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

Please remove these 2 indication lines. Just print out the reason is enough, don't need to explain or tell the user how to do debug it. "This means.." is not necessary at all

Comment on lines +376 to +379
"This means the SFP module is not detected as present on this interface. "
"Please verify the SFP module is properly inserted and operational, check compatibility, "
"run 'sfputil show presence' manually, and review DUT logs for related errors."
).format(intf)
Copy link
Copy Markdown
Contributor

@ZhaohuiS ZhaohuiS Jun 6, 2025

Choose a reason for hiding this comment

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

Please remove these 3 indication lines. Just print out the reason is enough, don't need to explain or tell the user how to do debug it. "This means.." is not necessary at all

assert sfp_eeprom['rc'] == 0, (
"Run command '{}' failed with return code {}. "
"This means the 'sfputil show eeprom' command did not execute successfully on the DUT. "
"Please check the command output, DUT logs, and platform status for troubleshooting."
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.

"This means.." is not necessary at all, please remove them.

expect_up=True
), (
"Not all interfaces that are admin up transitioned to the 'up' state after SFP reset. "
"This means one or more interfaces expected to be operationally up are still down. "
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.

"This means.." is not necessary at all. Just tell the failed reason, no need to tell user how to debug or fix it. Make the summary clean and clear.

assert wait_until(300, 10, 0, check_docker_status, duthost)
assert wait_until(300, 10, 0, check_docker_status, duthost), (
"Not all Docker containers reached the 'fully started' state within 300 seconds after config reload."
).format()
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.

same as above


assert wait_until(360, 20, 0, config_system_checks_passed, duthost, delayed_services), (
"System checks did not pass within the allotted time after config reload."
).format()
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.

Please remove format if there is no variable, or add some variables in format.


assert wait_until(360, 20, 0, config_system_checks_passed, duthost, delayed_services), (
"System checks did not pass within the allotted time after config reload."
).format()
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.

Please remove format if there is no variable, or add some variables in format.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

@ZhaohuiS ZhaohuiS left a comment

Choose a reason for hiding this comment

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

Looks good to me now.

@ZhaohuiS
Copy link
Copy Markdown
Contributor

ZhaohuiS commented Jun 9, 2025

@StormLiangMS Please help review. Thanks.

@ZhaohuiS
Copy link
Copy Markdown
Contributor

@bachalla Please add abstracted scripts name in the title.

@bachalla bachalla changed the title Added detailed reason for assert failure Added detailed reason for assert failure for bgp,sonic,sfp Jun 16, 2025
Copy link
Copy Markdown
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

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

hi @bachalla @ZhaohuiS I think this enhancement is great and will be very helpful for issue triage. Would you mind creating a document that categorizes the enhancements made for each case? I'd like to include this as part of the best practices in the sonic-mgmt codebase.

@StormLiangMS StormLiangMS merged commit 903edbe into sonic-net:master Jun 21, 2025
18 checks passed
mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Jun 21, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.
@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202505: #19125

mssonicbld pushed a commit that referenced this pull request Jun 21, 2025
Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.
nissampa pushed a commit to nissampa/sonic-mgmt_dpu_test that referenced this pull request Aug 7, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.
opcoder0 pushed a commit to opcoder0/sonic-mgmt that referenced this pull request Dec 8, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: opcoder0 <110003254+opcoder0@users.noreply.github.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 16, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this pull request Dec 16, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: Aharon Malkin <amalkin@nvidia.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 21, 2025
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
venu-nexthop pushed a commit to venu-nexthop/sonic-mgmt that referenced this pull request Jan 13, 2026
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Jan 26, 2026
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
ytzur1 pushed a commit to ytzur1/sonic-mgmt that referenced this pull request Feb 2, 2026
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.

Signed-off-by: Yael Tzur <ytzur@nvidia.com>
venu-nexthop pushed a commit to venu-nexthop/sonic-mgmt that referenced this pull request Mar 27, 2026
…#18777)

Summary:

Enhanced assertion messages in selected test cases to provide clearer failure context. This improves debuggability and speeds up issue resolution when tests fail.
Added detailed assertion failure messages in test scripts to make it easier to understand why tests fails.

What is the motivation for this PR?
The motivation is to improve test debuggability by adding detailed failure reasons in assertions for selected test cases. This enhancement makes it easier to identify the root cause of test failures in logs, thereby reducing triage time and simplifying test maintenance.

How did you do it?
I updated the assertion statements in the following test files to include descriptive error messages:
tests/bgp/test_bgp_azng_migration.py
tests/bgp/test_bgp_suppress_fib.py
tests/common/devices/sonic.py
tests/platform_tests/sfp/test_sfputil.py
tests/platform_tests/sfp/test_show_intf_xcvr.py
tests/platform_tests/test_reload_config.py

How did you verify/test it?
Verified that the updated assertion messages are correctly reflected in the test code by reviewing the changes locally.
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.

5 participants