From 39ecf47a3387429bb59f675c62a9245975900566 Mon Sep 17 00:00:00 2001 From: Kaushik Banerjee Date: Mon, 2 Sep 2024 19:16:09 +0530 Subject: [PATCH] Tests: Move journald rate disable to common/fixtures.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disabling journald rate limit was limited to alltests/conftest.py Moving it to common/fixtures.py will cover all the tests. Signed-off-by: Kaushik Banerjee Reviewed-by: Jakub Vávra --- src/tests/multihost/alltests/conftest.py | 36 ------------------- .../multihost/sssd/testlib/common/fixtures.py | 34 ++++++++++++++++++ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/tests/multihost/alltests/conftest.py b/src/tests/multihost/alltests/conftest.py index 230f0ac99b0..1182a9ca9a0 100644 --- a/src/tests/multihost/alltests/conftest.py +++ b/src/tests/multihost/alltests/conftest.py @@ -1574,42 +1574,6 @@ def restoresssdconf(): # ==================== Session Scoped Fixtures ================ -@pytest.fixture(scope='session', autouse=True) -def update_journald_conf(session_multihost, request): - """ - Update journald.conf - To turn off any kind of rate limiting, set RateLimitIntervalSec value to 0. - """ - cmd = session_multihost.client[0].run_command( - 'test -f /etc/systemd/journald.conf', raiseonerr=False) - if cmd.returncode == 0: - j_config = '/etc/systemd/journald.conf' - else: - j_config = '/usr/lib/systemd/journald.conf' - - bkup_cmd = f'cp -f {j_config} /tmp/journald.conf.bkup' - session_multihost.client[0].run_command(bkup_cmd, raiseonerr=False) - up_ratelimit = 'RateLimitIntervalSec=0' - journald_conf = session_multihost.client[0].get_file_contents( - j_config) - if isinstance(journald_conf, bytes): - contents = journald_conf.decode('utf-8') - else: - contents = journald_conf - contents = contents.replace(up_ratelimit, '') + up_ratelimit - session_multihost.client[0].put_file_contents(j_config, contents) - session_multihost.client[0].run_command( - "systemctl daemon-reload", raiseonerr=False) - session_multihost.client[0].run_command( - "systemctl restart systemd-journald", raiseonerr=False) - - def restore_journalsssd(): - """ Restore journalsssd.conf """ - bkup_cmd = f'cp -f /tmp/journald.conf.bkup {j_config}' - session_multihost.client[0].run_command(bkup_cmd) - request.addfinalizer(restore_journalsssd) - - @pytest.fixture(scope="session", autouse=True) # pylint: disable=unused-argument def setup_session(session_multihost, request, create_testdir): diff --git a/src/tests/multihost/sssd/testlib/common/fixtures.py b/src/tests/multihost/sssd/testlib/common/fixtures.py index 68645dc21d5..6b1cab2d560 100644 --- a/src/tests/multihost/sssd/testlib/common/fixtures.py +++ b/src/tests/multihost/sssd/testlib/common/fixtures.py @@ -109,3 +109,37 @@ def remove_test_dir(): machine.run_command(ad_rm_config_cmd) request.addfinalizer(remove_test_dir) + + +@pytest.fixture(scope='session', autouse=True) +def disable_journald_rate_limit(session_multihost, request): + """ + Update journald.conf + To turn off any kind of rate limiting, set RateLimitIntervalSec value to 0. + """ + cmd = session_multihost.client[0].run_command( + 'test -f /etc/systemd/journald.conf', raiseonerr=False) + if cmd.returncode == 0: + j_config = '/etc/systemd/journald.conf' + else: + j_config = '/usr/lib/systemd/journald.conf' + + bkup_cmd = f'cp -Zpf {j_config} /tmp/journald.conf.bkup' + session_multihost.client[0].run_command(bkup_cmd, raiseonerr=False) + up_ratelimit = 'RateLimitIntervalSec=0' + journald_conf = session_multihost.client[0].get_file_contents( + j_config) + if isinstance(journald_conf, bytes): + contents = journald_conf.decode('utf-8') + else: + contents = journald_conf + contents = contents.replace(up_ratelimit, '') + up_ratelimit + session_multihost.client[0].put_file_contents(j_config, contents) + session_multihost.client[0].run_command( + "systemctl restart systemd-journald", raiseonerr=False) + + def restore_journalsssd(): + """ Restore journalsssd.conf """ + bkup_cmd = f'cp -Zpf /tmp/journald.conf.bkup {j_config}' + session_multihost.client[0].run_command(bkup_cmd) + request.addfinalizer(restore_journalsssd)