route_check: fix 'string indices must be integers' crash in FRR route mitigation#4657
Closed
cshivashgit wants to merge 1 commit into
Closed
Conversation
… mitigation
fetch_routes()/process_route_entry() collected bare prefix strings, but
mitigate_installed_not_offloaded_frr_routes() and its unit test
(test_mitigate_routes) expect dicts with 'prefix' and 'protocol' keys.
When SUPPRESS_FIB_PENDING is enabled and FRR has installed-not-offloaded
routes, mitigate indexed entry['prefix'] on a str -> TypeError
'string indices must be integers', causing route_check.py to return -1.
Collect {'prefix', 'protocol'} dicts in process_route_entry so mitigate
gets the protocol it needs for the FieldValuePairs notification, and
extract prefixes when populating missed_FRR_routes/failed_FRR_routes so
the reported/result format stays unchanged. Update the unit-test mock to
return the same dict shape as the real fetch_routes.
Signed-off-by: Shivashankar CR <shivashankar.c.r@gmail.com>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
Closing this PR as changes are already merged as part of #4649 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
ixed a
route_check.pycrash —TypeError: string indices must be integers, not 'str'— that occurs during FRR route mitigation whenSUPPRESS_FIB_PENDINGis enabled.The
ijsonstreaming refactor offetch_routes()changed the data shape it produces:process_route_entry()started appending bare prefix strings to the missed/failed route lists. However, the downstream consumermitigate_installed_not_offloaded_frr_routes()(and its unit testtest_mitigate_routes) still expects dicts withprefixandprotocolkeys. When there are installed-but-not-offloaded FRR routes and FIB-suppress is enabled,mitigateindexesentry['prefix']on astr, raisingTypeError: string indices must be integers. This makescheck_routes()return-1, soroute_check.pyreports a failure even though routing is healthy.This is not caught by CI because the unit tests mock
check_frr_pending_routesto return strings and patchmitigate_installed_not_offloaded_frr_routesto a no-op, so the real string-vs-dict mismatch never executes.Crash:
How I did it
scripts/route_check.pyfetch_routes()/process_route_entry(): collect{'prefix': prefix, 'protocol': route_entry.get('protocol')}dicts instead of bare prefix strings, somitigatehas theprotocolit needs for theFieldValuePairsnotification it sends to fpmsyncd.check_routes_for_namespace(): extract the prefix when populatingresults["missed_FRR_routes"]/results["failed_FRR_routes"]and the failed-routes log message, so the reported/result format remains a list of prefix strings (no change to external output or existing test data).mitigate_installed_not_offloaded_frr_routes()is unchanged — it now receives the dict shape it always expected.tests/route_check_test.pymock_fetch_routeshelper to return the same{'prefix', 'protocol'}dict shape as the realfetch_routes, keeping the mock consistent with production behavior.How to verify it
Run the unit tests:
All cases pass, including
test_mitigate_routes(which exercises the dict contract directly).On a device with
SUPPRESS_FIB_PENDINGenabled, create an installed-but-not-offloaded FRR route condition (e.g. a selected BGP route present in APPL_DB whose offload flag has not been set in zebra) and run:Before the fix this aborts with
TypeError: string indices must be integersand a non-zero return code; after the fix it mitigates the route (sends theSWSS_RC_SUCCESSresponse) and returns success.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)
Backport: this fix also needs to be ported to the 202605