Repository navigation
Allow to override the mgmt gateway of SONiC switches - #2948
Conversation
|
|
||
| gateway = str(interface.ip) | ||
| network = ipaddress.ip_network(f"{oob_ip}/{prefix_len}", strict=False) | ||
| if interface.ip not in network: |
There was a problem hiding this comment.
Some values can never work as a next hop, but they get through with either no warning or a misleading one.
These are inside the OOB network, so they're accepted with only the INFO log. For a switch at 10.42.0.5/24:
10.42.0.5, the switch's own address. This is an easy copy-paste mistake in local context data, and it costs the switch its management reachability.10.42.0.0and10.42.0.255, the network and broadcast addresses.
These are outside the OOB network, so they're still used, with the "may be unreachable" warning:
0.0.0.0127.0.0.0/8- multicast addresses
255.255.255.255
Could all of these take the same path as a non-IPv4 value: warn, then fall back to the MetalBox IP? Two cases need care:
- Reject the network and broadcast addresses only when
prefix_len < 31. In a/31they are the two usable peers. - Leave link-local addresses alone. Inside a
169.254.0.0/16OOB network they're valid gateways, and outside it the existing membership warning already covers them.
A parametrized test with each rejected case, plus a /31 peer that is still accepted, would pin this down.
There was a problem hiding this comment.
Done in 19de804. All the addresses you list now take the same path as a non-IPv4 value: one warning that names the reason, then the MetalBox IP. The check is in the new _get_impossible_next_hop_reason and runs before the OOB network check, so the "may be unreachable" warning no longer appears for them.
- The network and broadcast addresses are rejected only when the prefix length is below 31.
- Link-local addresses are left alone. Outside the OOB network they still get the existing warning.
Tests: test_get_mgmt_gateway_override_impossible_next_hop_returns_none_and_warns has each rejected case, including 10.42.0.5/24 (the own address with its prefix length) and the network and broadcast addresses of a /30. test_get_mgmt_gateway_override_slash_31_peer_is_accepted covers both peers of a /31. Two more tests cover link-local addresses inside and outside the OOB network.
|
|
||
| ## Setting another gateway | ||
|
|
||
| Set the key `_segment_mgmt_gateway_ipv4` to use another gateway. The generator |
There was a problem hiding this comment.
Could you say here that the key only takes effect when the switch has an OOB IP in NetBox? Without one, no mgmt default route is written at all, whether or not the override is set.
There was a problem hiding this comment.
Done in 29083ed. The section now says that the key only takes effect when the switch has an OOB IP in NetBox, and that without one no default route is written for the mgmt VRF, whether or not the key is set.
|
|
||
| ## Fallback | ||
|
|
||
| - If the key is not set, or its value is empty, the MetalBox IP is used. |
There was a problem hiding this comment.
Two additions, please:
- Once the rejection above is in, list the addresses that are rejected.
- Add a bullet for the case where the override is absent or rejected and no MetalBox IP is found either. The route is then written with no next hop. Without that bullet, this section reads as if the fallback always produces a working route.
There was a problem hiding this comment.
Done in 29083ed. The section now lists the rejected addresses, with the /31 exception. A new bullet says that if the key is not set, or its value is empty or rejected, and no MetalBox IP is found either, the route is written without a next hop and does not work.
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 that can never be a next hop is ignored in the same way: the OOB IP of the switch itself, the network and broadcast address of the OOB network, 0.0.0.0, loopback and multicast addresses, and 255.255.255.255. In a /31 both addresses are usable peers, so the network and broadcast check does not apply there. Link-local addresses are allowed, because they are valid gateways in a link-local OOB network. Any other address outside the OOB network is used as given, with a warning. Tests: the helper with usable, unset and unusable values, with each kind of rejected address, with both peers of a /31, with link-local addresses, 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> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new page describes the default next hop of the mgmt default route, where _segment_mgmt_gateway_ipv4 can be set in NetBox, that it only takes effect with an OOB IP, which values it accepts and rejects, when the MetalBox IP is used instead, what happens if there is none, 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> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4e9fd39 to
29083ed
Compare
A SONiC switch can now get its management gateway from NetBox. If the rendered config context of a device has a usable IPv4 address under
_segment_mgmt_gateway_ipv4, the config generator writes it as the next hop ofSTATIC_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
_get_mgmt_gateway_overrideand_get_impossible_next_hop_reason, the call ingenerate_sonic_config, and the tests.ipaddressreads the integer42as0.0.0.42.0.0.0.0,127.0.0.0/8, multicast addresses and255.255.255.255. Link-local addresses are not rejected.None, as before. A test covers this.docs/sonic-mgmt-gateway.mdand links it in the README. The page also says that the key needs an OOB IP in NetBox, which addresses are rejected, and that the route has no next hop if there is neither a usable override nor a MetalBox IP.Verification
Run locally with the tool versions pinned in the OSISM Zuul roles:
None. The new helper test file failed on import. All of them pass now./31and for link-local addresses already passed and still do.pytest tests/unit/tasks/conductor/sonic: 861 passed (820 on the base commit2174a40e).pytest: 4270 passed, 3 xfailed (4229 passed, 3 xfailed on the base commit).flake8on the changed Python files, andblack --check .andmypyon the whole repository: no findings.git diff --stat 2174a40e -- tests/e2e/ files/sonic/is empty._add_ntp_configurationand_add_dns_configurationare identical to the base commit.Not exercised locally, only OSISM's Zuul can verify these:
python-osism-sonic-e2epasses against the unchanged goldens. The check pipeline of this pull request runs it, because the change is underosism/tasks/conductor/.flake8,python-black,mypyandpython-osism-unit-testspass. The check pipeline runs them too. The local runs above are evidence, not a replacement.Deviations from the approved plan
Open questions
None declined.
Noticed, not touched
osism sonic validate --generate(osism/commands/sonic.py:1361-1387) does not load the MetalBox cache. Onlysync_sonicdoes (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 hopNoneand no NTP or DNS server. This is an existing bug in another file.README.md:21-22(line numbers with this change) givespipenv install --devandpipenv run pytestfor the full unit suite.Pipfile.locklacks six packages fromrequirements.txt: boto3, fastapi, python-openstackclient, tabulate, uvicorn and websockets. CI gets them withpip install .. This is test setup, not part of the issue.README.mddoes not include the existing pagedocs/collection-plans.md. The issue asks for one new entry only.🤖 Generated with Claude Code