Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using addCleanup() instead of TearDown(). #562

Merged
merged 33 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4978a16
test_ws_ping: Replace tearDown() with addCleanup() for process termin…
ykargin Dec 27, 2023
9b2edba
tester.py: Replace tearDown() with addCleanup().
ykargin Dec 27, 2023
6eb176b
test_headercollection.py: Replace tearDown() with addCleanup().
ykargin Dec 27, 2023
69032af
stress.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
0bd7b25
test_x509.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
a375f4b
A small typo correction
ykargin Dec 28, 2023
54fa591
reconf_stress.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
6e954ad
test_sockets.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
f27dd9a
mixins.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
b1ccebe
test_reboot.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
4c592e0
test_shutdown.py: Replace tearDown() with addCleanup().
ykargin Dec 28, 2023
c19d450
test_deproxy.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
1fc9d45
test_deproxy_message.py:
ykargin Jan 2, 2024
f893c92
test_requests.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
b9b6fb7
test_responses.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
5170e5a
frang_test_case.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
5ca351e
test_http_tables.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
ffd472c
test_long_request.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
c78b52a
test_stress.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
65db7d6
functional.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
e4684e6
multi_backend.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
3c0d840
test_deadtime_1M.py: Replace tearDown() with addCleanup().
ykargin Jan 2, 2024
06b7d77
Apply Black code formatter
ykargin Jan 8, 2024
cbcdc09
Removed outdated comment
ykargin Jan 14, 2024
31ad983
Revert "test_deproxy.py: Replace tearDown() with addCleanup()."
ykargin Jan 14, 2024
3b1474f
Revert "test_shutdown.py: Replace tearDown() with addCleanup()."
ykargin Jan 14, 2024
8901750
Revert "functional.py: Replace tearDown() with addCleanup()."
ykargin Jan 14, 2024
d371ce0
Fix: AttributeError: 'FrangHostRequiredH2TestCase' object has no
ykargin Jan 17, 2024
7ae7c73
Fix error reporting for test_http_tables.py
ykargin Jan 17, 2024
8fb0952
Fix: cleanup
ykargin Jan 17, 2024
f8aa55a
Cleanup: removed empty tearDowns
ykargin Jan 17, 2024
5175677
Removed useless addCleanup() calls
ykargin Jan 19, 2024
c3eb1d9
Removed redundant addCleanup calls for tearDown in tests
ykargin Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions flacky_net/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -75,18 +74,21 @@ 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_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 init_filter(self):
node = self.servers[0].node
Expand Down
10 changes: 5 additions & 5 deletions framework/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def setUp(self):
self.skipTest("This is an abstract class")
self._nf_mark = None
super().setUp()
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
Expand All @@ -25,8 +30,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):
super().tearDown()
if self._nf_mark:
self.del_nf_mark(self._nf_mark)
38 changes: 24 additions & 14 deletions framework/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -333,33 +333,48 @@ 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()
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"
)
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(
Expand All @@ -377,15 +392,10 @@ 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 wait_while_busy(self, *items, timeout=20):
if items is None:
Expand Down
22 changes: 12 additions & 10 deletions reconf/reconf_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@
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

def setUp(self):
super().setUp()
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 create_servers(self):
port = tempesta.upstream_port_start_from()
rm_srv_n = tempesta.servers_in_group() / 3
Expand Down Expand Up @@ -77,7 +86,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()
Expand All @@ -93,13 +102,6 @@ def stress_reconfig_generic(self, configure_func, reconfigure_func):
self.r_thread.join()
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)

def configure_srvs_start(self):
srvs = self.const_srvs + self.rm_srvs
config = self.make_config(self.sg_name, srvs)
Expand Down
15 changes: 9 additions & 6 deletions regression/test_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand All @@ -25,6 +25,14 @@ class RebootUnderLoadTest(stress.StressTest):
# Timeout before first reboot.
warm_timeout = 0

def setUp(self):
super().setUp()
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="")
Expand Down Expand Up @@ -56,11 +64,6 @@ def reboot_routine(self, config):
control.client_run_blocking(self.wrk)
self.show_performance()

def tearDown(self):
if hasattr(self, "r_thread"):
self.r_thread.join()
stress.StressTest.tearDown(self)

def test_proxy(self):
config = "cache 0;\n"
self.reboot_routine(config)
Expand Down
6 changes: 4 additions & 2 deletions selftests/test_deproxy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
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 test_incomplite(self):
Expand Down Expand Up @@ -78,7 +80,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)
Expand Down
6 changes: 4 additions & 2 deletions selftests/test_headercollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
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"


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)
ykargin marked this conversation as resolved.
Show resolved Hide resolved

def tearDown(self):
def clenup_header_collection(self):
deproxy.HeaderCollection._disable_report_wrong_is_expected = False
self.headers = None

def test_length(self):
self.assertEqual(len(self.headers), 0)
Expand Down
6 changes: 4 additions & 2 deletions selftests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand All @@ -15,8 +15,10 @@ 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 test_equal(self):
Expand Down
6 changes: 4 additions & 2 deletions selftests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand All @@ -20,8 +20,10 @@ 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 test_equal(self):
Expand Down
8 changes: 3 additions & 5 deletions selftests/test_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand All @@ -19,10 +19,8 @@ def cert_text(self) -> str:

def setUp(self):
self.cgen = CertGenerator()
self.remove_certs()

def tearDown(self):
self.remove_certs()
self.remove_certs() # initial certs cleanup before testing
self.addCleanup(self.remove_certs)

def remove_certs(self):
for path in self.cgen.get_file_paths():
Expand Down
10 changes: 6 additions & 4 deletions t_frang/frang_test_case.py
Original file line number Diff line number Diff line change
@@ -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"


Expand Down Expand Up @@ -68,10 +68,12 @@ 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(self.cleanup_klog)

def tearDown(self):
super().tearDown()
del self.klog
def cleanup_klog(self):
if hasattr(self, "klog"):
del self.klog

# TODO: rename to set_frang_cfg_and_start
def set_frang_config(self, frang_config: str):
Expand Down
Loading