diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-03-17 19:12:04 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-07-25 21:10:25 +0200 |
commit | fb94d0b6091e09099c972355886918ef63ee9d97 (patch) | |
tree | 3f9d9c09f12d328bac4e79fab697dd19a294f055 /smoketest/scripts/cli/test_protocols_static.py | |
parent | c114e1904571ff3c323a9068d8b3784d9a238d0a (diff) | |
download | vyos-1x-fb94d0b6091e09099c972355886918ef63ee9d97.tar.gz vyos-1x-fb94d0b6091e09099c972355886918ef63ee9d97.zip |
smoketest: add shim for every test to re-use common tasts
Currently every smoketest does the setup and destruction of the configsession
on its own durin setUp(). This creates a lot of overhead and one configsession
should be re-used during execution of every smoketest script.
In addiion a test that failed will leaf the system in an unconsistent state.
For this reason before the test is executed we will save the running config
to /tmp and the will re-load the config after the test has passed, always
ensuring a clean environment for the next test.
(cherry picked from commit 0f3def974fbaa4a26e6ad590ee37dd965bc2358f)
Diffstat (limited to 'smoketest/scripts/cli/test_protocols_static.py')
-rwxr-xr-x | smoketest/scripts/cli/test_protocols_static.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/smoketest/scripts/cli/test_protocols_static.py b/smoketest/scripts/cli/test_protocols_static.py index 100fd3387..de9b48de4 100755 --- a/smoketest/scripts/cli/test_protocols_static.py +++ b/smoketest/scripts/cli/test_protocols_static.py @@ -19,6 +19,8 @@ import os import json import unittest +from base_vyostest_shim import VyOSUnitTestSHIM + from netifaces import interfaces from vyos.configsession import ConfigSession @@ -71,29 +73,27 @@ interface_routes = { }, } - -class StaticRouteTest(unittest.TestCase): +class StaticRouteTest(VyOSUnitTestSHIM.TestCase): def setUp(self): - self.session = ConfigSession(os.getpid()) # we need an alive next-hop interface - self.session.set(['interfaces', 'dummy', dummy_if, 'address', '192.0.2.1/24']) - self.session.set(['interfaces', 'dummy', dummy_if, 'address', '2001:db8::1/64']) + self.cli_set(['interfaces', 'dummy', dummy_if, 'address', '192.0.2.1/24']) + self.cli_set(['interfaces', 'dummy', dummy_if, 'address', '2001:db8::1/64']) def tearDown(self): - self.session.delete(['interfaces', 'dummy', dummy_if]) - self.session.commit() + self.cli_delete(['interfaces', 'dummy', dummy_if]) + self.cli_commit() def test_static_routes(self): for route, route_config in routes.items(): route_type = 'route' if is_ipv6(route): route_type = 'route6' - self.session.set(base_path + [route_type, route, 'next-hop', route_config['next_hop']]) + self.cli_set(base_path + [route_type, route, 'next-hop', route_config['next_hop']]) if 'distance' in route_config: - self.session.set(base_path + [route_type, route, 'next-hop', route_config['next_hop'], 'distance', route_config['distance']]) + self.cli_set(base_path + [route_type, route, 'next-hop', route_config['next_hop'], 'distance', route_config['distance']]) # commit changes - self.session.commit() + self.cli_commit() # Verify routes for route, route_config in routes.items(): @@ -114,19 +114,19 @@ class StaticRouteTest(unittest.TestCase): route_type = 'route' if is_ipv6(route): route_type = 'route6' - self.session.delete(base_path + [route_type, route]) + self.cli_delete(base_path + [route_type, route]) def test_interface_routes(self): for route, route_config in interface_routes.items(): route_type = 'interface-route' if is_ipv6(route): route_type = 'interface-route6' - self.session.set(base_path + [route_type, route, 'next-hop-interface', route_config['next_hop']]) + self.cli_set(base_path + [route_type, route, 'next-hop-interface', route_config['next_hop']]) if 'distance' in route_config: - self.session.set(base_path + [route_type, route, 'next-hop-interface', route_config['next_hop'], 'distance', route_config['distance']]) + self.cli_set(base_path + [route_type, route, 'next-hop-interface', route_config['next_hop'], 'distance', route_config['distance']]) # commit changes - self.session.commit() + self.cli_commit() # Verify routes for route, route_config in interface_routes.items(): @@ -148,7 +148,7 @@ class StaticRouteTest(unittest.TestCase): route_type = 'interface-route' if is_ipv6(route): route_type = 'interface-route6' - self.session.delete(base_path + [route_type, route]) + self.cli_delete(base_path + [route_type, route]) if __name__ == '__main__': - unittest.main(verbosity=2, failfast=True) + unittest.main(verbosity=2) |