From 50e290dced417b9537067acb5b4eee2321792b65 Mon Sep 17 00:00:00 2001 From: William Brown Date: Jan 09 2019 23:13:23 +0000 Subject: Ticket 50126 - Incorrect usage of sudo in test Bug Description: Sudo is assumed to be present and working in passwordless mode with basictest. Fix Description: We can not make this assumption, that sudo is installed (docker) or in passwordless mode. As a result for this test to work, we should run the suite as "sudo py.test" or "dirsrv". Potentially we may need to update defaults.inf for people who want to run the tests as their own user ID. https://pagure.io/389-ds-base/issue/50126 Author: William Brown Review by: ??? --- diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py index 790fcc6..50db65d 100644 --- a/dirsrvtests/tests/suites/basic/basic_test.py +++ b/dirsrvtests/tests/suites/basic/basic_test.py @@ -798,7 +798,9 @@ def test_basic_ldapagent(topology_st, import_example_ldif): log.info('test_basic_ldapagent: PASSED') -def test_basic_dse(topology_st, import_example_ldif): +@pytest.mark.skipif(not get_user_is_ds_owner(), + reason="process ownership permission is required") +def test_basic_dse_survives_kill9(topology_st, import_example_ldif): """Tests that the dse.ldif is not wiped out after the process is killed (bug 910581) :id: 10f141da-9b22-443a-885c-87271dcd7a59 @@ -819,7 +821,9 @@ def test_basic_dse(topology_st, import_example_ldif): dse_file = topology_st.standalone.confdir + '/dse.ldif' pid = check_output(['pidof', '-s', 'ns-slapd']).strip() - check_output(['sudo', 'kill', '-9', ensure_str(pid)]) + # We can't guarantee we have access to sudo in any environment ... Either + # run py.test with sudo, or as the same user as the dirsrv. + check_output(['kill', '-9', ensure_str(pid)]) if os.path.getsize(dse_file) == 0: log.fatal('test_basic_dse: dse.ldif\'s content was incorrectly removed!') assert False diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index 258afe8..cb0244c 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -33,6 +33,7 @@ import socket import time import sys import filecmp +import pwd import six import shlex import subprocess @@ -1167,4 +1168,19 @@ def get_instance_list(prefix=None): insts.sort() return insts +def get_user_is_ds_owner(): + # Check if we have permission to administer the DS instance. This is required + # for some tasks such as installing, killing, or editing configs for the + # instance. + cur_uid = os.getuid() + if cur_uid == 0: + # We are root, we have permission + return True + cur_username = pwd.getpwuid(cur_uid)[0] + p = Paths() + if cur_username == p.user: + # We are the same user, all good + return True + return False +