Skip to content

Commit

Permalink
Tests: Disable journald rate limiting during alltests pytest session
Browse files Browse the repository at this point in the history
Logging was paused as the journald rate limit was reached.
Disable rate limiting during the alltests pytest session.

Signed-off-by: Kaushik Banerjee <[email protected]>

Reviewed-by: Anuj Borah <[email protected]>
  • Loading branch information
kaushikub authored and jakub-vavra-cz committed Sep 2, 2024
1 parent 0f351c2 commit 7067b57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
74 changes: 38 additions & 36 deletions src/tests/multihost/alltests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,42 +1205,6 @@ def remove_journalsssd():
request.addfinalizer(remove_journalsssd)


@pytest.fixture(scope='class')
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="class")
def enable_autofs_schema(session_multihost, request):
""" Enable autofs schema(rfc2307) to Windows AD.
Expand Down Expand Up @@ -1608,6 +1572,44 @@ def restoresssdconf():
request.addfinalizer(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
2 changes: 1 addition & 1 deletion src/tests/multihost/alltests/test_journald.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@pytest.mark.usefixtures('setup_sssd', 'create_posix_usersgroups',
'update_journald_conf', 'write_journalsssd')
'write_journalsssd')
@pytest.mark.journald
class TestJournald(object):
"""
Expand Down

0 comments on commit 7067b57

Please sign in to comment.