-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: converted alltests/test_default_debug_level
- Loading branch information
Showing
2 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
""" | ||
Automation for default debug level | ||
:requirement: SSSD - Default debug level | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
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) | ||
:steps: | ||
1. Restrict sssd.conf permissions | ||
2. Restart sssd | ||
3. Check logs | ||
:expectedresults: | ||
1. Permissions changed successfully | ||
2. SSSD failed to start | ||
3. 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) | ||
|
||
assert client.fs.chmod(mode="444", path="/etc/sssd/sssd.conf").rc == 0, "chmod call failed" | ||
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. 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) | ||
|
||
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") |