Repository navigation
Make the BGP multipath limits of the SONiC default VRF configurable - #2947
Conversation
1323a3a to
6c31be2
Compare
| return None | ||
| if isinstance(value, int): | ||
| limit = value | ||
| elif isinstance(value, str) and re.fullmatch(r"[0-9]+", value.strip()): |
There was a problem hiding this comment.
[0-9]+ has no length bound, so int(value) raises ValueError for strings longer than 4300 digits (the integer string conversion limit in Python 3.11 and later). The exception escapes before the warning-and-fallback path runs. SONIC_BGP_MAX_PATHS is read for every device that has no NetBox override, so one bad conductor value would fail generation for all of those devices. It would not degrade with a warning, as the comment in settings.py promises.
Unrealistic input, but cheap to close:
| elif isinstance(value, str) and re.fullmatch(r"[0-9]+", value.strip()): | |
| elif isinstance(value, str) and re.fullmatch(r"0*[0-9]{1,3}", value.strip()): |
This bounds the length and still accepts zero-padded values like "0004". Could you also add "9" * 4301 to test_parse_bgp_max_paths_rejects, plus a _get_bgp_max_paths test that checks the warning and the fallback for it?
| limit = _parse_bgp_max_paths(value) | ||
| if limit is None: | ||
| logger.warning( | ||
| f"Ignoring invalid {label} value {value!r} for device {device.name}: " |
There was a problem hiding this comment.
For the SONIC_BGP_MAX_PATHS source, this fires once per field for every device, on every sync. On a 40-switch fabric that is 80 identical warnings per run. Each one says "for device leaf-N", so a single global misconfiguration (including SONIC_BGP_MAX_PATHS= set to an empty string) looks like many device-specific problems.
Could the conductor setting be validated once, e.g. with a small functools.cached helper, and warned about once without a device name? The per-device warning still makes sense for sonic_parameters and _segment_bgp_*.
| # | ||
| # _segment_bgp_max_ebgp_paths raises max_ebgp_paths of the default VRF to 4 | ||
| # for every fixture device. _segment_bgp_max_ibgp_paths is deliberately left | ||
| # unset, so max_ibgp_paths shows the built-in fallback of 2. |
There was a problem hiding this comment.
Two things here:
-
Because
max_ibgp_pathsfalls through to the conductor setting, the goldens now depend on the caller's environment.sonic_golden_test.shexports the otherSONIC_*variables but leavesSONIC_BGP_MAX_PATHSalone, sopython -m tests.e2e.generateinherits it from the caller's shell. WithSONIC_BGP_MAX_PATHS=8exported, every device without a device override gets"8". A normal run then fails with golden mismatches, and--regeneratequietly writes"8"into the committed goldens. Could you addunset SONIC_BGP_MAX_PATHS(orexport SONIC_BGP_MAX_PATHS=2) next to the otherSONIC_*exports in the runner? -
Nit: the
2here is not really the built-in fallback.settings.SONIC_BGP_MAX_PATHSdefaults to"2", so the value comes from the conductor setting.DEFAULT_BGP_MAX_PATHSis only reached when that setting is invalid.
| assert config["BGP_GLOBALS_AF"][f"default|{af_name}"] == af_attributes | ||
| assert ( | ||
| af_attributes.items() | ||
| <= config["BGP_GLOBALS_AF"][f"default|{af_name}"].items() |
There was a problem hiding this comment.
With the switch from == to a <= subset check, this test no longer catches unexpected extra keys in the default-VRF address families. For example, max_*_paths leaking into l2vpn_evpn would now pass. Could we keep exact equality instead? Compare the IPv4/IPv6 unicast entries against {**af_attributes, "max_ebgp_paths": "2", "max_ibgp_paths": "2"} and the remaining ones against af_attributes. If the subset check stays, please say in the commit message that the assertion was loosened.
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_get_bgp_max_paths_falls_back_to_builtin_default(loguru_logs): |
There was a problem hiding this comment.
The autouse fixture sets SONIC_BGP_MAX_PATHS to "2", so this test resolves from the conductor setting and never reaches DEFAULT_BGP_MAX_PATHS. The invalid-conductor tests do cover the real fallback, so nothing goes untested, but the name claims more than the test does. Either patch the setting to None here, which _get_bgp_max_paths skips, so the test really covers the no-sources case, or rename it to something like ..._uses_conductor_default.
Conductor-wide default for max_ebgp_paths and max_ibgp_paths in the IPv4 and IPv6 unicast address families of the SONiC default VRF. It is kept as a string, not wrapped in int(), so a typo cannot fail the import of osism.settings for every osism process; the SONiC config generator validates it and falls back to 2. Part of #2559. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Christian Berendt <berendt@osism.tech> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The generator pinned max_ebgp_paths and max_ibgp_paths of default|ipv4_unicast and default|ipv6_unicast to 2, so a leaf with more than two uplinks installed only two equal-cost paths. Each field now resolves on its own, first valid value wins: sonic_parameters.max_ebgp_paths / max_ibgp_paths on the device, then _segment_bgp_max_ebgp_paths / _segment_bgp_max_ibgp_paths in its config context, then SONIC_BGP_MAX_PATHS, then the built-in 2. A valid value is an int (not a bool) or a digit string from 1 to 256, the range of sonic-bgp-global.yang. An invalid value is skipped with a warning: per device for the NetBox sources, once per sync run and without a device name for SONIC_BGP_MAX_PATHS, which is the same for every device. A missing or null value is skipped silently. A device that sets nothing generates the same config as before. l2vpn_evpn and the per-VRF address families are unchanged. Part of #2559. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Christian Berendt <berendt@osism.tech> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The e2e-segment config context sets _segment_bgp_max_ebgp_paths to 4, so every fixture device shows the segment default for max_ebgp_paths and the default of SONIC_BGP_MAX_PATHS, 2, for max_ibgp_paths. e2e-leaf-2 sets max_ebgp_paths 8 and max_ibgp_paths 4 in sonic_parameters, proving the per-device override over the segment value and over the conductor setting. sonic_golden_test.sh unsets SONIC_BGP_MAX_PATHS before it generates, so a value exported in the caller's shell can neither fail the comparison nor end up in regenerated goldens. The goldens were regenerated from a fresh stack with make sonic-e2e-down and make sonic-e2e-regen; they change in the default-VRF unicast address families only (9 files, 20 lines). Part of #2559. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Christian Berendt <berendt@osism.tech> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
6c31be2 to
614cca1
Compare
Closes #2559
The SONiC config generator no longer pins
max_ebgp_pathsandmax_ibgp_pathsofdefault|ipv4_unicastanddefault|ipv6_unicastto"2". Each field resolves per device and on its own, first valid value wins:sonic_parameters.max_ebgp_paths/max_ibgp_pathsin the device's custom fields_segment_bgp_max_ebgp_paths/_segment_bgp_max_ibgp_pathsin its config contextSONIC_BGP_MAX_PATHSin the conductor environment (new, shared by both fields)DEFAULT_BGP_MAX_PATHS = 2A valid value is an
int(not abool) or a digit string from 1 to 256, the rangesonic-bgp-global.yanggives both fields. An invalid value is skipped with a warning naming its source and the device. A missing ornullone is skipped silently. A device that sets nothing generates the same config as before.default|l2vpn_evpnand the per-VRF address families are unchanged.Commits
osism/settings.py, deliberately not wrapped inint(), so a typo cannot fail the import for every osism process. Tests:test_sonic_bgp_max_paths_default,test_sonic_bgp_max_paths_override.DEFAULT_VRF_BGP_GLOBALS_AF, and adds theBGP_MAX_PATHS_*/DEFAULT_VRF_MULTIPATH_AFSconstants and_parse_bgp_max_paths/_get_bgp_max_paths._add_default_vrf_configurationmerges the resolved pair into both unicast families, still assigning per key. Tests: the newtest_config_generator_multipath.py(53 cases),test_vrf_ipv4_unicast_limits_ignore_conductor_setting, and a subset assertion intest_generate_sonic_config_default_vrf_entries_match_policy_constants.e2e-segmentsets_segment_bgp_max_ebgp_paths: 4, ande2e-leaf-2setsmax_ebgp_paths: 8/max_ibgp_paths: 4. The goldens were regenerated from a fresh stack (make sonic-e2e-down && make sonic-e2e-regen). They change in exactly the 20 lines the issue lists (9 files,max_ebgp_paths"4", and on leaf-2"8"/"4").VrfStorage|ipv4_unicastis untouched.Notes for review
test_generate_sonic_config_default_vrf_entries_match_policy_constants. It goes from equality toaf_attributes.items() <= ...items(), as the issue prescribes: the unicast constants no longer carry the two fields, so equality cannot hold.test_generate_sonic_config_emits_default_vrf_entries_without_vni_vrfsstill pins the literal"2"values and is unedited.test_get_bgp_max_paths_logs_source_at_debugis parametrized over the device and the segment source. The issue lists only the device case, but its criterion names both.test_get_bgp_max_paths_falls_back_to_builtin_defaultalso asserts that noWARNINGis logged, since the "absent inputs" criterion cites it.uvbecause the machine'spython3lacksensurepip, and the E2E runs used their own pipenv venv, so the unit-test venv stayed as CI builds it (no ansible-core).Verification
Run locally on
1323a3a0:pipenv run pytest tests/unit: 4285 passed, 3 xfailed (mainbaseline: 4229 passed, same 3 xfailed)pipenv run pytest tests/unit/tasks/conductor/sonic/test_validator_artifacts.py: 11 passed, every golden validatesgrep -c '"max_[ei]bgp_paths": "' osism/tasks/conductor/sonic/config_generator.py:2(the per-VRF literals only)git diff --stat origin/main -- tests/e2e/golden/: 9 files changed, 20 insertions(+), 20 deletions(-)make sonic-e2e, cold, against the committed goldens:>>> SONiC E2E golden test passed.black==26.10.1 --check .(252 files unchanged),flake8==7.5.0on every changed.pyfile (clean),mypy==1.20.2 --ignore-missing-imports --install-types --non-interactive .(no issues in 251 files)Not exercised here: the Zuul check jobs
flake8,python-black,mypy, andpython-osism-sonic-e2ethemselves. They run on this pull request. Locally, the seeding tool came from anetbox-managercheckout on itsbump-dependenciesbranch, while the job uses netbox-manager'smain.Noticed but not touching
osism/commands/sonic.py:1385readsdevice.custom_fields.get("sonic_parameters", {}).get("config_version"). A device whosesonic_parametersis JSONnullmakes the first.getreturnNone, and the second raisesAttributeErrorinosism sonic validategenerate mode. That is outside Make the BGP multipath limits of the SONiC default VRF configurable #2559.🤖 Generated with Claude Code