Testsuite - Add SlurmTestUser to the testsuite.conf
diff --git a/testsuite/README b/testsuite/README
index c11087e..d353706 100644
--- a/testsuite/README
+++ b/testsuite/README
@@ -45,6 +45,11 @@
 SlurmInstallDir: Slurm Installation Directory (value of --prefix configure option)
 SlurmConfigDir:  Slurm Configuration Directory (compiled-in location of slurm.conf)
 
+If you are running in local-config, if the user running the test is SlurmUser or
+AdminLevel, you better specify an unprivileged user to run the test commands as:
+
+SlurmTestUser: Linux user without AdminLevel in the local-config Slurm.
+
 Tips:
 
 * the include and exclude filters use (perl 5) regular expressions
diff --git a/testsuite/python/conftest.py b/testsuite/python/conftest.py
index e6c929a..dab3d0c 100644
--- a/testsuite/python/conftest.py
+++ b/testsuite/python/conftest.py
@@ -14,7 +14,7 @@
 # import shutil
 import sys
 
-# from pathlib import Path
+from pathlib import Path
 
 sys.path.append(sys.path[0] + "/lib")
 import atf
@@ -125,7 +125,7 @@
         color_log_level(logging.TRACE, purple=True, bold=True)
 
 
-def update_tmp_path_exec_permissions():
+def update_tmp_path_exec_permissions(path):
     """
     For pytest versions 6+  the tmp path it uses no longer has
     public exec permissions for dynamically created directories by default.
@@ -140,15 +140,22 @@
     Bug 16568
     """
 
-    user_name = atf.get_user_name()
-    path = f"/tmp/pytest-of-{user_name}"
-
     if os.path.isdir(path):
         os.chmod(path, 0o777)
         for root, dirs, files in os.walk(path):
             for d in dirs:
                 os.chmod(os.path.join(root, d), 0o777)
 
+        # Ensure access for parent dirs too
+        path = path.resolve()
+        if not path.is_relative_to("/tmp"):
+            pytest.fail(f"Unexpected tmp path outside /tmp: {path}")
+
+        subdir = Path("/tmp")
+        for part in path.relative_to("/tmp").parts:
+            subdir = subdir / part
+            os.chmod(subdir, 0o777)
+
 
 @pytest.fixture(scope="module", autouse=True)
 def module_setup(request, tmp_path_factory):
@@ -179,7 +186,7 @@
     name = name[:30]
     atf.properties["test_name"] = name
     atf.module_tmp_path = tmp_path_factory.mktemp(name, numbered=True)
-    update_tmp_path_exec_permissions()
+    update_tmp_path_exec_permissions(atf.module_tmp_path)
 
     # Module-level fixtures should run from within the module_tmp_path
     os.chdir(atf.module_tmp_path)
@@ -318,6 +325,7 @@
         logging.info(request.function.__doc__)
 
     # Start each test inside the tmp_path
+    update_tmp_path_exec_permissions(tmp_path)
     monkeypatch.chdir(tmp_path)
 
 
diff --git a/testsuite/python/lib/atf.py b/testsuite/python/lib/atf.py
index 95ba0a2..99bcc0e 100644
--- a/testsuite/python/lib/atf.py
+++ b/testsuite/python/lib/atf.py
@@ -182,6 +182,10 @@
     if env_vars is not None:
         command = env_vars.strip() + " " + command
 
+    # If user is not specified but test-user is set, then set user to test-user
+    if not user and properties["test-user-set"]:
+        user = properties["test-user"]
+
     start_time = time.time()
     invocation_message = "Running command"
     if user is not None:
@@ -189,7 +193,7 @@
     invocation_message += f": {command}"
     logging.log(log_command_level, invocation_message)
     try:
-        if user is not None and user != properties["test-user"]:
+        if user is not None:
             if not properties["sudo-rights"]:
                 pytest.skip(
                     "This test requires the test user to have unprompted sudo rights",
@@ -1278,7 +1282,9 @@
             slurm_prefix = f"{properties['slurm-sbin-dir']}/.."
 
         version_str = (
-            run_command_output(f"sudo {slurm_prefix}/{component} -V", quiet=True)
+            run_command_output(
+                f"{slurm_prefix}/{component} -V", quiet=True, user="root"
+            )
             .strip()
             .replace("slurm ", "")
         )
@@ -2481,7 +2487,7 @@
         False
     """
 
-    user_name = get_user_name()
+    user_name = properties["test-user"]
 
     run_command(f"scancel -u {user_name}", fatal=fatal, quiet=quiet)
 
@@ -4125,7 +4131,9 @@
                         augmentation_dict[parameter_name] = parameter_value
             elif parameter_name == "Features":
                 required_features = set(parameter_value.split(","))
-                node_features = set(lower_node_dict.get("features", "").split(","))
+                features = lower_node_dict.get("features", [])
+                features = features[0] if features else ""
+                node_features = set(features.split(","))
                 if not required_features.issubset(node_features):
                     if node_qualifies:
                         node_qualifies = False
@@ -4224,7 +4232,16 @@
     with open(script_name, "w") as f:
         f.write("#!/bin/bash\n")
         f.write(script_contents)
-    os.chmod(script_name, 0o0700)
+
+    run_command(f"chmod 777 {script_name}", user="root", fatal=True, quiet=True)
+
+    if properties["test-user-set"]:
+        run_command(
+            f"chown {properties['test-user']} {script_name}",
+            user="root",
+            fatal=True,
+            quiet=True,
+        )
 
 
 def wait_for_file(file_name, **repeat_until_kwargs):
@@ -4883,7 +4900,7 @@
             if match := re.search(r"^\s*(?i:SlurmUser)\s*=\s*(.*)$", line):
                 properties["slurm-user"] = match.group(1)
 else:
-    # slurm.conf is not readable as test-user. We will try reading it as root
+    # slurm.conf is not readable, we will try reading it as root
     results = run_command(
         f"grep -i SlurmUser {slurm_config_file}", user="root", quiet=True
     )
@@ -4894,7 +4911,16 @@
             properties["slurm-user"] = match.group(1)
 
 properties["submitted-jobs"] = []
-properties["test-user"] = pwd.getpwuid(os.getuid()).pw_name
+if "slurmtestuser" in testsuite_config:
+    properties["test-user"] = testsuite_config["slurmtestuser"]
+    properties["test-user-set"] = True
+else:
+    properties["test-user"] = pwd.getpwuid(os.getuid()).pw_name
+    properties["test-user-set"] = False
+
+properties["test-user-uid"] = pwd.getpwnam(properties["test-user"]).pw_uid
+properties["test-user-gid"] = pwd.getpwnam(properties["test-user"]).pw_gid
+
 properties["auto-config"] = False
 properties["allow-slurmdbd-modify"] = False
 properties["slurmrestd-started"] = False