diff --git a/src/tests/multihost/alltests/test_default_debug_level.py b/src/tests/multihost/alltests/test_default_debug_level.py index 616d67c4477..ede9f205f14 100644 --- a/src/tests/multihost/alltests/test_default_debug_level.py +++ b/src/tests/multihost/alltests/test_default_debug_level.py @@ -20,6 +20,7 @@ @pytest.mark.defaultdebuglevel class TestDefaultDebugLevel(object): """ Check sssd default debug level """ + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__check') @pytest.mark.tier1_4 def test_0001_check_default_debug_level(self, multihost, backupsssdconf): """ @@ -62,6 +63,7 @@ def test_0001_check_default_debug_level(self, multihost, backupsssdconf): debug_str1 = pattern2.search(log_single_line) assert debug_str1.group() == '(0x3f7c0)' + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__check_with_login') @pytest.mark.tier1_4 def test_0002_check_default_level_with_auth(self, multihost, backupsssdconf): @@ -109,6 +111,7 @@ def test_0002_check_default_level_with_auth(self, multihost, assert ssh, f'{user} is not able to login' assert alog_size.stdout_text == blog_size.stdout_text + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__fatal_and_critical_failures') @pytest.mark.tier2 def test_0003_bz1893159(self, multihost, backupsssdconf): """ @@ -149,6 +152,7 @@ def test_0003_bz1893159(self, multihost, backupsssdconf): if not find1.search(log_str) and not find2.search(log_str): assert False + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__cannot_load_sssd_config') @pytest.mark.tier1_4 def test_0004_bz1893159(self, multihost, backupsssdconf): """ @@ -177,6 +181,7 @@ def test_0004_bz1893159(self, multihost, backupsssdconf): pattern = re.compile(r'SSSD couldn\'t load the configuration database') assert pattern.search(log_str) + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__nonexisting_ldap_server') @pytest.mark.tier1_4 def test_bz1893159(self, multihost, backupsssdconf): """ @@ -204,6 +209,7 @@ def test_bz1893159(self, multihost, backupsssdconf): #check what is logged at default debug_level(2) assert find.search(log_str) + @pytest.mark.converted('test_default_debug_level.py', 'test_default_debug_level__sbus') @pytest.mark.tier1_4 def test_0005_bz1915319(self, multihost, backupsssdconf): """ diff --git a/src/tests/system/tests/test_default_debug_level.py b/src/tests/system/tests/test_default_debug_level.py new file mode 100644 index 00000000000..6beffaf3396 --- /dev/null +++ b/src/tests/system/tests/test_default_debug_level.py @@ -0,0 +1,181 @@ +""" +Automation for default debug level + +:requirement: SSSD - Default debug level +""" + +from __future__ import annotations +import time + +import pytest +from pytest_mh.ssh import SSHProcessError +from sssd_test_framework.roles.client import Client +from sssd_test_framework.roles.generic import GenericProvider +from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup + + +@pytest.mark.topology(KnownTopology.Client) +def test_default_debug_level__check(client: Client): + """ + :title: Check default debug level when sssd started successfully + :setup: + 1. Clear logs and cache + 2. Start SSSD with default debug level + :steps: + 1. Check log files + :expectedresults: + 1. "Starting with debug level = 0x0070" is in each file and + if log contains more than one line, log message with number "0x3f7c0" is stored + :customerscenario: False + """ + client.sssd.common.local() + client.sssd.default_domain = "local" + + client.sssd.clear(db=True, memcache=True, logs=True, config=False) + client.sssd.start(debug_level=None) + + for filename in ["sssd", "sssd_local", "sssd_nss", "sssd_pam"]: + log_str = client.fs.read(f"/var/log/sssd/{filename}.log") + assert "Starting with debug level = 0x0070" in log_str, f"Log file has wrong format: {log_str}" + + if len(log_str.split("\n")) > 1: + assert "(0x3f7c0)" in log_str, f"Log file has wrong format: {log_str}" + + +@pytest.mark.topology(KnownTopologyGroup.AnyProvider) +def test_default_debug_level__check_with_login(client: Client, provider: GenericProvider): + """ + :title: Successful login with default debug level doesn't generate any logs + :setup: + 1. Add user to SSSD, set its password + 2. Add fallback_homedir (generates extra logs on + user auth if not specified) + 3. Clear cache and logs + :steps: + 1. Start SSSD with default debug level + 2. Check total log size before user authentication + 3. Authenticate with user + 4. Check total log size after authentication + :expectedresults: + 1. SSSD started successfully + 2. Checked correctly + 3. User is authenticated + 4. Log sizes before and after are the same + :customerscenario: False + """ + + def log_length() -> int: + try: + output = client.fs.wc("/var/log/sssd/*", lines=True).stdout + return int(output.split()[0]) + except SSHProcessError: + return 0 + + provider.user("user1").add(password="Secret123") + client.sssd.common.local() + client.sssd.default_domain = "local" + client.sssd.domain["fallback_homedir"] = "/home/%%u" + + client.sssd.clear(db=True, memcache=True, logs=True, config=False) + client.sssd.start(debug_level=None) + + start_log_length = log_length() + assert client.auth.ssh.password("user1", "Secret123"), "Authentication failed" + assert start_log_length == log_length(), "Debug messages were generated" + + +@pytest.mark.ticket(bz=1893159) +@pytest.mark.topology(KnownTopology.Client) +def test_default_debug_level__fatal_and_critical_failures(client: Client): + """ + :title: Check that messages with levels 0 and 1 are logged for fatal or critical failures + :setup: + 1. Start SSSD with default debug level (config file is created) + 2. Restrict sssd.conf permissions + :steps: + 1. Restart sssd + 2. Check logs + :expectedresults: + 1. SSSD failed to start + 2. Fatal failures (level 0) and Critical failures (level 1) are in log file + :customerscenario: True + """ + client.sssd.common.local() + client.sssd.default_domain = "local" + client.sssd.start(debug_level=None) + client.fs.chmod(mode="444", path="/etc/sssd/sssd.conf") + + assert ( + client.sssd.restart(debug_level=None, raise_on_error=False, apply_config=False).rc != 0 + ), "SSSD started successfully, which is not expected" + + log_str = client.fs.read("/var/log/sssd/sssd.log") + assert "0x0010" in log_str, "Fatal failures were not found in log" + assert "0x0020" in log_str, "Critical failures were not found in log" + + +@pytest.mark.ticket(bz=1893159) +@pytest.mark.topology(KnownTopology.Client) +def test_default_debug_level__cannot_load_sssd_config(client: Client): + """ + :title: Check that messages with level 2 are logged when SSSD can't load config + :setup: + 1. Set 'domains' to 'non_existing_domain' in sssd section + :steps: + 1. Try to start SSSD with default debug level + 2. Check logs + :expectedresults: + 1. SSSD failed to start + 2. Correct error message is in log file + :customerscenario: True + """ + client.sssd.sssd["domains"] = "non_existing_domain" + assert ( + client.sssd.start(debug_level=None, raise_on_error=False).rc != 0 + ), "SSSD started successfully, which is not expected" + assert "SSSD couldn't load the configuration database" in client.fs.read("/var/log/sssd/sssd.log") + + +@pytest.mark.ticket(bz=1893159) +@pytest.mark.topology(KnownTopology.LDAP) +def test_default_debug_level__nonexisting_ldap_server(client: Client): + """ + :title: Check that messages with level 2 are logged when LDAP server doesn't exist + :setup: + 1. Start sssd with default debug level + 2. Set ldap_uri to a non-existing ldap-server + :steps: + 1. Check logs + :expectedresults: + 1. Domain Logs should contain a log related to 'going offline' + :customerscenario: True + """ + client.sssd.domain["ldap_uri"] = "ldap://typo" + client.sssd.start(debug_level=None, raise_on_error=False) + time.sleep(1) + assert "Failed to connect, going offline" in client.fs.read( + f"/var/log/sssd/sssd_{client.sssd.default_domain}.log" + ), "Searched string was not found in logs" + + +@pytest.mark.ticket(bz=1915319) +@pytest.mark.topology(KnownTopology.Client) +def test_default_debug_level__sbus(client: Client): + """ + :title: SBUS doesn't trigger failure message at modules startup + :setup: + 1. Start sssd with default debug level + :steps: + 1. Check logs + :expectedresults: + 1. "Unable to remove key" is not in the logs + :customerscenario: True + """ + client.sssd.common.local() + client.sssd.default_domain = "local" + client.sssd.start(debug_level=None) + + for log_filename in ["sssd", "sssd_local", "sssd_nss", "sssd_pam"]: + assert "Unable to remove key" not in client.fs.read( + f"/var/log/sssd/{log_filename}.log" + ), f"'Unable to remove key' was found in file: {log_filename}.log"