Skip to content

Commit

Permalink
tests: housekeeping - test_cache.py
Browse files Browse the repository at this point in the history
housekeeping, the following is looked at and may have been done:

* fixed typos and standardized formatting
* renamed test cases to improve the clarity of what the test does
* improved docstring language, setup, steps and expected results
* synced code with the docstring order
* removed necessary configuration relevant to the test
* added pytest.mark.importance to test cases

noteable changes:

* created test_tools.py to move sss_cache test to
* renamed test_sss_cache.py to test_cache.py
* renamed test_memory_cache.py to test_memcache.py
  • Loading branch information
Dan Lavu committed Jul 18, 2024
1 parent e89d198 commit 3634a2c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 53 deletions.
101 changes: 48 additions & 53 deletions src/tests/multihost/alltests/test_sssctl_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:upstream: yes
:status: approved
"""

from __future__ import print_function
import pytest
from sssd.testlib.common.utils import sssdTools
Expand All @@ -17,17 +18,17 @@ def client_version(multihost):
return True


@pytest.mark.usefixtures('default_sssd')
@pytest.mark.usefixtures("default_sssd")
@pytest.mark.sssctl
class Testsssctl(object):
"""
This is test case class for sssctl suite
"""
@pytest.mark.converted("test_tools.py", "test_tools__sss_cache_expired_does_not_print_unrelated_message")
@pytest.mark.converted(
"test_sssctl.py", "test_sssctl__user_show_cache_expiration_time"
)
@pytest.mark.tier1_2
def test_0001_bz1640576(self, multihost,
backupsssdconf,
localusers):
def test_0001_bz1640576(self, multihost, backupsssdconf, localusers):
"""
:title: IDM-SSSD-TC: sssctl: sssctl reports incorrect
information about local user's cache entry expiration time
Expand All @@ -37,27 +38,22 @@ def test_0001_bz1640576(self, multihost,
pytest.skip("Files Provider support isn't available, skipping")
users = localusers
tools = sssdTools(multihost.client[0])
multihost.client[0].service_sssd('stop')
tools.remove_sss_cache('/var/lib/sss/db')
tools.remove_sss_cache('/var/log/sssd')
sssd_param = {'domains': 'local'}
tools.sssd_conf('sssd', sssd_param)
param = {'id_provider': 'files',
'passwd_files': '/etc/passwd'}
tools.sssd_conf('domain/local', param)
multihost.client[0].service_sssd('start')
multihost.client[0].service_sssd("stop")
tools.remove_sss_cache("/var/lib/sss/db")
tools.remove_sss_cache("/var/log/sssd")
sssd_param = {"domains": "local"}
tools.sssd_conf("sssd", sssd_param)
param = {"id_provider": "files", "passwd_files": "/etc/passwd"}
tools.sssd_conf("domain/local", param)
multihost.client[0].service_sssd("start")
for user in users.keys():
sssctl_cmd = 'sssctl user-show %s' % user
cmd = multihost.client[0].run_command(sssctl_cmd,
raiseonerr=False)
assert 'Cache entry expiration time: Never'\
in cmd.stdout_text
sssctl_cmd = "sssctl user-show %s" % user
cmd = multihost.client[0].run_command(sssctl_cmd, raiseonerr=False)
assert "Cache entry expiration time: Never" in cmd.stdout_text

@pytest.mark.converted('test_sssctl.py', 'test_sssctl__handle_implicit_domain')
@pytest.mark.converted("test_sssctl.py", "test_sssctl__handle_implicit_domain")
@pytest.mark.tier1_2
def test_0002_bz1599207(self, multihost,
backupsssdconf,
localusers):
def test_0002_bz1599207(self, multihost, backupsssdconf, localusers):
"""
:title: IDM-SSSD-TC: sssctl: sssd tools do not handle the implicit
domain
Expand All @@ -67,28 +63,27 @@ def test_0002_bz1599207(self, multihost,
pytest.skip("Files Provider support isn't available, skipping")
users = localusers
tools = sssdTools(multihost.client[0])
multihost.client[0].service_sssd('stop')
tools.remove_sss_cache('/var/lib/sss/db')
tools.remove_sss_cache('/var/log/sssd')
tools.sssd_conf("sssd",
{'enable_files_domain': 'true'},
action='update')
multihost.client[0].service_sssd('start')
multihost.client[0].service_sssd("stop")
tools.remove_sss_cache("/var/lib/sss/db")
tools.remove_sss_cache("/var/log/sssd")
tools.sssd_conf("sssd", {"enable_files_domain": "true"}, action="update")
multihost.client[0].service_sssd("start")
for user in users.keys():
cmd = multihost.client[0].run_command('getent'
' -s sss'
' passwd %s '
'&& sssctl '
'user-show %s' %
(user, user),
raiseonerr=False)
assert 'Cache entry creation date' in \
cmd.stdout_text and cmd.returncode == 0
cmd = multihost.client[0].run_command(
"getent"
" -s sss"
" passwd %s "
"&& sssctl "
"user-show %s" % (user, user),
raiseonerr=False,
)
assert (
"Cache entry creation date" in cmd.stdout_text and cmd.returncode == 0
)

@pytest.mark.converted('test_cache.py', 'test_sss_cache__cache_expire_message')
@pytest.mark.converted("test_cache.py", "test_sss_cache__cache_expire_message")
@pytest.mark.tier1_2
def test_0003_bz1661182(self, multihost,
backupsssdconf):
def test_0003_bz1661182(self, multihost, backupsssdconf):
"""
:title: sss_cache prints spurious error messages
when invoked from shadow-utils on package install
Expand All @@ -111,24 +106,24 @@ def test_0003_bz1661182(self, multihost,
if not multihost.client[0].detect_files_provider():
pytest.skip("Files Provider support isn't available, skipping")
tools = sssdTools(multihost.client[0])
ldap_params = {'enable_files_domain': 'false'}
tools.sssd_conf('sssd', ldap_params)
ldap_params = {"enable_files_domain": "false"}
tools.sssd_conf("sssd", ldap_params)
with pytest.raises(SSSDException):
multihost.client[0].service_sssd('restart')
multihost.client[0].service_sssd("restart")
ps_cmd = "> /var/log/sssd/sssd.log"
multihost.client[0].run_command(ps_cmd)
ps_cmd = "useradd user1_test"
multihost.client[0].run_command(ps_cmd, raiseonerr=False)
ps_cmd = "usermod -a -G wheel user1_test"
cmd = multihost.client[0].run_command(ps_cmd)
assert 'No domains configured, fatal error!' \
not in cmd.stdout_text
assert "No domains configured, fatal error!" not in cmd.stdout_text
ps_cmd = "userdel user1_test"
multihost.client[0].run_command(ps_cmd)
for ps_cmd in ('sss_cache -U',
'sss_cache -G',
'sss_cache -E',
'sss_cache -u non-existinguser'):
for ps_cmd in (
"sss_cache -U",
"sss_cache -G",
"sss_cache -E",
"sss_cache -u non-existinguser",
):
cmd = multihost.client[0].run_command(ps_cmd)
assert 'No domains configured, fatal error!' \
not in cmd.stdout_text
assert "No domains configured, fatal error!" not in cmd.stdout_text
13 changes: 13 additions & 0 deletions src/tests/system/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_del
1. Login as users
2. Modify 'user-modify' shell and delete 'user-delete' and clear cache
3. Login as users
<<<<<<< HEAD
4. Lookup user 'user-delete'
5. Lookup user 'user-modify'
:expectedresults:
Expand All @@ -172,6 +173,14 @@ def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_del
3. User 'user-modify' logged in
4. User 'user-delete' is not found
5. User 'user-modify' is found and shell was updated
=======
4. Lookup user 'user-modify'
:expectedresults:
1. Users logged in
2. User is modified and user is deleted
3. User 'user-modify' logged in
4. User's shell was updated
>>>>>>> 6ed7dd4a4 (tests: housekeeping - test_cache.py)
:customerscenario: False
"""
provider.user("user-modify").add(shell="/bin/bash")
Expand All @@ -191,6 +200,10 @@ def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_del
assert client.auth.ssh.password("user-modify", "Secret123"), "Login failed!"
assert not client.auth.ssh.password("user-delete", "Secret123"), "Login successful!"

<<<<<<< HEAD
result = client.tools.getent.passwd("user-modify")
assert result is not None, "User not found!"
assert result.shell == "/bin/sh", "User shell did not update!"
=======
assert client.tools.getent.passwd("user-modify").shell == "/bin/sh", "User shell did not update!"
>>>>>>> 6ed7dd4a4 (tests: housekeeping - test_cache.py)

0 comments on commit 3634a2c

Please sign in to comment.