Skip to content

sonic: Fix STATIC_ROUTE clobber in OOB management path#2238

Open
ideaship wants to merge 1 commit intomainfrom
fix/static-route-clobber
Open

sonic: Fix STATIC_ROUTE clobber in OOB management path#2238
ideaship wants to merge 1 commit intomainfrom
fix/static-route-clobber

Conversation

@ideaship
Copy link
Copy Markdown
Contributor

Summary

  • generate_sonic_config() reset STATIC_ROUTE to {} before writing the management default route, silently discarding any routes loaded from /etc/sonic/config_db.json on every sync.
  • The reset was introduced in f4f2290 when base config loading did not exist yet — it was harmless at the time and went unnoticed when base config loading was added later.
  • Fix: write the management route directly into the existing dict without resetting it first.

Test plan

🤖 Generated with Claude Code

When a device has an OOB IP, generate_sonic_config() built the
management default route by first resetting STATIC_ROUTE to an empty
dict and then writing the single route into it:

    config["STATIC_ROUTE"] = {}
    config["STATIC_ROUTE"]["mgmt|0.0.0.0/0"] = {"nexthop": metalbox_ip}

The assignment discards any routes loaded from /etc/sonic/config_db.json
before reaching this point, silently wiping them on every sync.

The reset was introduced in f4f2290 ("sonic: Add static default route
in mgmt VRF"), at a time when config_db.json base loading did not exist
yet. config was always an empty dict at that point, so the = {} was
effectively an initialisation and cost nothing. Base config loading was
added later, making the reset destructive without anyone noticing.

Fix by writing the management route directly into the existing dict
without resetting it first.

AI-assisted: Claude Code
Signed-off-by: Roger Luethi <[email protected]>
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • When writing to config["STATIC_ROUTE"]["mgmt|0.0.0.0/0"], consider using config.setdefault("STATIC_ROUTE", {})[...] or otherwise ensuring the key is initialized so the function remains robust if called with a config that lacks a STATIC_ROUTE section.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When writing to `config["STATIC_ROUTE"]["mgmt|0.0.0.0/0"]`, consider using `config.setdefault("STATIC_ROUTE", {})[...]` or otherwise ensuring the key is initialized so the function remains robust if called with a config that lacks a `STATIC_ROUTE` section.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant