summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2025-10-22 15:39:18 +0300
committerGitHub <noreply@github.com>2025-10-22 15:39:18 +0300
commitc284938df61b5e970dd13cde03e0693254e89211 (patch)
tree8339e1bbe531ac5caffb80938b48fdce4743cbba /smoketest/scripts/cli
parentd272b2509836403682c6c8ab4096ccf4be003bcb (diff)
parentc4632bb6ad6c055fb7fe5a5c055354c6895ba8e5 (diff)
downloadvyos-1x-c284938df61b5e970dd13cde03e0693254e89211.tar.gz
vyos-1x-c284938df61b5e970dd13cde03e0693254e89211.zip
Merge pull request #4622 from MattKobayashi/T3680
T3680: protocols: add dhclient hooks for dhcp-interface static routes
Diffstat (limited to 'smoketest/scripts/cli')
-rwxr-xr-xsmoketest/scripts/cli/test_protocols_static.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_protocols_static.py b/smoketest/scripts/cli/test_protocols_static.py
index 03115b7b8..77a45e333 100755
--- a/smoketest/scripts/cli/test_protocols_static.py
+++ b/smoketest/scripts/cli/test_protocols_static.py
@@ -651,5 +651,112 @@ class TestProtocolsStatic(VyOSUnitTestSHIM.TestCase):
while process_named_running('dhclient', cmdline=interface, timeout=10):
sleep(0.250)
+ def test_07_dhcp_interface_static_routes(self):
+ # Test static routes using dhcp-interface option
+ # When running via vyos-build under the QEMU environment a local DHCP
+ # server is available. This test verifies that static routes with
+ # dhcp-interface are configured correctly.
+ if not os.path.exists('/tmp/vyos.smoketests.hint'):
+ self.skipTest('Not running under VyOS CI/CD QEMU environment!')
+
+ dhcp_interface = 'eth0'
+ interface_path = ['interfaces', 'ethernet', dhcp_interface]
+
+ # Configure DHCP on the interface
+ self.cli_set(interface_path + ['address', 'dhcp'])
+
+ # Commit configuration
+ self.cli_commit()
+
+ # Wait for dhclient to receive IP address
+ sleep(5)
+
+ # Configure static routes with dhcp-interface
+ dhcp_routes = {
+ '10.10.0.0/16': {
+ 'dhcp_interface': [dhcp_interface],
+ },
+ '192.168.100.0/24': {
+ 'dhcp_interface': [dhcp_interface],
+ },
+ }
+
+ # Configure the static routes
+ for route, route_config in dhcp_routes.items():
+ base = base_path + ['route', route]
+ if 'dhcp_interface' in route_config:
+ for dhcp_if in route_config['dhcp_interface']:
+ self.cli_set(base + ['dhcp-interface', dhcp_if])
+
+ # Commit configuration
+ self.cli_commit()
+
+ # Verify that the DHCP hook interface list file is created
+ dhcp_hook_iflist = '/tmp/static_dhcp_interfaces'
+ self.assertTrue(
+ os.path.exists(dhcp_hook_iflist),
+ 'DHCP hook interface list file should be created',
+ )
+
+ # Read the interface list file and verify it contains our interface
+ with open(dhcp_hook_iflist, 'r') as f:
+ interface_list = f.read().strip()
+ self.assertIn(
+ dhcp_interface,
+ interface_list,
+ f'Interface {dhcp_interface} should be in hook interface list',
+ )
+
+ # Get the DHCP router for verification
+ router = get_dhcp_router(dhcp_interface)
+ self.assertIsNotNone(router, 'DHCP router should be available')
+
+ # Verify FRR configuration contains the static routes with DHCP router
+ frrconfig = self.getFRRconfig('ip route')
+
+ for route in dhcp_routes.keys():
+ expected_route = f'ip route {route} {router} {dhcp_interface}'
+ self.assertIn(
+ expected_route,
+ frrconfig,
+ f'Static route {route} with dhcp-interface should be in FRR config',
+ )
+
+ # Test table-based routes with dhcp-interface
+ table_id = '100'
+ table_route = '10.20.0.0/16'
+ table_base = base_path + ['table', table_id, 'route', table_route]
+ self.cli_set(table_base + ['dhcp-interface', dhcp_interface])
+ self.cli_commit()
+
+ # Verify table route in FRR config
+ frrconfig = self.getFRRconfig('ip route')
+ expected_table_route = (
+ f'ip route {table_route} {router} {dhcp_interface} table {table_id}'
+ )
+ self.assertIn(
+ expected_table_route,
+ frrconfig,
+ f'Table static route {table_route} with dhcp-interface should be in FRR config',
+ )
+
+ # Clean up - remove DHCP configuration
+ self.cli_delete(interface_path + ['address'])
+ self.cli_commit()
+
+ # Wait for dhclient to stop
+ while process_named_running('dhclient', cmdline=dhcp_interface, timeout=10):
+ sleep(0.250)
+
+ # Verify that the hook interface list file is cleaned up when no dhcp-interface routes exist
+ self.cli_delete(base_path)
+ self.cli_commit()
+
+ # The interface list file should be removed when no dhcp-interface routes are configured
+ self.assertFalse(
+ os.path.exists(dhcp_hook_iflist),
+ 'DHCP hook interface list file should be removed when no dhcp-interface routes exist',
+ )
+
if __name__ == '__main__':
unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())