Skip to content

Commit

Permalink
Tests: Move journald rate disable to common/fixtures.py
Browse files Browse the repository at this point in the history
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 <[email protected]>

Reviewed-by: Jakub Vávra <[email protected]>
(cherry picked from commit 39ecf47)
  • Loading branch information
kaushikub authored and jakub-vavra-cz committed Sep 3, 2024
1 parent 11db501 commit b8f2b33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
36 changes: 0 additions & 36 deletions src/tests/multihost/alltests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,42 +1572,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):
Expand Down
34 changes: 34 additions & 0 deletions src/tests/multihost/sssd/testlib/common/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b8f2b33

Please sign in to comment.