summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_system_login.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_system_login.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_system_login.py')
-rwxr-xr-xsmoketest/scripts/cli/test_system_login.py61
1 files changed, 29 insertions, 32 deletions
diff --git a/smoketest/scripts/cli/test_system_login.py b/smoketest/scripts/cli/test_system_login.py
index dfa56e971..8327235fb 100755
--- a/smoketest/scripts/cli/test_system_login.py
+++ b/smoketest/scripts/cli/test_system_login.py
@@ -14,11 +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 re
import platform
import unittest
+from base_vyostest_shim import VyOSUnitTestSHIM
+
from distutils.version import LooseVersion
from platform import release as kernel_version
from subprocess import Popen, PIPE
@@ -32,42 +33,38 @@ from vyos.template import inc_ip
base_path = ['system', 'login']
users = ['vyos1', 'vyos2']
-class TestSystemLogin(unittest.TestCase):
- def setUp(self):
- self.session = ConfigSession(os.getpid())
-
+class TestSystemLogin(VyOSUnitTestSHIM.TestCase):
def tearDown(self):
# Delete individual users from configuration
for user in users:
- self.session.delete(base_path + ['user', user])
+ self.cli_delete(base_path + ['user', user])
- self.session.commit()
- del self.session
+ self.cli_commit()
def test_add_linux_system_user(self):
system_user = 'backup'
- self.session.set(base_path + ['user', system_user, 'authentication', 'plaintext-password', system_user])
+ self.cli_set(base_path + ['user', system_user, 'authentication', 'plaintext-password', system_user])
# check validate() - can not add username which exists on the Debian
# base system (UID < 1000)
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
- self.session.delete(base_path + ['user', system_user])
+ self.cli_delete(base_path + ['user', system_user])
def test_system_login_user(self):
# Check if user can be created and we can SSH to localhost
- self.session.set(['service', 'ssh', 'port', '22'])
+ self.cli_set(['service', 'ssh', 'port', '22'])
for user in users:
name = "VyOS Roxx " + user
home_dir = "/tmp/" + user
- self.session.set(base_path + ['user', user, 'authentication', 'plaintext-password', user])
- self.session.set(base_path + ['user', user, 'full-name', 'VyOS Roxx'])
- self.session.set(base_path + ['user', user, 'home-directory', home_dir])
+ self.cli_set(base_path + ['user', user, 'authentication', 'plaintext-password', user])
+ self.cli_set(base_path + ['user', user, 'full-name', 'VyOS Roxx'])
+ self.cli_set(base_path + ['user', user, 'home-directory', home_dir])
- self.session.commit()
+ self.cli_commit()
for user in users:
cmd = ['su','-', user]
@@ -104,18 +101,18 @@ class TestSystemLogin(unittest.TestCase):
radius_port = '2000'
radius_timeout = '1'
- self.session.set(base_path + ['radius', 'server', radius_server, 'key', radius_key])
- self.session.set(base_path + ['radius', 'server', radius_server, 'port', radius_port])
- self.session.set(base_path + ['radius', 'server', radius_server, 'timeout', radius_timeout])
- self.session.set(base_path + ['radius', 'source-address', radius_source])
- self.session.set(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'key', radius_key])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'port', radius_port])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'timeout', radius_timeout])
+ self.cli_set(base_path + ['radius', 'source-address', radius_source])
+ self.cli_set(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
# check validate() - Only one IPv4 source-address supported
with self.assertRaises(ConfigSessionError):
- self.session.commit()
- self.session.delete(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
+ self.cli_commit()
+ self.cli_delete(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
- self.session.commit()
+ self.cli_commit()
# this file must be read with higher permissions
pam_radius_auth_conf = cmd('sudo cat /etc/pam_radius_auth.conf')
@@ -158,18 +155,18 @@ class TestSystemLogin(unittest.TestCase):
radius_port = '4000'
radius_timeout = '4'
- self.session.set(base_path + ['radius', 'server', radius_server, 'key', radius_key])
- self.session.set(base_path + ['radius', 'server', radius_server, 'port', radius_port])
- self.session.set(base_path + ['radius', 'server', radius_server, 'timeout', radius_timeout])
- self.session.set(base_path + ['radius', 'source-address', radius_source])
- self.session.set(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'key', radius_key])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'port', radius_port])
+ self.cli_set(base_path + ['radius', 'server', radius_server, 'timeout', radius_timeout])
+ self.cli_set(base_path + ['radius', 'source-address', radius_source])
+ self.cli_set(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
# check validate() - Only one IPv4 source-address supported
with self.assertRaises(ConfigSessionError):
- self.session.commit()
- self.session.delete(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
+ self.cli_commit()
+ self.cli_delete(base_path + ['radius', 'source-address', inc_ip(radius_source, 1)])
- self.session.commit()
+ self.cli_commit()
# this file must be read with higher permissions
pam_radius_auth_conf = cmd('sudo cat /etc/pam_radius_auth.conf')