summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_protocols_ripng.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-17 19:12:04 +0100
committerChristian Poessinger <christian@poessinger.com>2021-07-25 21:10:25 +0200
commitfb94d0b6091e09099c972355886918ef63ee9d97 (patch)
tree3f9d9c09f12d328bac4e79fab697dd19a294f055 /smoketest/scripts/cli/test_protocols_ripng.py
parentc114e1904571ff3c323a9068d8b3784d9a238d0a (diff)
downloadvyos-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_ripng.py')
-rwxr-xr-xsmoketest/scripts/cli/test_protocols_ripng.py89
1 files changed, 41 insertions, 48 deletions
diff --git a/smoketest/scripts/cli/test_protocols_ripng.py b/smoketest/scripts/cli/test_protocols_ripng.py
index 90cbaccd8..3380dc78b 100755
--- a/smoketest/scripts/cli/test_protocols_ripng.py
+++ b/smoketest/scripts/cli/test_protocols_ripng.py
@@ -14,12 +14,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import os
import unittest
+from base_vyostest_shim import VyOSUnitTestSHIM
+
from vyos.configsession import ConfigSession
from vyos.ifconfig import Section
-from vyos.util import cmd
from vyos.util import process_named_running
PROCESS_NAME = 'ripngd'
@@ -31,33 +31,26 @@ route_map = 'FooBar123'
base_path = ['protocols', 'ripng']
-def getFRRconfig():
- return cmd('vtysh -c "show run" | sed -n "/router ripng/,/^!/p"')
-
-class TestProtocolsRIPng(unittest.TestCase):
+class TestProtocolsRIPng(VyOSUnitTestSHIM.TestCase):
def setUp(self):
- self.session = ConfigSession(os.getpid())
-
- self.session.set(['policy', 'access-list6', acl_in, 'rule', '10', 'action', 'permit'])
- self.session.set(['policy', 'access-list6', acl_in, 'rule', '10', 'source', 'any'])
- self.session.set(['policy', 'access-list6', acl_out, 'rule', '20', 'action', 'deny'])
- self.session.set(['policy', 'access-list6', acl_out, 'rule', '20', 'source', 'any'])
- self.session.set(['policy', 'prefix-list6', prefix_list_in, 'rule', '100', 'action', 'permit'])
- self.session.set(['policy', 'prefix-list6', prefix_list_in, 'rule', '100', 'prefix', '2001:db8::/32'])
- self.session.set(['policy', 'prefix-list6', prefix_list_out, 'rule', '200', 'action', 'deny'])
- self.session.set(['policy', 'prefix-list6', prefix_list_out, 'rule', '200', 'prefix', '2001:db8::/32'])
- self.session.set(['policy', 'route-map', route_map, 'rule', '10', 'action', 'permit'])
+ self.cli_set(['policy', 'access-list6', acl_in, 'rule', '10', 'action', 'permit'])
+ self.cli_set(['policy', 'access-list6', acl_in, 'rule', '10', 'source', 'any'])
+ self.cli_set(['policy', 'access-list6', acl_out, 'rule', '20', 'action', 'deny'])
+ self.cli_set(['policy', 'access-list6', acl_out, 'rule', '20', 'source', 'any'])
+ self.cli_set(['policy', 'prefix-list6', prefix_list_in, 'rule', '100', 'action', 'permit'])
+ self.cli_set(['policy', 'prefix-list6', prefix_list_in, 'rule', '100', 'prefix', '2001:db8::/32'])
+ self.cli_set(['policy', 'prefix-list6', prefix_list_out, 'rule', '200', 'action', 'deny'])
+ self.cli_set(['policy', 'prefix-list6', prefix_list_out, 'rule', '200', 'prefix', '2001:db8::/32'])
+ self.cli_set(['policy', 'route-map', route_map, 'rule', '10', 'action', 'permit'])
def tearDown(self):
- self.session.delete(base_path)
- self.session.delete(['policy', 'access-list6', acl_in])
- self.session.delete(['policy', 'access-list6', acl_out])
- self.session.delete(['policy', 'prefix-list6', prefix_list_in])
- self.session.delete(['policy', 'prefix-list6', prefix_list_out])
- self.session.delete(['policy', 'route-map', route_map])
-
- self.session.commit()
- del self.session
+ self.cli_delete(base_path)
+ self.cli_delete(['policy', 'access-list6', acl_in])
+ self.cli_delete(['policy', 'access-list6', acl_out])
+ self.cli_delete(['policy', 'prefix-list6', prefix_list_in])
+ self.cli_delete(['policy', 'prefix-list6', prefix_list_out])
+ self.cli_delete(['policy', 'route-map', route_map])
+ self.cli_commit()
# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))
@@ -72,38 +65,38 @@ class TestProtocolsRIPng(unittest.TestCase):
timer_timeout = '1000'
timer_update = '90'
- self.session.set(base_path + ['default-information', 'originate'])
- self.session.set(base_path + ['default-metric', metric])
- self.session.set(base_path + ['distribute-list', 'access-list', 'in', acl_in])
- self.session.set(base_path + ['distribute-list', 'access-list', 'out', acl_out])
- self.session.set(base_path + ['distribute-list', 'prefix-list', 'in', prefix_list_in])
- self.session.set(base_path + ['distribute-list', 'prefix-list', 'out', prefix_list_out])
- self.session.set(base_path + ['passive-interface', 'default'])
- self.session.set(base_path + ['timers', 'garbage-collection', timer_garbage])
- self.session.set(base_path + ['timers', 'timeout', timer_timeout])
- self.session.set(base_path + ['timers', 'update', timer_update])
+ self.cli_set(base_path + ['default-information', 'originate'])
+ self.cli_set(base_path + ['default-metric', metric])
+ self.cli_set(base_path + ['distribute-list', 'access-list', 'in', acl_in])
+ self.cli_set(base_path + ['distribute-list', 'access-list', 'out', acl_out])
+ self.cli_set(base_path + ['distribute-list', 'prefix-list', 'in', prefix_list_in])
+ self.cli_set(base_path + ['distribute-list', 'prefix-list', 'out', prefix_list_out])
+ self.cli_set(base_path + ['passive-interface', 'default'])
+ self.cli_set(base_path + ['timers', 'garbage-collection', timer_garbage])
+ self.cli_set(base_path + ['timers', 'timeout', timer_timeout])
+ self.cli_set(base_path + ['timers', 'update', timer_update])
for aggregate in aggregates:
- self.session.set(base_path + ['aggregate-address', aggregate])
+ self.cli_set(base_path + ['aggregate-address', aggregate])
for interface in interfaces:
- self.session.set(base_path + ['interface', interface])
- self.session.set(base_path + ['distribute-list', 'interface', interface, 'access-list', 'in', acl_in])
- self.session.set(base_path + ['distribute-list', 'interface', interface, 'access-list', 'out', acl_out])
- self.session.set(base_path + ['distribute-list', 'interface', interface, 'prefix-list', 'in', prefix_list_in])
- self.session.set(base_path + ['distribute-list', 'interface', interface, 'prefix-list', 'out', prefix_list_out])
+ self.cli_set(base_path + ['interface', interface])
+ self.cli_set(base_path + ['distribute-list', 'interface', interface, 'access-list', 'in', acl_in])
+ self.cli_set(base_path + ['distribute-list', 'interface', interface, 'access-list', 'out', acl_out])
+ self.cli_set(base_path + ['distribute-list', 'interface', interface, 'prefix-list', 'in', prefix_list_in])
+ self.cli_set(base_path + ['distribute-list', 'interface', interface, 'prefix-list', 'out', prefix_list_out])
for network in networks:
- self.session.set(base_path + ['network', network])
- self.session.set(base_path + ['route', network])
+ self.cli_set(base_path + ['network', network])
+ self.cli_set(base_path + ['route', network])
for proto in redistribute:
- self.session.set(base_path + ['redistribute', proto, 'metric', metric])
- self.session.set(base_path + ['redistribute', proto, 'route-map', route_map])
+ self.cli_set(base_path + ['redistribute', proto, 'metric', metric])
+ self.cli_set(base_path + ['redistribute', proto, 'route-map', route_map])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify FRR ospfd configuration
- frrconfig = getFRRconfig()
+ frrconfig = self.getFRRconfig('router ripng')
self.assertIn(f'router ripng', frrconfig)
self.assertIn(f' default-information originate', frrconfig)
self.assertIn(f' default-metric {metric}', frrconfig)