summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_protocols_rpki.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_rpki.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_rpki.py')
-rwxr-xr-xsmoketest/scripts/cli/test_protocols_rpki.py51
1 files changed, 23 insertions, 28 deletions
diff --git a/smoketest/scripts/cli/test_protocols_rpki.py b/smoketest/scripts/cli/test_protocols_rpki.py
index bec4ef76f..8212e9469 100755
--- a/smoketest/scripts/cli/test_protocols_rpki.py
+++ b/smoketest/scripts/cli/test_protocols_rpki.py
@@ -17,6 +17,8 @@
import os
import unittest
+from base_vyostest_shim import VyOSUnitTestSHIM
+
from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
from vyos.util import cmd
@@ -29,22 +31,15 @@ rpki_known_hosts = '/config/auth/known_hosts'
rpki_ssh_key = '/config/auth/id_rsa_rpki'
rpki_ssh_pub = f'{rpki_ssh_key}.pub'
-def getFRRRPKIconfig():
- return cmd(f'vtysh -c "show run" | sed -n "/rpki/,/^!/p"')
-
-class TestProtocolsRPKI(unittest.TestCase):
- def setUp(self):
- self.session = ConfigSession(os.getpid())
-
+class TestProtocolsRPKI(VyOSUnitTestSHIM.TestCase):
def tearDown(self):
- self.session.delete(base_path)
- self.session.commit()
- del self.session
+ self.cli_delete(base_path)
+ self.cli_commit()
# Nothing RPKI specific should be left over in the config
#
# Disabled until T3266 is resolved
- # frrconfig = getFRRRPKIconfig()
+ # frrconfig = self.getFRRconfig('rpki')
# self.assertNotIn('rpki', frrconfig)
# Check for running process
@@ -71,16 +66,16 @@ class TestProtocolsRPKI(unittest.TestCase):
},
}
- self.session.set(base_path + ['polling-period', polling])
+ self.cli_set(base_path + ['polling-period', polling])
for peer, peer_config in cache.items():
- self.session.set(base_path + ['cache', peer, 'port', peer_config['port']])
- self.session.set(base_path + ['cache', peer, 'preference', peer_config['preference']])
+ self.cli_set(base_path + ['cache', peer, 'port', peer_config['port']])
+ self.cli_set(base_path + ['cache', peer, 'preference', peer_config['preference']])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify FRR configuration
- frrconfig = getFRRRPKIconfig()
+ frrconfig = self.getFRRconfig('rpki')
self.assertIn(f'rpki polling_period {polling}', frrconfig)
for peer, peer_config in cache.items():
@@ -103,21 +98,21 @@ class TestProtocolsRPKI(unittest.TestCase):
},
}
- self.session.set(base_path + ['polling-period', polling])
+ self.cli_set(base_path + ['polling-period', polling])
for peer, peer_config in cache.items():
- self.session.set(base_path + ['cache', peer, 'port', peer_config['port']])
- self.session.set(base_path + ['cache', peer, 'preference', peer_config['preference']])
- self.session.set(base_path + ['cache', peer, 'ssh', 'username', peer_config['username']])
- self.session.set(base_path + ['cache', peer, 'ssh', 'public-key-file', rpki_ssh_pub])
- self.session.set(base_path + ['cache', peer, 'ssh', 'private-key-file', rpki_ssh_key])
- self.session.set(base_path + ['cache', peer, 'ssh', 'known-hosts-file', rpki_known_hosts])
+ self.cli_set(base_path + ['cache', peer, 'port', peer_config['port']])
+ self.cli_set(base_path + ['cache', peer, 'preference', peer_config['preference']])
+ self.cli_set(base_path + ['cache', peer, 'ssh', 'username', peer_config['username']])
+ self.cli_set(base_path + ['cache', peer, 'ssh', 'public-key-file', rpki_ssh_pub])
+ self.cli_set(base_path + ['cache', peer, 'ssh', 'private-key-file', rpki_ssh_key])
+ self.cli_set(base_path + ['cache', peer, 'ssh', 'known-hosts-file', rpki_known_hosts])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Verify FRR configuration
- frrconfig = getFRRRPKIconfig()
+ frrconfig = self.getFRRconfig('rpki')
self.assertIn(f'rpki polling_period {polling}', frrconfig)
for peer, peer_config in cache.items():
@@ -140,12 +135,12 @@ class TestProtocolsRPKI(unittest.TestCase):
}
for peer, peer_config in cache.items():
- self.session.set(base_path + ['cache', peer, 'port', peer_config['port']])
- self.session.set(base_path + ['cache', peer, 'preference', peer_config['preference']])
+ self.cli_set(base_path + ['cache', peer, 'port', peer_config['port']])
+ self.cli_set(base_path + ['cache', peer, 'preference', peer_config['preference']])
# check validate() - preferences must be unique
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
if __name__ == '__main__':