summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_vrf.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-17 19:12:04 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-17 19:18:17 +0100
commit0f3def974fbaa4a26e6ad590ee37dd965bc2358f (patch)
tree36cc09af1fefbc3f6a4f6ad7b946d00baaecb703 /smoketest/scripts/cli/test_vrf.py
parent42d3cfbd3ee893ec567582a04467a899191f44fd (diff)
downloadvyos-1x-0f3def974fbaa4a26e6ad590ee37dd965bc2358f.tar.gz
vyos-1x-0f3def974fbaa4a26e6ad590ee37dd965bc2358f.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.
Diffstat (limited to 'smoketest/scripts/cli/test_vrf.py')
-rwxr-xr-xsmoketest/scripts/cli/test_vrf.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/smoketest/scripts/cli/test_vrf.py b/smoketest/scripts/cli/test_vrf.py
index aac115663..591630c46 100755
--- a/smoketest/scripts/cli/test_vrf.py
+++ b/smoketest/scripts/cli/test_vrf.py
@@ -20,6 +20,7 @@ import json
import unittest
from netifaces import interfaces
+from base_vyostest_shim import VyOSUnitTestSHIM
from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
@@ -33,7 +34,7 @@ from vyos.validate import is_intf_addr_assigned
base_path = ['vrf']
vrfs = ['red', 'green', 'blue', 'foo-bar', 'baz_foo']
-class VRFTest(unittest.TestCase):
+class VRFTest(VyOSUnitTestSHIM.TestCase):
_interfaces = []
@classmethod
@@ -47,14 +48,13 @@ class VRFTest(unittest.TestCase):
for tmp in Section.interfaces('ethernet'):
if not '.' in tmp:
cls._interfaces.append(tmp)
-
- def setUp(self):
- self.session = ConfigSession(os.getpid())
+ # call base-classes classmethod
+ super(cls, cls).setUpClass()
def tearDown(self):
# delete all VRFs
- self.session.delete(base_path)
- self.session.commit()
+ self.cli_delete(base_path)
+ self.cli_commit()
for vrf in vrfs:
self.assertNotIn(vrf, interfaces())
@@ -63,20 +63,20 @@ class VRFTest(unittest.TestCase):
for vrf in vrfs:
base = base_path + ['name', vrf]
description = f'VyOS-VRF-{vrf}'
- self.session.set(base + ['description', description])
+ self.cli_set(base + ['description', description])
# check validate() - a table ID is mandatory
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
- self.session.set(base + ['table', table])
+ self.cli_set(base + ['table', table])
if vrf == 'green':
- self.session.set(base + ['disable'])
+ self.cli_set(base + ['disable'])
table = str(int(table) + 1)
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify VRF configuration
table = '1000'
@@ -107,11 +107,11 @@ class VRFTest(unittest.TestCase):
table = '2000'
for vrf in vrfs:
base = base_path + ['name', vrf]
- self.session.set(base + ['table', str(table)])
+ self.cli_set(base + ['table', str(table)])
table = str(int(table) + 1)
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify VRF configuration
for vrf in vrfs:
@@ -125,31 +125,31 @@ class VRFTest(unittest.TestCase):
table = '1000'
vrf = vrfs[0]
base = base_path + ['name', vrf]
- self.session.set(base + ['table', table])
+ self.cli_set(base + ['table', table])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Check if VRF has been created
self.assertTrue(vrf in interfaces())
table = str(int(table) + 1)
- self.session.set(base + ['table', table])
+ self.cli_set(base + ['table', table])
# check validate() - table ID can not be altered!
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
def test_vrf_assign_interface(self):
vrf = vrfs[0]
table = '5000'
- self.session.set(['vrf', 'name', vrf, 'table', table])
+ self.cli_set(['vrf', 'name', vrf, 'table', table])
for interface in self._interfaces:
section = Section.section(interface)
- self.session.set(['interfaces', section, interface, 'vrf', vrf])
+ self.cli_set(['interfaces', section, interface, 'vrf', vrf])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify & cleanup
for interface in self._interfaces:
@@ -158,7 +158,7 @@ class VRFTest(unittest.TestCase):
self.assertEqual(tmp, vrf)
# cleanup
section = Section.section(interface)
- self.session.delete(['interfaces', section, interface, 'vrf'])
+ self.cli_delete(['interfaces', section, interface, 'vrf'])
if __name__ == '__main__':
unittest.main(verbosity=2)