Skip to content

Commit

Permalink
Tests: Fix hostmap tests not to depend on user-nsswitch.conf
Browse files Browse the repository at this point in the history
The user-nsswitch.conf was removed in F36+. Tests using it therefore
need fixing to use /etc/nssswitch.conf on Fedora instead.
Fixed indentation of install_nslcd.

Reviewed-by: Madhuri Upadhye <[email protected]>
  • Loading branch information
jakub-vavra-cz committed Mar 7, 2024
1 parent a80e236 commit 0935ce9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/tests/multihost/alltests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,10 @@ def install_nslcd(session_multihost, request):
execute_cmd(session_multihost, "echo 'uid nslcd' > /etc/nslcd.conf")
execute_cmd(session_multihost, "echo 'gid ldap' >> /etc/nslcd.conf")
execute_cmd(session_multihost, f"echo 'uri ldap://"
f"{session_multihost.master[0].ip}'"
f" >> /etc/nslcd.conf")
f"{session_multihost.master[0].ip}'"
f" >> /etc/nslcd.conf")
execute_cmd(session_multihost, f"echo 'base {ds_suffix}' >> "
f"/etc/nslcd.conf")
f"/etc/nslcd.conf")
execute_cmd(session_multihost, "systemctl restart nslcd")

def restore_install_nslcd():
Expand Down Expand Up @@ -1439,20 +1439,30 @@ def restore_sssd():
def enable_sssd_hostmap(session_multihost, request):
""" Enables sssd for network and host database in nsswitch.conf """
tools = sssdTools(session_multihost.client[0])
# Since Fedora 36+ support of user-nsswitch was dropped
# This applies to CentOS 10 and RHEL 10
nsswitch_file = '/etc/authselect/user-nsswitch.conf'
cmd = session_multihost.client[0].run_command(
f"test -f {nsswitch_file}", raiseonerr=False)
has_user_nsswith = cmd.returncode == 0
if not has_user_nsswith:
nsswitch_file = "/etc/nsswitch.conf"

bkup = f'cp -vf {nsswitch_file} {nsswitch_file}_bkp'
session_multihost.client[0].run_command(bkup)

for value in ['hosts', 'networks']:
update_nsswitch = f"sed -i 's/{value}:/{value}: sss/' {nsswitch_file}"
session_multihost.client[0].run_command(update_nsswitch)
authselect = 'authselect select sssd'
session_multihost.client[0].run_command(authselect)
if has_user_nsswith:
authselect = 'authselect select sssd'
session_multihost.client[0].run_command(authselect)

def restore_nsswitch():
restore = f"cp -vf {nsswitch_file}_bkp {nsswitch_file}"
session_multihost.client[0].run_command(restore)
session_multihost.client[0].run_command(authselect)
if has_user_nsswith:
session_multihost.client[0].run_command(authselect)
tools.clear_sssd_cache()
# remove the backup file
remove_bkup = 'rm -f %s_bkup' % nsswitch_file
Expand Down

0 comments on commit 0935ce9

Please sign in to comment.