Skip to content

Commit 73b4db8

Browse files
authored
Merge pull request #4803 from c-po/smoketest-call-base-class
T7948: always call setUp() and tearDown() base class methods
2 parents 9e1cb14 + 75e2355 commit 73b4db8

File tree

89 files changed

+273
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+273
-69
lines changed

smoketest/scripts/cli/base_accel_ppp_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def setUp(self):
4646
# ensure we can also run this test on a live system - so lets clean
4747
# out the current configuration :)
4848
self.cli_delete(self._base_path)
49+
# always forward to base class
50+
super().setUp()
4951

5052
def tearDown(self):
5153
# Check for running process
@@ -56,6 +58,8 @@ def tearDown(self):
5658

5759
# Check for running process
5860
self.assertFalse(process_named_running(self._process_name))
61+
# always forward to base class
62+
super().tearDown()
5963

6064
def set(self, path):
6165
self.cli_set(self._base_path + path)

smoketest/scripts/cli/base_interfaces_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ def tearDown(self):
217217
else:
218218
self.assertFalse(process_named_running(daemon))
219219

220+
# always forward to base class
221+
super().tearDown()
222+
220223
def test_dhcp_disable_interface(self):
221224
if not self._test_dhcp:
222225
self.skipTest(MSG_TESTCASE_UNSUPPORTED)

smoketest/scripts/cli/base_vyostest_shim.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
from time import sleep
2424
from typing import Type
2525

26+
from vyos import ConfigError
2627
from vyos.configsession import ConfigSession
2728
from vyos.configsession import ConfigSessionError
28-
from vyos import ConfigError
2929
from vyos.defaults import commit_lock
30+
from vyos.frrender import mgmt_daemon
3031
from vyos.utils.process import cmd
32+
from vyos.utils.process import process_named_running
3133
from vyos.utils.process import run
3234

3335
save_config = '/tmp/vyos-smoketest-save'
@@ -42,11 +44,11 @@
4244

4345
class VyOSUnitTestSHIM:
4446
class TestCase(unittest.TestCase):
45-
# if enabled in derived class, print out each and every set/del command
46-
# on the CLI. This is usefull to grap all the commands required to
47-
# trigger the certain failure condition.
48-
# Use "self.debug = True" in derived classes setUp() method
47+
# If enabled, print out each and every set/del command on stdout.
48+
# This is usefull to grap all the commands required to trigger the
49+
# certain failure condition.
4950
debug = False
51+
mgmt_daemon_pid = 0
5052

5153
@staticmethod
5254
def debug_on():
@@ -68,7 +70,10 @@ def setUpClass(cls):
6870
cls._session = ConfigSession(os.getpid())
6971
cls._session.save_config(save_config)
7072
cls.debug = cls.debug_on()
71-
pass
73+
74+
# Retrieve FRR mgmtd daemon PID - it is not allowed to crash, thus
75+
# PID must remain the same
76+
cls.mgmt_daemon_pid = process_named_running(mgmt_daemon)
7277

7378
@classmethod
7479
def tearDownClass(cls):
@@ -83,6 +88,13 @@ def tearDownClass(cls):
8388
cls._session.discard()
8489
cls.fail(cls)
8590

91+
def setUp(self):
92+
pass
93+
94+
def tearDown(self):
95+
# check process health and continuity
96+
self.assertEqual(self.mgmt_daemon_pid, process_named_running(mgmt_daemon))
97+
8698
def cli_set(self, path, value=None):
8799
if self.debug:
88100
str = f'set {" ".join(path)} {value}' if value else f'set {" ".join(path)}'

smoketest/scripts/cli/test_cgnat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def tearDown(self):
3737
self.cli_commit()
3838
self.assertFalse(os.path.exists(nftables_cgnat_config))
3939

40+
# always forward to base class
41+
super().tearDown()
42+
4043
def test_cgnat(self):
4144
internal_name = 'vyos-int-01'
4245
external_name = 'vyos-ext-01'

smoketest/scripts/cli/test_config_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ def test_disk_resident_atomic(self):
9696

9797

9898
if __name__ == '__main__':
99-
unittest.main(verbosity=2)
99+
unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())

smoketest/scripts/cli/test_configd_init.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@
2222
from vyos.utils.process import is_systemd_service_running
2323
from vyos.utils.process import cmd
2424

25+
service_name = 'vyos-configd.service'
26+
2527
class TestConfigdInit(unittest.TestCase):
2628
def setUp(self):
27-
self.running_state = is_systemd_service_running('vyos-configd.service')
29+
self.running_state = is_systemd_service_running(service_name)
30+
# always forward to base class
31+
super().setUp()
32+
33+
def tearDown(self):
34+
if not self.running_state:
35+
cmd(f'sudo systemctl stop {service_name}')
36+
# always forward to base class
37+
super().tearDown()
2838

2939
def test_configd_init(self):
3040
if not self.running_state:
31-
cmd('sudo systemctl start vyos-configd.service')
41+
cmd(f'sudo systemctl start {service_name}')
3242
# allow time for init to succeed/fail
3343
sleep(2)
34-
self.assertTrue(is_systemd_service_running('vyos-configd.service'))
35-
36-
def tearDown(self):
37-
if not self.running_state:
38-
cmd('sudo systemctl stop vyos-configd.service')
44+
self.assertTrue(is_systemd_service_running(service_name))
3945

4046
if __name__ == '__main__':
4147
unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())

smoketest/scripts/cli/test_container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
busybox_image = 'busybox:stable'
3434
busybox_image_path = '/usr/share/vyos/busybox-stable.tar'
3535

36-
3736
def cmd_to_json(command):
3837
c = cmd(command + ' --format=json')
3938
data = json.loads(c)[0]
4039
return data
4140

42-
4341
class TestContainer(VyOSUnitTestSHIM.TestCase):
4442
@classmethod
4543
def setUpClass(cls):
@@ -70,6 +68,8 @@ def tearDown(self):
7068
# Ensure systemd units are removed
7169
units = glob.glob('/run/systemd/system/vyos-container-*')
7270
self.assertEqual(units, [])
71+
# always forward to base class
72+
super().tearDown()
7373

7474
def test_basic(self):
7575
cont_name = 'c1'
@@ -242,7 +242,7 @@ def test_user_defined_mac(self):
242242
self.assertEqual(n['NetworkSettings']['Networks']['bridge1']['MacAddress'], '02:00:00:00:00:01')
243243
n = cmd_to_json(f'sudo podman container inspect test2')
244244
self.assertEqual(n['NetworkSettings']['Networks']['bridge1']['MacAddress'], '02:00:00:00:00:02')
245-
245+
246246
def test_ipv4_network(self):
247247
prefix = '192.0.2.0/24'
248248
base_name = 'ipv4'

smoketest/scripts/cli/test_firewall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def tearDown(self):
7171
]
7272

7373
self.verify_nftables(nftables_search, 'ip vyos_filter', inverse=True)
74+
# always forward to base class
75+
super().tearDown()
7476

7577
def wait_for_domain_resolver(self, table, set_name, element, max_wait=10):
7678
# Resolver no longer blocks commit, need to wait for daemon to populate set

smoketest/scripts/cli/test_high-availability_virtual-server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def tearDown(self):
3838

3939
# Process must be terminated after deleting the config
4040
self.assertFalse(process_named_running(PROCESS_NAME))
41+
# always forward to base class
42+
super().tearDown()
4143

4244
def test_01_ha_virtual_server(self):
4345
algo = 'least-connection'

smoketest/scripts/cli/test_high-availability_vrrp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def tearDown(self):
5050

5151
# Process must be terminated after deleting the config
5252
self.assertFalse(process_named_running(PROCESS_NAME))
53+
# always forward to base class
54+
super().tearDown()
5355

5456
def test_01_default_values(self):
5557
for group in groups:

0 commit comments

Comments
 (0)