From 4978a16bf9d1251737bc51bf1d56ad95be64679d Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 27 Dec 2023 14:04:22 +0300 Subject: [PATCH 01/33] test_ws_ping: Replace tearDown() with addCleanup() for process termination Signed-off-by: Yaroslav Kargin --- ws/test_ws_ping.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ws/test_ws_ping.py b/ws/test_ws_ping.py index 28e7ae1a5..a27f29405 100755 --- a/ws/test_ws_ping.py +++ b/ws/test_ws_ping.py @@ -292,14 +292,21 @@ def setUp(self): self.p1 = None self.p2 = None super().setUp() + self.addCleanup(self.cleanup_p1) + self.addCleanup(self.cleanup_p2) def tearDown(self): + pass + + def cleanup_p1(self): if self.p1: self.p1.terminate() + self.p1 = None + + def cleanup_p2(self): if self.p2: self.p2.terminate() - super().tearDown() - + self.p2 = None class WssPing(WsPing): From 9b2edba1cfa34f5abfa6c172346da59a2241558a Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 27 Dec 2023 20:13:43 +0300 Subject: [PATCH 02/33] tester.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- framework/tester.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/framework/tester.py b/framework/tester.py index 85df9c8c3..8b6272843 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -340,26 +340,41 @@ def setUp(self): self.__create_tempesta() self.__create_clients() self.__run_tcpdump() - - def tearDown(self): - tf_cfg.dbg(3, "\tTeardown") - + # Cleanup part + self.addCleanup(self.cleanup_check_dmesg) + self.addCleanup(self.cleanup_stop_tcpdump) + self.addCleanup(self.cleanup_interfaces) + self.addCleanup(self.cleanup_deproxy) + self.addCleanup(self.cleanup_services) + + def cleanup_services(self): + tf_cfg.dbg(3, "\tCleanup: services") for service in self.get_all_services(): service.stop() + def cleanup_deproxy(self): + tf_cfg.dbg(3, "\tCleanup: deproxy") try: deproxy_manager.finish_all_deproxy() except Exception as e: dbg( self.deproxy_manager, 1, f"Unknown exception in stopping deproxy - {e}", prefix="\t" ) + # TODO it should be changed after #534 issue + self.deproxy_manager.check_exceptions() - tf_cfg.dbg(3, "Removing interfaces") + def cleanup_interfaces(self): + tf_cfg.dbg(3, "\tCleanup: Removing interfaces") interface = tf_cfg.cfg.get("Server", "aliases_interface") sysnet.remove_routes(interface, self.__ips) sysnet.remove_interfaces(interface, self.__ips) self.__ips = [] + def cleanup_stop_tcpdump(self): + tf_cfg.dbg(3, "\tCleanup: stopping tcpdump") + self.__stop_tcpdump() + def cleanup_check_dmesg(self): + tf_cfg.dbg(3, "\tCleanup: checking dmesg") self.oops.update() tf_cfg.dbg( @@ -377,15 +392,14 @@ def tearDown(self): if len(self.oops.log_findall(err)) > 0: self.oops.show() self.oops_ignore = [] - raise Exception("%s happened during test on Tempesta" % err) + raise Exception(f"{err} happened during test on Tempesta") # Drop the list of ignored errors to allow set different errors masks # for different tests. self.oops_ignore = [] del self.oops - self.__stop_tcpdump() - # TODO it should be change after #534 issue - self.deproxy_manager.check_exceptions() + def tearDown(self): + pass def wait_while_busy(self, *items, timeout=20): if items is None: From 6eb176b13b2dec0d756f6c35e5ed1bca7217a83f Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 27 Dec 2023 23:03:53 +0300 Subject: [PATCH 03/33] test_headercollection.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- selftests/test_headercollection.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selftests/test_headercollection.py b/selftests/test_headercollection.py index 0bbf46c32..55b005b8c 100644 --- a/selftests/test_headercollection.py +++ b/selftests/test_headercollection.py @@ -14,9 +14,14 @@ class TestHeaderCollection(unittest.TestCase): def setUp(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = True self.headers = deproxy.HeaderCollection() + self.addCleanup(self.clenup_header_collection) - def tearDown(self): + def clenup_header_collection(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False + self.headers = None + + def tearDown(self): + pass def test_length(self): self.assertEqual(len(self.headers), 0) From 69032af136a65e57f1b1da862661a64703132914 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Thu, 28 Dec 2023 15:05:31 +0300 Subject: [PATCH 04/33] stress.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- testers/stress.py | 48 +++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/testers/stress.py b/testers/stress.py index d3b035d7f..292c4209c 100644 --- a/testers/stress.py +++ b/testers/stress.py @@ -73,45 +73,49 @@ def setUp(self): self.create_clients() self.create_servers() self.create_tempesta() + # Cleanup part + self.addCleanup(self.cleanup_check_dmesg) + self.addCleanup(self.cleanup_servers) + self.addCleanup(self.cleanup_tempesta) - def force_stop(self): - """Forcefully stop all servers.""" - # Call functions only if variables not None: there might be an error - # before tempesta would be created. - if self.tempesta: - self.tempesta.force_stop() - if self.servers: - control.servers_force_stop(self.servers) - - def tearDown(self): - """Carefully stop all servers. Error on stop will make next test fail, - so mark test as failed even if everything other is fine. - """ - # Call functions only if variables not None: there might be an error - # before tempesta would be created. + def cleanup_tempesta(self): if self.tempesta: self.tempesta.stop() + if self.tempesta.state == stateful.STATE_ERROR: + raise Exception("Error during stopping tempesta") + + def cleanup_servers(self): if self.servers: control.servers_stop(self.servers) + for server in self.servers: + if server.state == stateful.STATE_ERROR: + raise Exception("Error during stopping servers") - if self.tempesta.state == stateful.STATE_ERROR: - raise Exception("Error during stopping tempesta") - for server in self.servers: - if server.state == stateful.STATE_ERROR: - raise Exception("Error during stopping servers") - + def cleanup_check_dmesg(self): self.oops.update() for err in ["Oops", "WARNING", "ERROR"]: if err in self.oops_ignore: continue if len(self.oops.log_findall(err)) > 0: self.oops_ignore = [] - raise Exception("%s happened during test on Tempesta" % err) + raise Exception(f"{err} happened during test on Tempesta") # Drop the list of ignored errors to allow set different errors masks # for different tests. self.oops_ignore = [] del self.oops + def force_stop(self): + """Forcefully stop all servers.""" + # Call functions only if variables not None: there might be an error + # before tempesta would be created. + if self.tempesta: + self.tempesta.force_stop() + if self.servers: + control.servers_force_stop(self.servers) + + def tearDown(self): + pass + def show_performance(self): if tf_cfg.v_level() < 2: return From 0bd7b254e27d2ec0fc095250a2c05134b77fb0e9 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Thu, 28 Dec 2023 16:29:55 +0300 Subject: [PATCH 05/33] test_x509.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- selftests/test_x509.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selftests/test_x509.py b/selftests/test_x509.py index 0eb4a5623..853da3657 100644 --- a/selftests/test_x509.py +++ b/selftests/test_x509.py @@ -19,10 +19,11 @@ def cert_text(self) -> str: def setUp(self): self.cgen = CertGenerator() - self.remove_certs() + self.remove_certs() # initial certs cleanup before testing + self.addCleanup(self.remove_certs) def tearDown(self): - self.remove_certs() + pass def remove_certs(self): for path in self.cgen.get_file_paths(): From a375f4b07f91d64f35273a0debb21e01748d5585 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Thu, 28 Dec 2023 16:36:14 +0300 Subject: [PATCH 06/33] A small typo correction Signed-off-by: Yaroslav Kargin --- reconf/reconf_stress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconf/reconf_stress.py b/reconf/reconf_stress.py index c5c37324e..deac454a5 100644 --- a/reconf/reconf_stress.py +++ b/reconf/reconf_stress.py @@ -77,7 +77,7 @@ def assert_clients(self): self.assertLess(err, max_err) def stress_reconfig_generic(self, configure_func, reconfigure_func): - """Generic test routinr for reconfig.""" + """Generic test routine for reconfig.""" self.reconfigure_func = reconfigure_func control.servers_start(self.servers) configure_func() From 54fa59142087a96b361dfbf7187f6a7240e2f2a8 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Thu, 28 Dec 2023 18:13:36 +0300 Subject: [PATCH 07/33] reconf_stress.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- reconf/reconf_stress.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/reconf/reconf_stress.py b/reconf/reconf_stress.py index deac454a5..b048279ee 100644 --- a/reconf/reconf_stress.py +++ b/reconf/reconf_stress.py @@ -19,6 +19,19 @@ class LiveReconfStress(stress.StressTest): sg_name = "default" auto_vhosts = True + def setUp(self): + self.addCleanup(self.cleanup_parent_teardown) + self.addCleanup(self.cleanup_reconfig_thread) + + def cleanup_reconfig_thread(self): + # Wait for reconfig thread if it's not finished (exception was thrown + # during stress_reconfig_generic() + if hasattr(self, "r_thread"): + self.r_thread.join() + + def cleanup_parent_teardown(self): + stress.StressTest.tearDown(self) + def create_servers(self): port = tempesta.upstream_port_start_from() rm_srv_n = tempesta.servers_in_group() / 3 @@ -94,11 +107,7 @@ def stress_reconfig_generic(self, configure_func, reconfigure_func): self.assert_clients() def tearDown(self): - # Wait for reconfig thread if it's not finished (exception was thrown - # during stress_reconfig_generic() - if hasattr(self, "r_thread"): - self.r_thread.join() - stress.StressTest.tearDown(self) + pass def configure_srvs_start(self): srvs = self.const_srvs + self.rm_srvs From 6e954ad838b46c58e57bde480dbd307683a86ff9 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 29 Dec 2023 00:47:23 +0300 Subject: [PATCH 08/33] test_sockets.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- flacky_net/test_sockets.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/flacky_net/test_sockets.py b/flacky_net/test_sockets.py index 0fdfd0542..23ebfbe6d 100644 --- a/flacky_net/test_sockets.py +++ b/flacky_net/test_sockets.py @@ -77,16 +77,26 @@ def check_sockets(self, allow_conns=True): def setUp(self): stress.StressTest.setUp(self) self.filter = None + # Cleanup part + self.addCleanup(self.cleanup_parent_teardown) + self.addCleanup(self.cleanup_stop_tempesta) + self.addCleanup(self.cleanup_filter) - def tearDown(self): + def cleanup_filter(self): if self.filter: self.filter.clean_up() + + def cleanup_stop_tempesta(self): if hasattr(self, "dummy_servers"): # No need to stop servers. if self.tempesta: self.tempesta.stop() - else: - stress.StressTest.tearDown(self) + + def cleanup_parent_teardown(self): + stress.StressTest.tearDown(self) + + def tearDown(self): + pass def init_filter(self): node = self.servers[0].node From f27dd9a319520442dd87c39a824e20909a40d0d7 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 29 Dec 2023 01:08:25 +0300 Subject: [PATCH 09/33] mixins.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- framework/mixins.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/framework/mixins.py b/framework/mixins.py index db6a67872..4332c2053 100644 --- a/framework/mixins.py +++ b/framework/mixins.py @@ -13,6 +13,12 @@ def setUp(self): self.skipTest("This is an abstract class") self._nf_mark = None super().setUp() + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_del_nf_mark) + + def cleanup_del_nf_mark(self): + if self._nf_mark: + self.del_nf_mark(self._nf_mark) def set_nf_mark(self, mark): cmd = "iptables -t mangle -A PREROUTING -p tcp -j MARK --set-mark %s" % mark @@ -27,6 +33,4 @@ def del_nf_mark(self, mark): self._nf_mark = None def tearDown(self): - super().tearDown() - if self._nf_mark: - self.del_nf_mark(self._nf_mark) + pass From b1ccebeb51e0cc60f89797018accbba13c4de9a0 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 29 Dec 2023 01:17:38 +0300 Subject: [PATCH 10/33] test_reboot.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- regression/test_reboot.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/regression/test_reboot.py b/regression/test_reboot.py index c338972ce..6f0ce7ba6 100644 --- a/regression/test_reboot.py +++ b/regression/test_reboot.py @@ -25,6 +25,15 @@ class RebootUnderLoadTest(stress.StressTest): # Timeout before first reboot. warm_timeout = 0 + def setUp(self): + super().setUp() + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_r_thread) + + def cleanup_r_thread(self): + if hasattr(self, "r_thread"): + self.r_thread.join() + def create_clients(self): self.wrk = control.Wrk() self.wrk.set_script("foo", content="") @@ -57,9 +66,7 @@ def reboot_routine(self, config): self.show_performance() def tearDown(self): - if hasattr(self, "r_thread"): - self.r_thread.join() - stress.StressTest.tearDown(self) + pass def test_proxy(self): config = "cache 0;\n" From 4c592e096e8bbbaaafab5a0a5d59ddc07ce9bb28 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 29 Dec 2023 01:23:02 +0300 Subject: [PATCH 11/33] test_shutdown.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- regression/test_shutdown.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/regression/test_shutdown.py b/regression/test_shutdown.py index 7f4446b33..04a2ec627 100644 --- a/regression/test_shutdown.py +++ b/regression/test_shutdown.py @@ -23,14 +23,23 @@ class ShutdownTest(functional.FunctionalTest): def setUp(self): self.clients = [] - functional.FunctionalTest.setUp(self) + super().setUp() + # Cleanup part + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_tester) + self.addCleanup(self.cleanup_tempesta) - def tearDown(self): + def cleanup_tempesta(self): if self.tempesta: self.tempesta.stop("Tempesta") + + def cleanup_tester(self): if self.tester: self.tester.stop("Tester") + def tearDown(self): + pass + def create_tester(self): pass From c19d45023cf384f3d8d8f001fc99508d8c57c46f Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 13:55:48 +0300 Subject: [PATCH 12/33] test_deproxy.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- selftests/test_deproxy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/selftests/test_deproxy.py b/selftests/test_deproxy.py index c9481597b..d824184c9 100644 --- a/selftests/test_deproxy.py +++ b/selftests/test_deproxy.py @@ -30,13 +30,21 @@ def setUp(self): self.tester = None tf_cfg.dbg(3) # Step to the next line after name of test case. tf_cfg.dbg(3, "\tInit test case...") + # Cleanup part + self.addCleanup(self.cleanup_tester) + self.addCleanup(self.cleanup_client) - def tearDown(self): + def cleanup_client(self): if self.client: self.client.stop() + + def cleanup_tester(self): if self.tester: self.tester.stop() + def tearDown(self): + pass + def create_clients(self): port = tempesta.upstream_port_start_from() self.client = deproxy.Client(port=port, host="Client") From 1fc9d4586e2866f3b82a82b6e166e7e2d9a3157d Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 14:05:23 +0300 Subject: [PATCH 13/33] test_deproxy_message.py: * Replace tearDown() with addCleanup(). * Minor typo fix Signed-off-by: Yaroslav Kargin --- selftests/test_deproxy_message.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/selftests/test_deproxy_message.py b/selftests/test_deproxy_message.py index 6d4bdf888..806e20841 100644 --- a/selftests/test_deproxy_message.py +++ b/selftests/test_deproxy_message.py @@ -8,10 +8,15 @@ class TestDeproxyMessage(unittest.TestCase): def setUp(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = True + # Cleanup part + self.addCleanup(self.cleanup_deproxy) - def tearDown(self): + def cleanup_deproxy(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False + def tearDown(self): + pass + def test_incomplite(self): message_1 = "HTTP/1.1 20" message_2 = ( @@ -78,7 +83,7 @@ def test_incomplite(self): (message_6, "body: too short"), ] for message, reason in incomplite: - msg = "Message parsed, but it has incomplite %s. Message:\n%s" % (reason, message) + msg = "Message parsed, but it has incomplete %s. Message:\n%s" % (reason, message) parsed = True try: deproxy.Response(message) From f893c9271e02f17e3ed5fe7929d1617d82979f7c Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 14:11:28 +0300 Subject: [PATCH 14/33] test_requests.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- selftests/test_requests.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selftests/test_requests.py b/selftests/test_requests.py index d896cff1b..945a3a78b 100644 --- a/selftests/test_requests.py +++ b/selftests/test_requests.py @@ -15,10 +15,15 @@ def setUp(self): self.plain = deproxy.Request(PLAIN) self.reordered = deproxy.Request(REORDERED) self.duplicated = deproxy.Request(DUPLICATED) + # Cleanup part + self.addCleanup(self.cleanup_deproxy) - def tearDown(self): + def cleanup_deproxy(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False + def tearDown(self): + pass + def test_equal(self): # Reordering of headers is allowed. self.assertTrue(self.plain == self.reordered) From b9b6fb794e11b119072b7c6f99c2f1f32565c209 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 14:16:04 +0300 Subject: [PATCH 15/33] test_responses.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- selftests/test_responses.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selftests/test_responses.py b/selftests/test_responses.py index c0c51d960..9fbbf7337 100644 --- a/selftests/test_responses.py +++ b/selftests/test_responses.py @@ -20,10 +20,15 @@ def setUp(self): self.trailer = deproxy.Response(TRAILER) self.o_trailer = deproxy.Response(OTHER_TRAILER) + # Cleanup part + self.addCleanup(self.cleanup_HeaderCollection) - def tearDown(self): + def cleanup_HeaderCollection(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False + def tearDown(self): + pass + def test_equal(self): # Reordering of headers is allowed. self.assertTrue(self.plain == self.reordered) From 5170e5a45937850a360ed6cc3cb31a6099ddac04 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 14:38:36 +0300 Subject: [PATCH 16/33] frang_test_case.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- t_frang/frang_test_case.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/t_frang/frang_test_case.py b/t_frang/frang_test_case.py index 181dd756f..0d82dcbe5 100644 --- a/t_frang/frang_test_case.py +++ b/t_frang/frang_test_case.py @@ -68,11 +68,16 @@ def setUp(self): super().setUp() self.klog = dmesg.DmesgFinder(disable_ratelimit=True) self.assert_msg = "Expected nums of warnings in `journalctl`: {exp}, but got {got}" + # Cleanup part + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_klog) - def tearDown(self): - super().tearDown() + def cleanup_klog(self): del self.klog + def tearDown(self): + pass + # TODO: rename to set_frang_cfg_and_start def set_frang_config(self, frang_config: str): self.tempesta["config"] = self.tempesta_template["config"] % { From 5ca351eb02b92418b20ec5c35bfaaa1971361229 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 14:52:40 +0300 Subject: [PATCH 17/33] test_http_tables.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- t_http_rules/test_http_tables.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/t_http_rules/test_http_tables.py b/t_http_rules/test_http_tables.py index f2a1b4ba6..5ad110825 100644 --- a/t_http_rules/test_http_tables.py +++ b/t_http_rules/test_http_tables.py @@ -255,11 +255,16 @@ def del_nf_mark(self, mark): def setUp(self): self.marked = None HttpTablesTest.setUp(self) + # Cleanup part + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_marked) - def tearDown(self): + def cleanup_marked(self): if self.marked: self.del_nf_mark(self.marked) - tester.TempestaTest.tearDown(self) + + def tearDown(self): + pass def test_chains(self): """Test for mark rules in HTTP chains: requests must From ffd472cb166598b5aa699f3a9a175c488c457105 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 15:03:16 +0300 Subject: [PATCH 18/33] test_long_request.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- t_long_body/test_long_request.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/t_long_body/test_long_request.py b/t_long_body/test_long_request.py index 23d209371..1652338ea 100644 --- a/t_long_body/test_long_request.py +++ b/t_long_body/test_long_request.py @@ -114,15 +114,21 @@ def setUp(self): self.abs_path = os.path.join(location, "long_body.bin") remote.client.copy_file(self.abs_path, "x" * BODY_SIZE) super().setUp() + # Cleanup part + self.addCleanup(self.cleanup_file) + self.addCleanup(self.cleanup_verbose) + self.addCleanup(super().tearDown) - def tearDown(self): - super().tearDown() - + def cleanup_verbose(self): tf_cfg.cfg.set_option("General", "verbose", self.verbose) + def cleanup_file(self): if not remote.DEBUG_FILES: remote.client.run_cmd(f"rm {self.abs_path}") + def tearDown(self): + pass + def _test(self, client_id: str, header: str): """Send request with long body and check that Tempesta does not crash.""" self.start_all_services(client=False) From c78b52ae1a235076ffd058db80f00d42adebd2e6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 15:23:24 +0300 Subject: [PATCH 19/33] test_stress.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- t_stress/test_stress.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/t_stress/test_stress.py b/t_stress/test_stress.py index 7d4f1e192..8022e2f76 100644 --- a/t_stress/test_stress.py +++ b/t_stress/test_stress.py @@ -143,10 +143,12 @@ def setUp(self): ] super().setUp() self.create_large_page() + # Cleanup part + self.addCleanup(self.remove_large_page) + self.addCleanup(super().tearDown) def tearDown(self): - super().tearDown() - self.remove_large_page() + pass def create_large_page(self): server = self.get_server("nginx-large-page") @@ -184,14 +186,17 @@ def setUp(self): destination_ip=tf_cfg.cfg.get("Tempesta", "ip"), mtu=self.server_to_tempesta_mtu, ) + # Cleanup part + self.addCleanup(super().tearDown) + self.addCleanup(self.cleanup_mtus) - def tearDown(self): + def cleanup_mtus(self): # Restore previous MTU values - try: - for args in self._prev_mtu.values(): - sysnet.change_mtu(*args) - finally: - super().tearDown() + for args in self._prev_mtu.values(): + sysnet.change_mtu(*args) + + def tearDown(self): + pass def set_mtu(self, node, destination_ip, mtu): if mtu: @@ -574,12 +579,17 @@ class RequestStress(CustomMtuMixin, tester.TempestaTest): def setUp(self): remote.client.copy_file(self.fullname, "x" * LARGE_CONTENT_LENGTH) super().setUp() + # Cleanup part + self.addCleanup(self.cleanup_test_file) + self.addCleanup(super().tearDown) - def tearDown(self): - super().tearDown() + def cleanup_test_file(self): if not remote.DEBUG_FILES: remote.client.run_cmd(f"rm {self.fullname}") + def tearDown(self): + pass + def _test_wrk(self, client_id: str, method: str): """ HTTP stress test generated by `wrk` with concurrent connections and large body in request. From 65db7d629ff17e693f2d3328e29bc0bbf985a025 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Tue, 2 Jan 2024 15:57:55 +0300 Subject: [PATCH 20/33] functional.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- testers/functional.py | 54 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/testers/functional.py b/testers/functional.py index 5fea7a73e..de8a3de15 100644 --- a/testers/functional.py +++ b/testers/functional.py @@ -67,6 +67,58 @@ def setUp(self): self.create_tempesta() self.create_client() self.create_tester() + # Cleanup part + self.addCleanup(self.cleanup_check_oops, oops_list=["Oops", "WARNING", "ERROR"]) + self.addCleanup(self.cleanup_check_errors) + self.addCleanup(self.cleanup_deproxy) + self.addCleanup(self.cleanup_servers) + self.addCleanup(self.cleanup_tester) + self.addCleanup(self.cleanup_tempesta) + self.addCleanup(self.cleanup_client) + + def cleanup_client(self): + # Close client connection before stopping the TempestaFW. + if self.client: + self.client.stop("Client") + + def cleanup_tempesta(self): + if self.tempesta: + self.tempesta.stop("Tempesta") + + def cleanup_tester(self): + if self.tester: + self.tester.stop("Tester") + + def cleanup_servers(self): + for server in self.servers: + server.stop("Deproxy server") + + def cleanup_deproxy(self): + try: + deproxy.finish_all_deproxy() + except: + print("Unknown exception in stopping deproxy") + + def cleanup_check_errors(self): + for proc in [self.client, self.tempesta, self.tester]: + if proc.state == stateful.STATE_ERROR: + raise Exception(f"Error during stopping {proc.__class__.__name__}") + for server in self.servers: + if server.state == stateful.STATE_ERROR: + raise Exception("Error during stopping server") + + def cleanup_check_oops(self, oops_list): + self.oops.update() + for err in oops_list: + if err in self.oops_ignore: + continue + if len(self.oops.log_findall(err)) > 0: + self.oops_ignore = [] + raise Exception(f"{err} happened during test on Tempesta") + # Drop the list of ignored errors to allow set different errors masks + # for different tests. + self.oops_ignore = [] + del self.oops def force_stop(self): # Close client connection before stopping the TempestaFW. @@ -88,7 +140,7 @@ def force_stop(self): print("Unknown exception in stopping deproxy") def tearDown(self): - # Close client connection before stopping the TempestaFW. + if self.client: self.client.stop("Client") From e4684e657c19e8385c13bbfc421e976ef34a4ca7 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 3 Jan 2024 00:05:30 +0300 Subject: [PATCH 21/33] multi_backend.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- very_many_backends/multi_backend.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/very_many_backends/multi_backend.py b/very_many_backends/multi_backend.py index 02976c4b4..69ea7d0e1 100644 --- a/very_many_backends/multi_backend.py +++ b/very_many_backends/multi_backend.py @@ -262,6 +262,20 @@ class MultipleBackends(stress.StressTest): base_port = 16384 + def setUp(self): + super().setUp() + self.create_servers() + self.configure_tempesta() + # Cleanup part + self.addCleanup(self.cleanup_interfaces) + self.addCleanup(self.cleanup_servers) + self.addCleanup(self.cleanup_tempesta) + + def cleanup_interfaces(self): + tf_cfg.dbg(2, "Cleanup: Removing interfaces") + sysnet.remove_interfaces(self.interface, self.ips) + self.ips = [] + def create_servers(self): self.interface = tf_cfg.cfg.get("Server", "aliases_interface") self.base_ip = tf_cfg.cfg.get("Server", "aliases_base_ip") @@ -283,18 +297,7 @@ def configure_tempesta(self): sgid = sgid + 1 def tearDown(self): - """Stop nginx and tempesta, clear interfaces after this""" - has_base_excpt = False - try: - super(MultipleBackends, self).tearDown() - except Exception as exc: - has_base_excpt = True - excpt = exc - tf_cfg.dbg(2, "Removing interfaces") - sysnet.remove_interfaces(self.interface, self.ips) - self.ips = [] - if has_base_excpt: - raise excpt + pass def test(self): """Test 1M backends""" From 3c0d840a9281550b8f8d68c5d6f02f3d81618ee6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 3 Jan 2024 00:33:19 +0300 Subject: [PATCH 22/33] test_deadtime_1M.py: Replace tearDown() with addCleanup(). Signed-off-by: Yaroslav Kargin --- very_many_backends/test_deadtime_1M.py | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/very_many_backends/test_deadtime_1M.py b/very_many_backends/test_deadtime_1M.py index 4645f2e09..d7392a5c5 100644 --- a/very_many_backends/test_deadtime_1M.py +++ b/very_many_backends/test_deadtime_1M.py @@ -143,28 +143,31 @@ def setUp(self): self.ips = sysnet.create_interfaces( self.interface, self.base_ip, self.num_extra_interfaces + 1 ) - stress.StressTest.setUp(self) - - def tearDown(self): - has_base_excpt = False - # stopping client - if self.client != None: + super().setUp() + # Cleanup part + self.addCleanup(self.cleanup_interfaces) + self.addCleanup(self.cleanup_servers) + self.addCleanup(self.cleanup_tempesta) + self.addCleanup(self.cleanup_check_client_error) + self.addCleanup(self.cleanup_client) + + def cleanup_client(self): + if self.client is not None: self.client.stop() - # stopping tempesta and servers - try: - stress.StressTest.tearDown(self) - except Exception as exc: - has_base_excpt = True - excpt = exc - tf_cfg.dbg(2, "Removing interfaces") + + def cleanup_interfaces(self): + tf_cfg.dbg(2, "Cleanup: Removing interfaces") for ip in self.ips: sysnet.remove_interface(self.interface, ip) self.ips = [] - if has_base_excpt: - raise excpt + + def cleanup_check_client_error(self): if self.client.state == stateful.STATE_ERROR: raise Exception("Error while stopping client") + def tearDown(self): + pass + def configure_tempesta(self): """Configure tempesta 1 port in group""" sg = tempesta.ServerGroup("default") From 06b7d77d0f5ceba84a0b8ada6a034e0e40883ad5 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Mon, 8 Jan 2024 17:12:35 +0300 Subject: [PATCH 23/33] Apply Black code formatter Signed-off-by: Yaroslav Kargin --- framework/tester.py | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/tester.py b/framework/tester.py index 8b6272843..f8b041495 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -369,6 +369,7 @@ def cleanup_interfaces(self): sysnet.remove_routes(interface, self.__ips) sysnet.remove_interfaces(interface, self.__ips) self.__ips = [] + def cleanup_stop_tcpdump(self): tf_cfg.dbg(3, "\tCleanup: stopping tcpdump") self.__stop_tcpdump() From cbcdc092e18e246cb5cad1777f72e209b2259239 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Sun, 14 Jan 2024 14:53:50 +0300 Subject: [PATCH 24/33] Removed outdated comment Signed-off-by: Yaroslav Kargin --- framework/tester.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/framework/tester.py b/framework/tester.py index f8b041495..b70929472 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -247,7 +247,7 @@ def get_servers_id(self): def __create_clients(self): if not remote.wait_available(): - raise Exception("Client node is unavaliable") + raise Exception("Client node is unavailable") for client in self.clients: # Copy description to keep it clean between several tests. self.__create_client(client.copy()) @@ -333,7 +333,7 @@ def setUp(self): tf_cfg.dbg(3, "\tInit test case...") if not remote.wait_available(): - raise Exception("Tempesta node is unavaliable") + raise Exception("Tempesta node is unavailable") self.oops = dmesg.DmesgFinder() self.oops_ignore = [] self.__create_servers() @@ -360,7 +360,6 @@ def cleanup_deproxy(self): dbg( self.deproxy_manager, 1, f"Unknown exception in stopping deproxy - {e}", prefix="\t" ) - # TODO it should be changed after #534 issue self.deproxy_manager.check_exceptions() def cleanup_interfaces(self): From 31ad983281e556f477621e32e2772cdb53a014c2 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Sun, 14 Jan 2024 15:34:25 +0300 Subject: [PATCH 25/33] Revert "test_deproxy.py: Replace tearDown() with addCleanup()." This reverts commit 1a77d1e46bcecb113e0b3540098d6b86858b890c. No need to modify old-framework based tests --- selftests/test_deproxy.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/selftests/test_deproxy.py b/selftests/test_deproxy.py index d824184c9..c9481597b 100644 --- a/selftests/test_deproxy.py +++ b/selftests/test_deproxy.py @@ -30,21 +30,13 @@ def setUp(self): self.tester = None tf_cfg.dbg(3) # Step to the next line after name of test case. tf_cfg.dbg(3, "\tInit test case...") - # Cleanup part - self.addCleanup(self.cleanup_tester) - self.addCleanup(self.cleanup_client) - def cleanup_client(self): + def tearDown(self): if self.client: self.client.stop() - - def cleanup_tester(self): if self.tester: self.tester.stop() - def tearDown(self): - pass - def create_clients(self): port = tempesta.upstream_port_start_from() self.client = deproxy.Client(port=port, host="Client") From 3b1474f68bda73dbe41e026597c896612d816e34 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Sun, 14 Jan 2024 17:12:35 +0300 Subject: [PATCH 26/33] Revert "test_shutdown.py: Replace tearDown() with addCleanup()." This reverts commit f3b534378a2fd0410e8b2e6267f729fa84d07010. No need to modify old-framework based tests --- regression/test_shutdown.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/regression/test_shutdown.py b/regression/test_shutdown.py index 04a2ec627..7f4446b33 100644 --- a/regression/test_shutdown.py +++ b/regression/test_shutdown.py @@ -23,23 +23,14 @@ class ShutdownTest(functional.FunctionalTest): def setUp(self): self.clients = [] - super().setUp() - # Cleanup part - self.addCleanup(super().tearDown) - self.addCleanup(self.cleanup_tester) - self.addCleanup(self.cleanup_tempesta) + functional.FunctionalTest.setUp(self) - def cleanup_tempesta(self): + def tearDown(self): if self.tempesta: self.tempesta.stop("Tempesta") - - def cleanup_tester(self): if self.tester: self.tester.stop("Tester") - def tearDown(self): - pass - def create_tester(self): pass From 8901750d90bf7b814e23e3bd8500e1223d0b8b39 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Sun, 14 Jan 2024 17:34:08 +0300 Subject: [PATCH 27/33] Revert "functional.py: Replace tearDown() with addCleanup()." This reverts commit 935eb7061518d081ca445ffa9fcb69ef4d5175a9. No need to modify old-framework based tests --- testers/functional.py | 54 +------------------------------------------ 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/testers/functional.py b/testers/functional.py index de8a3de15..5fea7a73e 100644 --- a/testers/functional.py +++ b/testers/functional.py @@ -67,58 +67,6 @@ def setUp(self): self.create_tempesta() self.create_client() self.create_tester() - # Cleanup part - self.addCleanup(self.cleanup_check_oops, oops_list=["Oops", "WARNING", "ERROR"]) - self.addCleanup(self.cleanup_check_errors) - self.addCleanup(self.cleanup_deproxy) - self.addCleanup(self.cleanup_servers) - self.addCleanup(self.cleanup_tester) - self.addCleanup(self.cleanup_tempesta) - self.addCleanup(self.cleanup_client) - - def cleanup_client(self): - # Close client connection before stopping the TempestaFW. - if self.client: - self.client.stop("Client") - - def cleanup_tempesta(self): - if self.tempesta: - self.tempesta.stop("Tempesta") - - def cleanup_tester(self): - if self.tester: - self.tester.stop("Tester") - - def cleanup_servers(self): - for server in self.servers: - server.stop("Deproxy server") - - def cleanup_deproxy(self): - try: - deproxy.finish_all_deproxy() - except: - print("Unknown exception in stopping deproxy") - - def cleanup_check_errors(self): - for proc in [self.client, self.tempesta, self.tester]: - if proc.state == stateful.STATE_ERROR: - raise Exception(f"Error during stopping {proc.__class__.__name__}") - for server in self.servers: - if server.state == stateful.STATE_ERROR: - raise Exception("Error during stopping server") - - def cleanup_check_oops(self, oops_list): - self.oops.update() - for err in oops_list: - if err in self.oops_ignore: - continue - if len(self.oops.log_findall(err)) > 0: - self.oops_ignore = [] - raise Exception(f"{err} happened during test on Tempesta") - # Drop the list of ignored errors to allow set different errors masks - # for different tests. - self.oops_ignore = [] - del self.oops def force_stop(self): # Close client connection before stopping the TempestaFW. @@ -140,7 +88,7 @@ def force_stop(self): print("Unknown exception in stopping deproxy") def tearDown(self): - + # Close client connection before stopping the TempestaFW. if self.client: self.client.stop("Client") From d371ce0f3560f66bbfb0f565e9dbc51b1e362bc8 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 17 Jan 2024 12:58:11 +0300 Subject: [PATCH 28/33] Fix: AttributeError: 'FrangHostRequiredH2TestCase' object has no attribute 'oops' for tester.py Signed-off-by: Yaroslav Kargin --- framework/tester.py | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/tester.py b/framework/tester.py index b70929472..f6ace4b39 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -396,7 +396,6 @@ def cleanup_check_dmesg(self): # Drop the list of ignored errors to allow set different errors masks # for different tests. self.oops_ignore = [] - del self.oops def tearDown(self): pass From 7ae7c73aeb81083b58b2b00c434b651432c8169e Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 17 Jan 2024 17:21:11 +0300 Subject: [PATCH 29/33] Fix error reporting for test_http_tables.py Signed-off-by: Yaroslav Kargin --- t_http_rules/test_http_tables.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/t_http_rules/test_http_tables.py b/t_http_rules/test_http_tables.py index 5ad110825..cfaeb5418 100644 --- a/t_http_rules/test_http_tables.py +++ b/t_http_rules/test_http_tables.py @@ -4,10 +4,10 @@ (in separate tests). """ from framework import tester -from helpers import chains, remote +from helpers import chains, remote, dmesg __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2022-2023 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2022-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -583,6 +583,7 @@ def tearDown(self): pass def test(self): + self.oops_ignore = ["ERROR"] try: self.start_tempesta() started = True @@ -590,6 +591,10 @@ def test(self): started = False finally: self.assertFalse(started) + self.oops.find( + "ERROR: http_tbl: too many vars (more 8) in redirection url:", + cond=dmesg.amount_positive, + ) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 8fb095268f3e68a8342a2e35f5b12feeb14e05a3 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 17 Jan 2024 21:07:08 +0300 Subject: [PATCH 30/33] Fix: cleanup Signed-off-by: Yaroslav Kargin --- t_frang/frang_test_case.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t_frang/frang_test_case.py b/t_frang/frang_test_case.py index 0d82dcbe5..a8fad7c0b 100644 --- a/t_frang/frang_test_case.py +++ b/t_frang/frang_test_case.py @@ -1,7 +1,7 @@ """Basic file for frang functional tests.""" __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2022-2023 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2022-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -73,7 +73,8 @@ def setUp(self): self.addCleanup(self.cleanup_klog) def cleanup_klog(self): - del self.klog + if hasattr(self, "klog"): + del self.klog def tearDown(self): pass From f8aa55acbc38d971d502c933092fc656ae6d4501 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Wed, 17 Jan 2024 21:29:27 +0300 Subject: [PATCH 31/33] Cleanup: removed empty tearDowns Signed-off-by: Yaroslav Kargin --- flacky_net/test_sockets.py | 6 +----- framework/mixins.py | 3 --- framework/tester.py | 5 +---- reconf/reconf_stress.py | 6 +----- regression/test_reboot.py | 5 +---- selftests/test_deproxy_message.py | 3 --- selftests/test_headercollection.py | 5 +---- selftests/test_requests.py | 5 +---- selftests/test_responses.py | 5 +---- selftests/test_x509.py | 5 +---- t_frang/frang_test_case.py | 3 --- t_http_rules/test_http_tables.py | 6 ------ t_long_body/test_long_request.py | 5 +---- t_stress/test_stress.py | 11 +---------- testers/stress.py | 5 +---- very_many_backends/multi_backend.py | 5 +---- very_many_backends/test_deadtime_1M.py | 5 +---- ws/test_ws_ping.py | 6 ++---- 18 files changed, 15 insertions(+), 79 deletions(-) diff --git a/flacky_net/test_sockets.py b/flacky_net/test_sockets.py index 23ebfbe6d..590696f21 100644 --- a/flacky_net/test_sockets.py +++ b/flacky_net/test_sockets.py @@ -8,12 +8,11 @@ from testers import stress __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" class CloseOnShutdown(stress.StressTest): - timeout = 180 config = "cache 0;\n" "\n" @@ -95,9 +94,6 @@ def cleanup_stop_tempesta(self): def cleanup_parent_teardown(self): stress.StressTest.tearDown(self) - def tearDown(self): - pass - def init_filter(self): node = self.servers[0].node self.filter = flacky.Filter(node) diff --git a/framework/mixins.py b/framework/mixins.py index 4332c2053..a2b2dce89 100644 --- a/framework/mixins.py +++ b/framework/mixins.py @@ -31,6 +31,3 @@ def del_nf_mark(self, mark): tf_cfg.dbg(3, f"Delete Netfiler mark: {mark}") remote.tempesta.run_cmd(cmd, timeout=30) self._nf_mark = None - - def tearDown(self): - pass diff --git a/framework/tester.py b/framework/tester.py index f6ace4b39..750593b35 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -20,7 +20,7 @@ from helpers import control, dmesg, remote, sysnet, tf_cfg __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2018-2023 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2018-2024 Tempesta Technologies, Inc." __license__ = "GPL2" from helpers.deproxy import dbg @@ -397,9 +397,6 @@ def cleanup_check_dmesg(self): # for different tests. self.oops_ignore = [] - def tearDown(self): - pass - def wait_while_busy(self, *items, timeout=20): if items is None: return diff --git a/reconf/reconf_stress.py b/reconf/reconf_stress.py index b048279ee..502e5b2db 100644 --- a/reconf/reconf_stress.py +++ b/reconf/reconf_stress.py @@ -9,12 +9,11 @@ from testers import stress __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" class LiveReconfStress(stress.StressTest): - defconfig = "" sg_name = "default" auto_vhosts = True @@ -106,9 +105,6 @@ def stress_reconfig_generic(self, configure_func, reconfigure_func): self.r_thread.join() self.assert_clients() - def tearDown(self): - pass - def configure_srvs_start(self): srvs = self.const_srvs + self.rm_srvs config = self.make_config(self.sg_name, srvs) diff --git a/regression/test_reboot.py b/regression/test_reboot.py index 6f0ce7ba6..2a07eb75c 100644 --- a/regression/test_reboot.py +++ b/regression/test_reboot.py @@ -11,7 +11,7 @@ from testers import stress __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -65,9 +65,6 @@ def reboot_routine(self, config): control.client_run_blocking(self.wrk) self.show_performance() - def tearDown(self): - pass - def test_proxy(self): config = "cache 0;\n" self.reboot_routine(config) diff --git a/selftests/test_deproxy_message.py b/selftests/test_deproxy_message.py index 806e20841..764a0061b 100644 --- a/selftests/test_deproxy_message.py +++ b/selftests/test_deproxy_message.py @@ -14,9 +14,6 @@ def setUp(self): def cleanup_deproxy(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False - def tearDown(self): - pass - def test_incomplite(self): message_1 = "HTTP/1.1 20" message_2 = ( diff --git a/selftests/test_headercollection.py b/selftests/test_headercollection.py index 55b005b8c..93ceab2e1 100644 --- a/selftests/test_headercollection.py +++ b/selftests/test_headercollection.py @@ -6,7 +6,7 @@ from helpers import deproxy __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -20,9 +20,6 @@ def clenup_header_collection(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False self.headers = None - def tearDown(self): - pass - def test_length(self): self.assertEqual(len(self.headers), 0) self.headers.add("Name", "Value") diff --git a/selftests/test_requests.py b/selftests/test_requests.py index 945a3a78b..6718712fb 100644 --- a/selftests/test_requests.py +++ b/selftests/test_requests.py @@ -5,7 +5,7 @@ from helpers import deproxy __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -21,9 +21,6 @@ def setUp(self): def cleanup_deproxy(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False - def tearDown(self): - pass - def test_equal(self): # Reordering of headers is allowed. self.assertTrue(self.plain == self.reordered) diff --git a/selftests/test_responses.py b/selftests/test_responses.py index 9fbbf7337..50ef9c117 100644 --- a/selftests/test_responses.py +++ b/selftests/test_responses.py @@ -5,7 +5,7 @@ from helpers import deproxy __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -26,9 +26,6 @@ def setUp(self): def cleanup_HeaderCollection(self): deproxy.HeaderCollection._disable_report_wrong_is_expected = False - def tearDown(self): - pass - def test_equal(self): # Reordering of headers is allowed. self.assertTrue(self.plain == self.reordered) diff --git a/selftests/test_x509.py b/selftests/test_x509.py index 853da3657..217fc410b 100644 --- a/selftests/test_x509.py +++ b/selftests/test_x509.py @@ -5,7 +5,7 @@ from framework.x509 import CertGenerator __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2022 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2022-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -22,9 +22,6 @@ def setUp(self): self.remove_certs() # initial certs cleanup before testing self.addCleanup(self.remove_certs) - def tearDown(self): - pass - def remove_certs(self): for path in self.cgen.get_file_paths(): Path(path).unlink(missing_ok=True) diff --git a/t_frang/frang_test_case.py b/t_frang/frang_test_case.py index a8fad7c0b..e5ab5e726 100644 --- a/t_frang/frang_test_case.py +++ b/t_frang/frang_test_case.py @@ -76,9 +76,6 @@ def cleanup_klog(self): if hasattr(self, "klog"): del self.klog - def tearDown(self): - pass - # TODO: rename to set_frang_cfg_and_start def set_frang_config(self, frang_config: str): self.tempesta["config"] = self.tempesta_template["config"] % { diff --git a/t_http_rules/test_http_tables.py b/t_http_rules/test_http_tables.py index cfaeb5418..84db56cce 100644 --- a/t_http_rules/test_http_tables.py +++ b/t_http_rules/test_http_tables.py @@ -263,9 +263,6 @@ def cleanup_marked(self): if self.marked: self.del_nf_mark(self.marked) - def tearDown(self): - pass - def test_chains(self): """Test for mark rules in HTTP chains: requests must arrive to backends in reverse order, since mark rules are @@ -579,9 +576,6 @@ class HttpTablesTestCustomRedirectTooManyVariables(tester.TempestaTest): ) } - def tearDown(self): - pass - def test(self): self.oops_ignore = ["ERROR"] try: diff --git a/t_long_body/test_long_request.py b/t_long_body/test_long_request.py index 1652338ea..52c101406 100644 --- a/t_long_body/test_long_request.py +++ b/t_long_body/test_long_request.py @@ -1,7 +1,7 @@ """Tests for long body in request.""" __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2022 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2022-2024 Tempesta Technologies, Inc." __license__ = "GPL2" import os @@ -126,9 +126,6 @@ def cleanup_file(self): if not remote.DEBUG_FILES: remote.client.run_cmd(f"rm {self.abs_path}") - def tearDown(self): - pass - def _test(self, client_id: str, header: str): """Send request with long body and check that Tempesta does not crash.""" self.start_all_services(client=False) diff --git a/t_stress/test_stress.py b/t_stress/test_stress.py index 8022e2f76..ea1ccda59 100644 --- a/t_stress/test_stress.py +++ b/t_stress/test_stress.py @@ -9,7 +9,7 @@ from helpers import dmesg, remote, sysnet, tf_cfg __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2022 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2022-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -147,9 +147,6 @@ def setUp(self): self.addCleanup(self.remove_large_page) self.addCleanup(super().tearDown) - def tearDown(self): - pass - def create_large_page(self): server = self.get_server("nginx-large-page") server.node.run_cmd(f"fallocate -l {self.nginx_backend_page_size} {self.large_page_path}") @@ -195,9 +192,6 @@ def cleanup_mtus(self): for args in self._prev_mtu.values(): sysnet.change_mtu(*args) - def tearDown(self): - pass - def set_mtu(self, node, destination_ip, mtu): if mtu: dev = sysnet.route_dst_ip(node=node, ip=destination_ip) @@ -587,9 +581,6 @@ def cleanup_test_file(self): if not remote.DEBUG_FILES: remote.client.run_cmd(f"rm {self.fullname}") - def tearDown(self): - pass - def _test_wrk(self, client_id: str, method: str): """ HTTP stress test generated by `wrk` with concurrent connections and large body in request. diff --git a/testers/stress.py b/testers/stress.py index 292c4209c..c24d41491 100644 --- a/testers/stress.py +++ b/testers/stress.py @@ -5,7 +5,7 @@ from helpers import control, dmesg, remote, stateful, tempesta, tf_cfg, util __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017-2018 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" @@ -113,9 +113,6 @@ def force_stop(self): if self.servers: control.servers_force_stop(self.servers) - def tearDown(self): - pass - def show_performance(self): if tf_cfg.v_level() < 2: return diff --git a/very_many_backends/multi_backend.py b/very_many_backends/multi_backend.py index 69ea7d0e1..25c178475 100644 --- a/very_many_backends/multi_backend.py +++ b/very_many_backends/multi_backend.py @@ -1,7 +1,7 @@ """ Test template """ __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017-2018 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" import os @@ -296,9 +296,6 @@ def configure_tempesta(self): self.tempesta.config.add_sg(server_group) sgid = sgid + 1 - def tearDown(self): - pass - def test(self): """Test 1M backends""" self.generic_test_routine(self.config) diff --git a/very_many_backends/test_deadtime_1M.py b/very_many_backends/test_deadtime_1M.py index d7392a5c5..f383ac1b8 100644 --- a/very_many_backends/test_deadtime_1M.py +++ b/very_many_backends/test_deadtime_1M.py @@ -1,5 +1,5 @@ __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" import asyncore @@ -165,9 +165,6 @@ def cleanup_check_client_error(self): if self.client.state == stateful.STATE_ERROR: raise Exception("Error while stopping client") - def tearDown(self): - pass - def configure_tempesta(self): """Configure tempesta 1 port in group""" sg = tempesta.ServerGroup("default") diff --git a/ws/test_ws_ping.py b/ws/test_ws_ping.py index a27f29405..10add97f4 100755 --- a/ws/test_ws_ping.py +++ b/ws/test_ws_ping.py @@ -14,7 +14,7 @@ from helpers import tf_cfg __author__ = "Tempesta Technologies, Inc." -__copyright__ = "Copyright (C) 2017-2023 Tempesta Technologies, Inc." +__copyright__ = "Copyright (C) 2017-2024 Tempesta Technologies, Inc." __license__ = "GPL2" GENERAL_WORKDIR = tf_cfg.cfg.get("General", "workdir") @@ -295,9 +295,6 @@ def setUp(self): self.addCleanup(self.cleanup_p1) self.addCleanup(self.cleanup_p2) - def tearDown(self): - pass - def cleanup_p1(self): if self.p1: self.p1.terminate() @@ -308,6 +305,7 @@ def cleanup_p2(self): self.p2.terminate() self.p2 = None + class WssPing(WsPing): """Ping test for websocket wss scheme.""" From 517567755cb77699d50a9e102751822fda8ac204 Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 19 Jan 2024 16:31:44 +0300 Subject: [PATCH 32/33] Removed useless addCleanup() calls Signed-off-by: Yaroslav Kargin --- reconf/reconf_stress.py | 2 +- very_many_backends/multi_backend.py | 2 -- very_many_backends/test_deadtime_1M.py | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/reconf/reconf_stress.py b/reconf/reconf_stress.py index 502e5b2db..bd6020702 100644 --- a/reconf/reconf_stress.py +++ b/reconf/reconf_stress.py @@ -19,7 +19,7 @@ class LiveReconfStress(stress.StressTest): auto_vhosts = True def setUp(self): - self.addCleanup(self.cleanup_parent_teardown) + super().setUp() self.addCleanup(self.cleanup_reconfig_thread) def cleanup_reconfig_thread(self): diff --git a/very_many_backends/multi_backend.py b/very_many_backends/multi_backend.py index 25c178475..dfab9014c 100644 --- a/very_many_backends/multi_backend.py +++ b/very_many_backends/multi_backend.py @@ -267,8 +267,6 @@ def setUp(self): self.create_servers() self.configure_tempesta() # Cleanup part - self.addCleanup(self.cleanup_interfaces) - self.addCleanup(self.cleanup_servers) self.addCleanup(self.cleanup_tempesta) def cleanup_interfaces(self): diff --git a/very_many_backends/test_deadtime_1M.py b/very_many_backends/test_deadtime_1M.py index f383ac1b8..2921fdf6c 100644 --- a/very_many_backends/test_deadtime_1M.py +++ b/very_many_backends/test_deadtime_1M.py @@ -146,10 +146,7 @@ def setUp(self): super().setUp() # Cleanup part self.addCleanup(self.cleanup_interfaces) - self.addCleanup(self.cleanup_servers) - self.addCleanup(self.cleanup_tempesta) self.addCleanup(self.cleanup_check_client_error) - self.addCleanup(self.cleanup_client) def cleanup_client(self): if self.client is not None: From c3eb1d9e82be5ced683a1c4a3bab263727fb416e Mon Sep 17 00:00:00 2001 From: Yaroslav Kargin Date: Fri, 19 Jan 2024 17:02:54 +0300 Subject: [PATCH 33/33] Removed redundant addCleanup calls for tearDown in tests Signed-off-by: Yaroslav Kargin --- flacky_net/test_sockets.py | 6 +----- framework/mixins.py | 1 - reconf/reconf_stress.py | 3 --- regression/test_reboot.py | 1 - t_frang/frang_test_case.py | 1 - t_http_rules/test_http_tables.py | 2 +- t_long_body/test_long_request.py | 1 - t_stress/test_stress.py | 3 --- 8 files changed, 2 insertions(+), 16 deletions(-) diff --git a/flacky_net/test_sockets.py b/flacky_net/test_sockets.py index 590696f21..ceed4efed 100644 --- a/flacky_net/test_sockets.py +++ b/flacky_net/test_sockets.py @@ -74,10 +74,9 @@ def check_sockets(self, allow_conns=True): self.check_after_stop() def setUp(self): - stress.StressTest.setUp(self) + super().setUp() self.filter = None # Cleanup part - self.addCleanup(self.cleanup_parent_teardown) self.addCleanup(self.cleanup_stop_tempesta) self.addCleanup(self.cleanup_filter) @@ -91,9 +90,6 @@ def cleanup_stop_tempesta(self): if self.tempesta: self.tempesta.stop() - def cleanup_parent_teardown(self): - stress.StressTest.tearDown(self) - def init_filter(self): node = self.servers[0].node self.filter = flacky.Filter(node) diff --git a/framework/mixins.py b/framework/mixins.py index a2b2dce89..2edb74978 100644 --- a/framework/mixins.py +++ b/framework/mixins.py @@ -13,7 +13,6 @@ def setUp(self): self.skipTest("This is an abstract class") self._nf_mark = None super().setUp() - self.addCleanup(super().tearDown) self.addCleanup(self.cleanup_del_nf_mark) def cleanup_del_nf_mark(self): diff --git a/reconf/reconf_stress.py b/reconf/reconf_stress.py index bd6020702..2d84385d2 100644 --- a/reconf/reconf_stress.py +++ b/reconf/reconf_stress.py @@ -28,9 +28,6 @@ def cleanup_reconfig_thread(self): if hasattr(self, "r_thread"): self.r_thread.join() - def cleanup_parent_teardown(self): - stress.StressTest.tearDown(self) - def create_servers(self): port = tempesta.upstream_port_start_from() rm_srv_n = tempesta.servers_in_group() / 3 diff --git a/regression/test_reboot.py b/regression/test_reboot.py index 2a07eb75c..5f5d7e910 100644 --- a/regression/test_reboot.py +++ b/regression/test_reboot.py @@ -27,7 +27,6 @@ class RebootUnderLoadTest(stress.StressTest): def setUp(self): super().setUp() - self.addCleanup(super().tearDown) self.addCleanup(self.cleanup_r_thread) def cleanup_r_thread(self): diff --git a/t_frang/frang_test_case.py b/t_frang/frang_test_case.py index e5ab5e726..a0d0b3987 100644 --- a/t_frang/frang_test_case.py +++ b/t_frang/frang_test_case.py @@ -69,7 +69,6 @@ def setUp(self): self.klog = dmesg.DmesgFinder(disable_ratelimit=True) self.assert_msg = "Expected nums of warnings in `journalctl`: {exp}, but got {got}" # Cleanup part - self.addCleanup(super().tearDown) self.addCleanup(self.cleanup_klog) def cleanup_klog(self): diff --git a/t_http_rules/test_http_tables.py b/t_http_rules/test_http_tables.py index 84db56cce..53c204113 100644 --- a/t_http_rules/test_http_tables.py +++ b/t_http_rules/test_http_tables.py @@ -255,8 +255,8 @@ def del_nf_mark(self, mark): def setUp(self): self.marked = None HttpTablesTest.setUp(self) + super().setUp() # Cleanup part - self.addCleanup(super().tearDown) self.addCleanup(self.cleanup_marked) def cleanup_marked(self): diff --git a/t_long_body/test_long_request.py b/t_long_body/test_long_request.py index 52c101406..f8fc87307 100644 --- a/t_long_body/test_long_request.py +++ b/t_long_body/test_long_request.py @@ -117,7 +117,6 @@ def setUp(self): # Cleanup part self.addCleanup(self.cleanup_file) self.addCleanup(self.cleanup_verbose) - self.addCleanup(super().tearDown) def cleanup_verbose(self): tf_cfg.cfg.set_option("General", "verbose", self.verbose) diff --git a/t_stress/test_stress.py b/t_stress/test_stress.py index ea1ccda59..d5477e7f5 100644 --- a/t_stress/test_stress.py +++ b/t_stress/test_stress.py @@ -145,7 +145,6 @@ def setUp(self): self.create_large_page() # Cleanup part self.addCleanup(self.remove_large_page) - self.addCleanup(super().tearDown) def create_large_page(self): server = self.get_server("nginx-large-page") @@ -184,7 +183,6 @@ def setUp(self): mtu=self.server_to_tempesta_mtu, ) # Cleanup part - self.addCleanup(super().tearDown) self.addCleanup(self.cleanup_mtus) def cleanup_mtus(self): @@ -575,7 +573,6 @@ def setUp(self): super().setUp() # Cleanup part self.addCleanup(self.cleanup_test_file) - self.addCleanup(super().tearDown) def cleanup_test_file(self): if not remote.DEBUG_FILES: