diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-09-26 01:42:14 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-25 16:42:14 +0100 |
| commit | 9fe93349225eb9b014e7a3e397da88fece40a0b2 (patch) | |
| tree | 8869b2586ad5227b164b94be015efe15fc489ed1 /tests/unit/modules | |
| parent | 8fcff7e2591690d14ae82bcfb430ee3755aec73c (diff) | |
| download | rest.vyos-9fe93349225eb9b014e7a3e397da88fece40a0b2.tar.gz rest.vyos-9fe93349225eb9b014e7a3e397da88fece40a0b2.zip | |
T8989: vyos_static_routes dict_op refactor (#25)
* T8989: vyos_static_routes dict_op refactor
* T8989: Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'tests/unit/modules')
| -rw-r--r-- | tests/unit/modules/test_vyos_static_routes.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unit/modules/test_vyos_static_routes.py b/tests/unit/modules/test_vyos_static_routes.py index 1a50da9..0ec74a5 100644 --- a/tests/unit/modules/test_vyos_static_routes.py +++ b/tests/unit/modules/test_vyos_static_routes.py @@ -259,6 +259,56 @@ class TestBuildCommands(VyOSModuleTestCase): expected = ("delete", _BASE + ["route", "192.0.2.0/24", "next-hop", "10.0.0.1", "distance"]) self.assertIn(expected, cmds) + def test_merged_explicit_enabled_true_clears_stale_disable(self): + """Confirmed real gap from review: dict_op(op="set") only ever + walks want's own keys, so it can never reach a "disable" leaf + that's simply absent from want -- under "merged" (which never + runs a purge pass at all) there was no way to clear a + previously disabled next-hop. Fixed via an explicit check + against the original argspec-shape config for enabled: true, + scoped to merged specifically since replaced/overridden + already handle this correctly through their existing purge + pass.""" + raw_have = {"route": {"192.0.2.0/24": {"next-hop": {"10.0.0.1": {"disable": {}}}}}} + config = [ + { + "afi": "ipv4", + "routes": [ + { + "dest": "192.0.2.0/24", + "next_hops": [ + {"forward_router_address": "10.0.0.1", "enabled": True}, + ], + }, + ], + }, + ] + cmds = build_commands(config, raw_have, "merged") + expected = ("delete", _BASE + ["route", "192.0.2.0/24", "next-hop", "10.0.0.1", "disable"]) + self.assertIn(expected, cmds) + + def test_merged_omitted_enabled_leaves_existing_disable_alone(self): + """enabled deliberately has no default (fixed alongside the + above): omitting it entirely means "no opinion", so an + unrelated merged update must not silently re-enable an + existing disabled next-hop.""" + raw_have = {"route": {"192.0.2.0/24": {"next-hop": {"10.0.0.1": {"disable": {}}}}}} + config = [ + { + "afi": "ipv4", + "routes": [ + { + "dest": "192.0.2.0/24", + "next_hops": [ + {"forward_router_address": "10.0.0.1", "admin_distance": 5}, + ], + }, + ], + }, + ] + cmds = build_commands(config, raw_have, "merged") + self.assertFalse(any("disable" in str(c) for c in cmds)) + def test_replaced_scoped_to_named_route_only(self): raw_have = { "route": { |
