Skip to content

[route_check]: Add truncation indicator and mismatch summary counts#4587

Open
Bojun-Feng wants to merge 3 commits into
sonic-net:masterfrom
Bojun-Feng:enh/route-check-truncation-summary
Open

[route_check]: Add truncation indicator and mismatch summary counts#4587
Bojun-Feng wants to merge 3 commits into
sonic-net:masterfrom
Bojun-Feng:enh/route-check-truncation-summary

Conversation

@Bojun-Feng

Copy link
Copy Markdown
Contributor

What I did

Fix sonic-net/sonic-buildimage#27509

Added a truncation indicator and mismatch summary counts to route_check.py failure output.

When print_message() truncates output at PRINT_MSG_LEN_MAX (1000 chars), it now appends ... (truncated) within the length budget so operators know data was omitted. Additionally, a compact per-namespace mismatch count summary line is emitted before the detailed (potentially truncated) JSON dump.

How I did it

  • Add PRINT_MSG_TRUNCATION_SUFFIX module-level constant and truncation marker logic in print_message() that keeps total length ≤ PRINT_MSG_LEN_MAX
  • Extract summarize_results() helper to produce {namespace: {category: count}} dict
  • Emit compact summary via json.dumps(..., separators=(",",":")) before the detailed failure results in both check_routes() and check_sids()

How to verify it

  1. Run existing test_logging — confirms backward compatibility (all length assertions pass unchanged)
  2. Run new test_logging_truncation_indicator — confirms truncation suffix behavior at realistic PRINT_MSG_LEN_MAX=50, short message passthrough, and edge case where max < suffix length
  3. Manually: inject 200+ route mismatches on a VS image, run route_check.py -l INFO, verify summary count line appears and truncated output ends with ... (truncated)

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

Failure results: {
    "": {
        "missed_ROUTE_TABLE_routes": [
            "2001:db8:1001::/64",
            "2001:db8:1002::/64",
            "2001:db8:10
Failed. Look at reported mismatches above

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

Route mismatch counts: {"":{"missed_ROUTE_TABLE_routes":47,"missed_INTF_TABLE_entries":2}}
Failure results: {
    "": {
        "missed_ROUTE_TABLE_routes": [
            "2001:db8:1001::/64",
            "2001:db8:1002::/64",
            "2001:db8:10 ... (truncated)
Failed. Look at reported mismatches above

* Add PRINT_MSG_TRUNCATION_SUFFIX constant and truncation marker within PRINT_MSG_LEN_MAX budget
* Extract summarize_results() helper for per-namespace mismatch counts
* Add test_logging_truncation_indicator with coverage for suffix, short msg, and edge cases

Signed-off-by: Bojun-Feng <bojundf@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

* Break long print_message calls to fit within 120 char limit

Signed-off-by: Bojun-Feng <bojundf@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

* Align continuation lines to opening parenthesis

Signed-off-by: Bojun-Feng <bojundf@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

route_check.py truncates large failure reports without showing mismatch counts

2 participants