summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_service_ssh.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_service_ssh.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_service_ssh.py')
-rwxr-xr-xsmoketest/scripts/cli/test_service_ssh.py50
1 files changed, 25 insertions, 25 deletions
diff --git a/smoketest/scripts/cli/test_service_ssh.py b/smoketest/scripts/cli/test_service_ssh.py
index 68081e56f..c76f709b1 100755
--- a/smoketest/scripts/cli/test_service_ssh.py
+++ b/smoketest/scripts/cli/test_service_ssh.py
@@ -14,10 +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 re
import os
+import re
import unittest
+from base_vyostest_shim import VyOSUnitTestSHIM
+
from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
from vyos.util import cmd
@@ -38,18 +40,16 @@ def get_config_value(key):
tmp = re.findall(f'\n?{key}\s+(.*)', tmp)
return tmp
-class TestServiceSSH(unittest.TestCase):
+class TestServiceSSH(VyOSUnitTestSHIM.TestCase):
def setUp(self):
- self.session = ConfigSession(os.getpid())
# ensure we can also run this test on a live system - so lets clean
# out the current configuration :)
- self.session.delete(base_path)
+ self.cli_delete(base_path)
def tearDown(self):
# delete testing SSH config
- self.session.delete(base_path)
- self.session.commit()
- del self.session
+ self.cli_delete(base_path)
+ self.cli_commit()
self.assertTrue(os.path.isfile(key_rsa))
self.assertTrue(os.path.isfile(key_dsa))
@@ -58,10 +58,10 @@ class TestServiceSSH(unittest.TestCase):
def test_ssh_default(self):
# Check if SSH service runs with default settings - used for checking
# behavior of <defaultValue> in XML definition
- self.session.set(base_path)
+ self.cli_set(base_path)
# commit changes
- self.session.commit()
+ self.cli_commit()
# Check configured port
port = get_config_value('Port')[0]
@@ -72,15 +72,15 @@ class TestServiceSSH(unittest.TestCase):
def test_ssh_single_listen_address(self):
# Check if SSH service can be configured and runs
- self.session.set(base_path + ['port', '1234'])
- self.session.set(base_path + ['disable-host-validation'])
- self.session.set(base_path + ['disable-password-authentication'])
- self.session.set(base_path + ['loglevel', 'verbose'])
- self.session.set(base_path + ['client-keepalive-interval', '100'])
- self.session.set(base_path + ['listen-address', '127.0.0.1'])
+ self.cli_set(base_path + ['port', '1234'])
+ self.cli_set(base_path + ['disable-host-validation'])
+ self.cli_set(base_path + ['disable-password-authentication'])
+ self.cli_set(base_path + ['loglevel', 'verbose'])
+ self.cli_set(base_path + ['client-keepalive-interval', '100'])
+ self.cli_set(base_path + ['listen-address', '127.0.0.1'])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Check configured port
port = get_config_value('Port')[0]
@@ -114,14 +114,14 @@ class TestServiceSSH(unittest.TestCase):
# listen ports and listen-addresses
ports = ['22', '2222', '2223', '2224']
for port in ports:
- self.session.set(base_path + ['port', port])
+ self.cli_set(base_path + ['port', port])
addresses = ['127.0.0.1', '::1']
for address in addresses:
- self.session.set(base_path + ['listen-address', address])
+ self.cli_set(base_path + ['listen-address', address])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Check configured port
tmp = get_config_value('Port')
@@ -139,17 +139,17 @@ class TestServiceSSH(unittest.TestCase):
def test_ssh_vrf(self):
# Check if SSH service can be bound to given VRF
port = '22'
- self.session.set(base_path + ['port', port])
- self.session.set(base_path + ['vrf', vrf])
+ self.cli_set(base_path + ['port', port])
+ self.cli_set(base_path + ['vrf', vrf])
# VRF does yet not exist - an error must be thrown
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
- self.session.set(['vrf', 'name', vrf, 'table', '1338'])
+ self.cli_set(['vrf', 'name', vrf, 'table', '1338'])
# commit changes
- self.session.commit()
+ self.cli_commit()
# Check configured port
tmp = get_config_value('Port')
@@ -163,7 +163,7 @@ class TestServiceSSH(unittest.TestCase):
self.assertIn(PROCESS_NAME, tmp)
# delete VRF
- self.session.delete(['vrf', 'name', vrf])
+ self.cli_delete(['vrf', 'name', vrf])
if __name__ == '__main__':
unittest.main(verbosity=2)