Skip to content

Allow to override the mgmt gateway of SONiC switches - #2948

Draft
berendt wants to merge 2 commits into
mainfrom
implement/issue-2396-sonic-mgmt-gateway
Draft

berendt wants to merge 2 commits into
mainfrom
implement/issue-2396-sonic-mgmt-gateway

Conversation

@berendt

@berendt berendt commented Nov 28, 2026

Copy link
Copy Markdown
Member

A SONiC switch can now get its management gateway from NetBox. If the rendered config context of a device has a valid IPv4 address under _segment_mgmt_gateway_ipv4, the config generator writes it as the next hop of STATIC_ROUTE["mgmt|0.0.0.0/0"] in place of the MetalBox IP. A device without the key gets the same config as before.

Closes #2396

Commits

  1. Allow to override the mgmt gateway of SONiC switches adds the key, the helper _get_mgmt_gateway_override, its call in generate_sonic_config, and the tests.
    • A prefix length is accepted and dropped.
    • An unset or empty value falls back to the MetalBox IP without a warning.
    • Any other value that is not an IPv4 address falls back to the MetalBox IP with a warning. Only strings are parsed, because ipaddress reads the integer 42 as 0.0.0.42.
    • An address outside the OOB network is used as given, with a warning.
    • If neither an override nor a MetalBox IP is found, the next hop stays None, as before. A test covers this.
    • NTP, DNS and the control-plane ACLs do not change.
  2. Document the SONiC mgmt gateway override adds docs/sonic-mgmt-gateway.md and links it in the README.

Verification

Run locally with the tool versions pinned in the OSISM Zuul roles:

  • Before the generator change, the two tests that expect the override as next hop failed because the route had the MetalBox IP or None. The new helper test file failed on import. All of them pass now.
  • pytest tests/unit/tasks/conductor/sonic: 844 passed (820 on main).
  • pytest: 4253 passed, 3 xfailed (4229 passed, 3 xfailed on main).
  • flake8 on the changed Python files, and black --check . and mypy on the whole repository: no findings.
  • The three existing OOB tests pass unmodified. The diff of their file only adds lines.
  • git diff --stat main -- tests/e2e/ files/sonic/ is empty. _add_ntp_configuration and _add_dns_configuration are identical to main.

Not exercised locally, only OSISM's Zuul can verify these:

  • python-osism-sonic-e2e passes against the unchanged goldens. The check pipeline of this pull request runs it, because the change is under osism/tasks/conductor/.
  • The check jobs flake8, python-black, mypy and python-osism-unit-tests pass. The check pipeline runs them too. The local runs above are evidence, not a replacement.

Deviations from the approved plan

None.

Open questions

None declined.

Noticed, not touched

  • osism sonic validate --generate (osism/commands/sonic.py:1361-1387) does not load the MetalBox cache. Only sync_sonic does (osism/tasks/conductor/sonic/sync.py:68). From reading the code (not run), the command finds no MetalBox IP, so without the new key it validates a config with next hop None and no NTP or DNS server. This is an existing bug in another file.
  • README.md:21-22 (line numbers with this change) gives pipenv install --dev and pipenv run pytest for the full unit suite. Pipfile.lock lacks six packages from requirements.txt: boto3, fastapi, python-openstackclient, tabulate, uvicorn and websockets. CI gets them with pip install .. This is test setup, not part of the issue.
  • The documentation list in README.md does not include the existing page docs/collection-plans.md. The issue asks for one new entry only.

🤖 Generated with Claude Code

The generator wrote the MetalBox IP as next hop of the default route
in the mgmt VRF. STATIC_ROUTE is rebuilt on every regen, so a
deployment whose management network uses another gateway could not
correct the route anywhere.

The next hop now comes from the config context key
_segment_mgmt_gateway_ipv4 when a device has it, in the same way as
the _segment_* keys for syslog and SNMP. NetBox merges local context
data over the assigned config contexts, so the key works for a whole
segment and for a single switch. NTP and DNS stay on the MetalBox IP,
and a device without the key gets the same config as before.

A value with a prefix length is accepted, because NetBox shows
addresses that way. Anything else that is not an IPv4 address is
ignored with a warning and the MetalBox IP is used. Raising would make
the sync skip the device, so one bad segment context would block all
changes for every switch it covers. Only strings are parsed, since
ipaddress reads the integer 42 as 0.0.0.42. An address outside the OOB
network is used as given, with a warning.

Tests: the helper with usable, unset and unusable values, and with an
address outside an IPv4 and an IPv6 OOB network. In the orchestrator,
the override with and without a MetalBox, the fallback for an invalid
value, the unchanged None next hop without either address, and a
device without an OOB IP.

Part of #2396.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
The new page describes the default next hop of the mgmt default
route, where _segment_mgmt_gateway_ipv4 can be set in NetBox, which
values it accepts, when the MetalBox IP is used instead, and that NTP,
DNS and the control-plane ACLs do not change. The README links it.

Part of #2396.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Allow to override the gateway in the mgmt network for Sonic devices

1 participant