Fix show macsec crash after deleting macsec ports#28585
Conversation
Signed-off-by: Darius Grassi <darius@nexthop.ai>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
This PR has backport request for branch(es): 202511. ---Powered by SONiC BuildBot
|
|
This PR has backport request label(s) for branch(es): 202511, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202511: <test result>) in the Test result section as well in your PR description. ---Powered by SONiC BuildBot
|
|
/azp run Azure.sonic-buildimage |
|
Commenter does not have sufficient privileges for PR 28585 in repo sonic-net/sonic-buildimage |
Signed-off-by: Darius Grassi <darius@nexthop.ai>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
This PR has backport request for branch(es): 202511,202605. ---Powered by SONiC BuildBot
|
|
The Tested branch section has been ticked and Test result is provided for branch(es): 202511. Added label(s): Tested for 202511 Branch. ---Powered by SONiC BuildBot
|
|
This PR has backport request label(s) for branch(es): 202605, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202605: <test result>) in the Test result section as well in your PR description. ---Powered by SONiC BuildBot
|
|
Hi — this PR is flagged for cherry-pick to the 202605 branch (
This helps us track readiness and ensures we don't cherry-pick untested changes. Thanks! Comment by @vaibhavhd via automated tooling |
Why I did it
config macsec port del <port>removes themacsecfield from the CONFIG_DB PORT entry immediately, while the APPL_DB MACSEC_PORT_TABLE entry is cleaned up asynchronously by macsecmgrd. Ifshow macsecruns in that window (for example, while deleting several ports at once),MACsecPort.dump_strfinds the APPL_DB entry but nomacsecfield in CONFIG_DB and crashes:The error is transient and re-running
show macsecafter teardown completes succeeds.fixes #28584
Work item tracking
How I did it
Switch to
self.cfgMeta.get("macsec", "")inMACsecPort.dump_strIf a port is mid-teardown, it will be shown with an empty profile instead of crashing, e.g.:
Reasoning is that the port still exists in APPL_DB, so we should still show the port in
show macsecwhile it is still programmed. This output is transient and the port will simply disappear once macsecmgrd has unprogrammed it.Also adds a guard for the port append in
create_macsec_objsagainst None result fromcreate_macsec_obj.How to verify it
New regression test
test_show_port_deleted_from_config: Ethernet5 in the mock DBs has an APPL_DBMACSEC_PORT_TABLEentry but nomacsecfield in CONFIG_DB (the mid-teardown state). Without the fix,test_show_alland the new test both crash with the KeyError above; with the fix the port shows with an empty profile and all macsec cli-plugin-tests pass.Which release branch to backport (provide reason below if selected)
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO): #28584
Failure type: day-one issue
Tested branch
Test result
(with fix)
202511:
Description for the changelog
Fix
show macsecKeyError crash when run while MACsec port deletion is still being processed.Link to config_db schema for YANG module changes
N/A
A picture of a cute animal (not mandatory but encouraged)