Skip to content

Commit

Permalink
Tests: sssd-be tends to run out of system resources, hitting the maxi…
Browse files Browse the repository at this point in the history
…mum number of open files

sssd-be tends to run out of system resources, hitting the maximum number of open files

Reviewed-by: Shridhar Gadekar <[email protected]>
Reviewed-by: Sumit Bose <[email protected]>
  • Loading branch information
aborah-sudo authored and jakub-vavra-cz committed Jul 11, 2023
1 parent 2487c99 commit fe99271
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/tests/multihost/alltests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
import time
import subprocess
import pytest
import textwrap
from sssd.testlib.common.expect import pexpect_ssh
from datetime import datetime as D_T
from sssd.testlib.common.exceptions import SSHLoginException
from sssd.testlib.common.ssh2_python import check_login_client
from sssd.testlib.common.utils import sssdTools, LdapOperations
from constants import ds_instance_name, ds_suffix, ds_rootdn, ds_rootpw
from sssd.testlib.common.ssh2_python import check_login_client
from sssd.testlib.common.helper_functions import count_pattern_logs, \
client_backup_file, client_restore_file, client_remove_file


def find_logs(multihost, log_name, string_name):
Expand Down Expand Up @@ -600,3 +603,51 @@ def test_bz822236(multihost, backupsssdconf):
ldap_inst.del_dn(f"ou=Netgroup,{ds_suffix}")
assert all(find_logs_results), "Searched string not found in the logs"
assert all(time_diff), "Test failed as the cache response time is higher."

@pytest.mark.tier1_2
def test_0017_filesldap(multihost):
"""
:title: sssd-be tends to run out of system resources,
hitting the maximum number of open files
:id: ad4a4a32-05d7-11ee-9caa-845cf3eff344
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2195919
:setup:
1. Replace /usr/libexec/sssd/krb5_child with a shell script like
#!/bin/bash
sleep 10
:steps:
1. Login with ldap user and count no of file descriptors before modifying krb5_child
2. Trigger authentication requests 'sssctl user-checks -a auth
3. Count no of file descriptors after modifying krb5_child
:expectedresults:
1. Login should success
2. Authentication requests will fail
3. No of file descriptors should be same as before and after modifying krb5_child
"""
client = multihost.client[0]
tools = sssdTools(multihost.client[0])
tools.clear_sssd_cache()
user = f'foo1@{ds_instance_name}'
check_login_client(multihost, user, "Secret123")
time.sleep(3)
client.run_command('ls -al /proc/$(pidof sssd_be)/fd > /tmp/before_count')
time.sleep(2)
n_log_bfr = count_pattern_logs(multihost, "/tmp/before_count", "pipe:")
client_backup_file(multihost, '/usr/libexec/sssd/krb5_child')
new_child = textwrap.dedent("""#!/bin/bash\nsleep 10 \n""")
client.put_file_contents('/usr/libexec/sssd/krb5_child', new_child)
for i in range(10):
client.run_command(f"echo 'Secret123'|sssctl user-checks -a auth foo{i}@{ds_instance_name}")
time.sleep(3)
client.run_command(f'ls -al /proc/$(pidof sssd_be)/fd > /tmp/after_count{i}')
time.sleep(2)
n_log_afr = []
for i in range(10):
n_log_afr.append(count_pattern_logs(multihost, f"/tmp/after_count{i}", "pipe:"))
client_restore_file(multihost, "/usr/libexec/sssd/krb5_child_bkp")
for f_file in ["/tmp/before_count", "/usr/libexec/sssd/krb5_child_bkp"]:
client_remove_file(multihost, f_file)
for i in range(10):
client_remove_file(multihost, f"/tmp/after_count{i}")
for n_n in n_log_afr:
assert n_log_bfr == n_n
67 changes: 67 additions & 0 deletions src/tests/multihost/sssd/testlib/common/helper_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import re


def find_logs(multihost, log_name, string_name):
"""This function will find strings in a log file
log_name: Absolute path of log where the search will happen.
string_name: String to search in the log file.
"""
log_str = multihost.client[0].get_file_contents(log_name).decode('utf-8')
assert string_name in log_str


def count_pattern_logs(multihost, log_name, string_name):
"""This function will find strings in a log file
log_name: Absolute path of log where the search will happen.
string_name: String to search in the log file.
"""
return len(re.findall(string_name, multihost.client[0].get_file_contents(log_name).decode('utf-8')))


def client_backup_file(multihost, file_path):
"""This function will backup file in client machine
file_path: String, Absolute path of file.
"""
client = multihost.client[0]
file_content = client.get_file_contents(file_path)
client.put_file_contents(file_path+'_bkp', file_content)


def client_restore_file(multihost, file_path):
"""This function will restore file in client machine
file_path: String, Absolute path of file.
"""
client = multihost.client[0]
file_content = client.get_file_contents(file_path)
client.put_file_contents(file_path.split("_bkp")[0], file_content)


def client_remove_file(multihost, file_path):
"""This function will remove file in client machine
file_path: String, Absolute path of file.
"""
client = multihost.client[0]
client.run_command(f"rm -vf {file_path}")


def count_lines(multihost, log_name):
"""This function will count no of lines of a file
file_path: String, Absolute path of file.
"""
return len(multihost.client[0].get_file_contents(log_name).decode('utf-8').split('\n')) - 1


def search_string_in_file(multihost, start_line, search_string, file_path):
"""This function will find strings in a log file
file_path: String, Absolute path of file.
search_string: String, to find in the log.
start_line: int, number of line from where search will start
"""
file = multihost.client[0].get_file_contents(file_path).decode('utf-8').split('\n')
current_line = 1
finding_list = []
for line in file:
if current_line >= start_line and search_string in line:
finding_list.append(f"Found '{search_string}' in {file_path} at line {current_line}: {line.strip()}")
current_line += 1
return finding_list

0 comments on commit fe99271

Please sign in to comment.