diff options
| author | Daniil Baturin <daniil@vyos.io> | 2026-04-09 15:23:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-09 15:23:54 +0100 |
| commit | 79f9bb8b6f73c2674891b1d4a768a7b0c4cd0f1e (patch) | |
| tree | 1e757b049a35c6cedaccb9c9ce5e4fbb2a8bb054 | |
| parent | 570b79e1899f69a320f4aff61402ca4fbb8bab81 (diff) | |
| parent | 3a21052c3167777354a6e4f4bb4a225b1294b3e7 (diff) | |
| download | vyos-1x-79f9bb8b6f73c2674891b1d4a768a7b0c4cd0f1e.tar.gz vyos-1x-79f9bb8b6f73c2674891b1d4a768a7b0c4cd0f1e.zip | |
Merge pull request #5116 from hedrok/T8465-fix_test_protocols_static_vrf
T8465: Fix test_06_dhcp_default_route_for_vrf
| -rw-r--r-- | smoketest/scripts/cli/base_vyostest_shim.py | 26 | ||||
| -rwxr-xr-x | smoketest/scripts/cli/test_protocols_static.py | 25 |
2 files changed, 46 insertions, 5 deletions
diff --git a/smoketest/scripts/cli/base_vyostest_shim.py b/smoketest/scripts/cli/base_vyostest_shim.py index ab0a95caf..502be2813 100644 --- a/smoketest/scripts/cli/base_vyostest_shim.py +++ b/smoketest/scripts/cli/base_vyostest_shim.py @@ -18,6 +18,7 @@ import pprint import re import unittest +from math import ceil from time import sleep from typing import Type @@ -415,6 +416,31 @@ class VyOSUnitTestSHIM: break self.assertTrue(not matched if inverse else matched, msg=search) + @staticmethod + def wait_for_result(runnable, check, pause=1, timeout=10): + """ + Run `runnable` each `pause` seconds till `timeout` seconds is over. + Each time compare return value with `check` if it is not callable, if + it is callable check if `check(result)` is True. + + @returns tuple (check_result, last_return_value). check_result is True + if (last_return_value == check) for non-callable check or if (check(last_return_value)) + is true. + """ + tries = ceil(timeout / pause) + result = None + for i in range(tries): + result = runnable() + if callable(check): + if check(result): + return True, result + elif result == check: + return True, result + + sleep(pause) + + return False, result + # standard construction; typing suggestion: https://stackoverflow.com/a/70292317 def ignore_warning(warning: Type[Warning]): import warnings diff --git a/smoketest/scripts/cli/test_protocols_static.py b/smoketest/scripts/cli/test_protocols_static.py index a049020a4..892a46d7b 100755 --- a/smoketest/scripts/cli/test_protocols_static.py +++ b/smoketest/scripts/cli/test_protocols_static.py @@ -648,17 +648,32 @@ class TestProtocolsStatic(VyOSUnitTestSHIM.TestCase): self.cli_set(interface_path + ['vrf', vrf]) self.cli_commit() - # Wait for dhclient to receive IP address and default gateway - sleep(5) - router = get_dhcp_router(interface) - frrconfig = self.getFRRconfig(f'vrf {vrf}', stop_section='^exit-vrf') - self.assertIn(rf'ip route 0.0.0.0/0 {router} {interface} tag 210 {default_distance}', frrconfig) + route_str = ( + rf'ip route 0.0.0.0/0 {router} {interface} tag 210 {default_distance}' + ) + + def check_default_route(): + frrconfig = self.getFRRconfig(f'vrf {vrf}', stop_section='^exit-vrf') + if route_str in frrconfig: + return True + return frrconfig + + result, config = self.wait_for_result( + check_default_route, True, pause=1, timeout=10 + ) + # First clean interfaces from VRF so that VRF can be deleted self.cli_delete(interface_path + ['address']) self.cli_delete(interface_path + ['vrf']) self.cli_commit() + # now we can assert + self.assertTrue( + result, + f"Expected '{route_str}' in FRR config, vrf section of FRR config:\n {config}", + ) + # Wait for dhclient to stop while process_named_running('dhclient', cmdline=interface, timeout=10): sleep(0.250) |
