Skip to content

Commit

Permalink
Tests: alltests/test_offline.py converted
Browse files Browse the repository at this point in the history
  • Loading branch information
patriki01 committed Oct 25, 2023
1 parent 6814b27 commit 693edcb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/tests/multihost/alltests/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestOffline(object):
"""
This is test case class for ldap offline suite
"""
@pytest.mark.converted('test_offline.py', 'test_offline__log_to_syslog')
@pytest.mark.tier1
def test_0001_bz1416150(self, multihost, backupsssdconf):
"""
Expand Down Expand Up @@ -58,6 +59,7 @@ def test_0001_bz1416150(self, multihost, backupsssdconf):
else:
pytest.fail("Failed to start sssd")

@pytest.mark.converted('test_offline.py', 'test_offline__timeout_setting_in_logs')
@pytest.mark.tier1_2
def test_0002_bz1928648(self, multihost, backupsssdconf):
"""
Expand Down Expand Up @@ -102,11 +104,15 @@ def test_0002_bz1928648(self, multihost, backupsssdconf):
assert block_ip.returncode == 0
user = 'foo1@example1'
time.sleep(5)
with pytest.raises(Exception):
check_login_client(multihost, user, 'Secret123')
multihost.client[0].run_command(f"iptables "
f"-D OUTPUT -d "
f"{hostname} -j DROP")
try:
with pytest.raises(Exception):
check_login_client(multihost, user, 'Secret123')
except(Exception) as e:
pytest.fail(e)
finally:
multihost.client[0].run_command(f"iptables "
f"-D OUTPUT -d "
f"{hostname} -j DROP")
it_cat = "cat /var/log/sssd/sssd_example1.log"
cat_read = multihost.client[0].run_command(it_cat)
for i in ['ldap_opt_timeout',
Expand Down
96 changes: 96 additions & 0 deletions src/tests/system/tests/test_offline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Automation of offline tests
:requirement: offline
"""

from __future__ import annotations

import time

import pytest
from sssd_test_framework.roles.client import Client
from sssd_test_framework.roles.ldap import LDAP
from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup


@pytest.mark.ticket(bz=1416150)
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_offline__log_to_syslog(client: Client):
"""
:title: Log to syslog when sssd cannot contact servers goes offline
:setup:
1. Set sssd.conf properly
2. Start SSSD
:steps:
1. Check domain status for default domain
2. Save date and restart SSSD
3. Check journalctl
:expectedresults:
1. Domain is offline
2. Succeed
3. "Backend is offline" found
:customerscenario: True
"""
client.sssd.domain["ldap_uri"] = f"ldaps://typo.{client.host.hostname}"
client.sssd.domain["ldap_sudo_random_offset"] = "0"
client.sssd.start()

status = client.sssctl.domain_status(client.sssd.default_domain)
assert status.rc == 0, "sssctl domain-status failed"
assert "Offline" in status.stdout, "'Offline' not found in command output"

date = client.host.ssh.run("date --rfc-3339=s")
client.sssd.restart()

i = 0
while i < 80:
time.sleep(1)
# We shorten date output to get correct format
# "2023-10-23 15:01:36+02:00" => "2023-10-23 15:01:36"
log = client.tools.journalctl(unit="sssd", since=date.stdout[0:19])
if "Backend is offline" in log.stdout:
break
i += 1
assert "Backend is offline" in log.stdout, "'Backend is offline' is not logged after 80 attempts"


@pytest.mark.ticket(bz=1928648)
@pytest.mark.topology(KnownTopology.LDAP)
def test_offline__timeout_setting_in_logs(client: Client, ldap: LDAP):
"""
:title: Each timeout setting is properly logged in logs
:setup:
1. Add user
2. Start SSSD
:steps:
1. Check logs
2. Fetch information about user
3. Block LDAP traffic
4. Connect user over SSH
5. Check logs
:expectedresults:
1. Timeout setting is stored in logs
2. User is found
3. LDAP traffic is blocked
4. User is unable to connect
5. Each timeout setting is stored in logs
:customerscenario: True
"""
ldap.user("user1").add(password="Secret123")
client.sssd.start()

log = client.fs.read(f"/var/log/sssd/sssd_{client.sssd.default_domain}.log")
assert "Setting 6 seconds timeout" in log
assert "ldap_network_timeout" in log

assert client.tools.id("user1") is not None

ldap.firewall.drop(389)

with pytest.raises(Exception):
client.ssh("user1", "Secret123").connect()

log = client.fs.read(f"/var/log/sssd/sssd_{client.sssd.default_domain}.log")
for timeout in ["ldap_opt_timeout", "ldap_search_timeout", "ldap_network_timeout", "dns_resolver_timeout"]:
assert timeout in log, f"Value '{timeout}' not found in logs"

0 comments on commit 693edcb

Please sign in to comment.