diff options
Diffstat (limited to 'smoketest/scripts/cli')
| -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) |
