Skip to content

Commit 6b4dd2a

Browse files
committed
Testsuite - Fix test_147_1 for upgrades adding spank_tmp_lib fixture
Issue: 50420
1 parent a452aa5 commit 6b4dd2a

4 files changed

Lines changed: 115 additions & 66 deletions

File tree

testsuite/python/conftest.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,55 @@ def spank_fail_lib(module_setup):
425425
yield bin_path
426426

427427
atf.run_command(f"rm -f {bin_path}", fatal=True)
428+
429+
430+
@pytest.fixture(scope="module")
431+
def spank_tmp_lib(module_setup):
432+
"""
433+
Compiles a SPANK plugin that will write files in a /tmp directory.
434+
Returns the tmp_spank dir and the bin path of the spank .so that will write
435+
files in the tmp_spank dir if configured.
436+
"""
437+
438+
# The plugin uses ESPANK_NODE_FAILURE, so it needs to compile against 25.05+
439+
# It also needs to be built against the same version of slurmd and submit
440+
# clients like sbatch
441+
new_prefixes = False
442+
if atf.is_upgrade_setup():
443+
slurmd_version = atf.get_version("sbin/slurmd")
444+
sbatch_version = atf.get_version("bin/sbatch")
445+
446+
if slurmd_version != sbatch_version:
447+
pytest.skip(
448+
f"We need to build SPANK against Slurm version of submit clients as sbatch {sbatch_version} and slurmd {slurmd_version}, but they diffear."
449+
)
450+
if (
451+
atf.get_version("config.h", slurm_prefix=atf.properties["new-build-prefix"])
452+
== slurmd_version
453+
):
454+
new_prefixes = True
455+
elif (
456+
not atf.get_version(
457+
"config.h", slurm_prefix=atf.properties["old-build-prefix"]
458+
)
459+
== slurmd_version
460+
):
461+
# This should never happen, slurmd should be one of those versions
462+
pytest.fail(
463+
"Unable to find build dir to match slurmd version {slurmd_version}"
464+
)
465+
466+
src_path = atf.properties["testsuite_scripts_dir"] + "/spank_tmp_plugin.c"
467+
bin_path = os.getcwd() + "/spank_tmp_plugin.so"
468+
469+
atf.compile_against_libslurm(
470+
src_path, bin_path, full=True, shared=True, new_prefixes=new_prefixes
471+
)
472+
473+
tmp_spank = "/tmp/spank"
474+
atf.run_command(f"mkdir -p {tmp_spank}", fatal=True)
475+
476+
yield tmp_spank, bin_path
477+
478+
atf.run_command(f"rm -f {bin_path}", fatal=True)
479+
atf.run_command(f"rm -rf {tmp_spank}", fatal=True)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*****************************************************************************\
2+
* Copyright (C) SchedMD LLC.
3+
\*****************************************************************************/
4+
#include <fcntl.h>
5+
#include <slurm/spank.h>
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
9+
SPANK_PLUGIN(spank_tmp_plugin, 1);
10+
11+
int slurm_spank_user_init(spank_t sp, int ac, char **av)
12+
{
13+
FILE *file = fopen("/tmp/spank/slurm_spank_user_init_log", "w");
14+
if (file == NULL) {
15+
slurm_error("Failed to open slurm_spank_user_init_log file\n");
16+
return ESPANK_ERROR;
17+
}
18+
fprintf(file, "slurm_spank_user_init_executed\n");
19+
fclose(file);
20+
return ESPANK_SUCCESS;
21+
}
22+
23+
int slurm_spank_task_post_fork(spank_t sp, int ac, char **av)
24+
{
25+
FILE *file = fopen("/tmp/spank/slurm_spank_task_post_fork_log", "w");
26+
if (file == NULL) {
27+
slurm_error(
28+
"Failed to open slurm_spank_task_post_fork_log file\n");
29+
return ESPANK_ERROR;
30+
}
31+
fprintf(file, "slurm_spank_task_post_fork_executed\n");
32+
fclose(file);
33+
return ESPANK_SUCCESS;
34+
}
35+
36+
int slurm_spank_task_exit(spank_t sp, int ac, char **av)
37+
{
38+
FILE *file = fopen("/tmp/spank/slurm_spank_task_exit_log", "w");
39+
if (file == NULL) {
40+
slurm_error("Failed to open slurm_spank_task_exit_log file\n");
41+
return ESPANK_ERROR;
42+
}
43+
fprintf(file, "slurm_spank_task_exit_executed\n");
44+
fclose(file);
45+
return ESPANK_SUCCESS;
46+
}

testsuite/python/scripts/test_147_1_spank_plugin.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

testsuite/python/tests/test_147_1.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,22 @@
22
import pytest
33
import os
44

5-
spank_plugin_script = "test_147_1_spank_plugin.c"
6-
spank_compiled_plugin = "test_147_1_spank_plugin.so"
5+
spank_tmp = ""
76

87

98
# Setup
109
@pytest.fixture(scope="module", autouse=True)
11-
def setup():
10+
def setup(spank_tmp_lib):
11+
global spank_tmp
12+
spank_tmp, spank_lib = spank_tmp_lib
1213
atf.require_config_parameter("JobContainerType", "job_container/tmpfs")
1314
atf.require_config_parameter_includes("SlurmdParameters", "contain_spank")
1415
atf.require_config_parameter_includes("PrologFlags", "Contain")
1516

16-
# Compile SPANK plugin
17-
spank_plugin_script_path = (
18-
f"{atf.properties['testsuite_scripts_dir']}/{spank_plugin_script}"
19-
)
20-
atf.compile_against_libslurm(
21-
spank_plugin_script_path, spank_compiled_plugin, full=True, shared=True
22-
)
23-
2417
# Ensure the SPANK plugin is included in plugstack.conf
2518
atf.require_config_parameter(
2619
"required",
27-
f"{atf.module_tmp_path}/{spank_compiled_plugin}",
20+
f"{spank_lib}",
2821
delimiter=" ",
2922
source="plugstack",
3023
)
@@ -35,11 +28,8 @@ def setup():
3528
"BasePath", "/tmp/%h_%n_base_path", source="job_container"
3629
)
3730

38-
# Mount /tmp/test_147_1_private in the job container as a private mount
39-
atf.require_config_parameter(
40-
"Dirs", "/tmp/test_147_1_private", source="job_container"
41-
)
42-
atf.run_command("mkdir -p /tmp/test_147_1_private", fatal=True)
31+
# Mount spank_tmp in the job container as a private mount
32+
atf.require_config_parameter("Dirs", spank_tmp, source="job_container")
4333

4434
atf.require_slurm_running()
4535

@@ -49,14 +39,14 @@ def test_spank_plugin_tmpfs():
4939
Test that SPANK plugin hooks execute correctly in the tmpfs job container.
5040
"""
5141
# Clear out the private mount and create a file outside the container
52-
atf.run_command("rm -rf /tmp/test_147_1_private/*", fatal=True)
53-
atf.run_command("touch /tmp/test_147_1_private/file_on_host", fatal=True)
42+
atf.run_command(f"rm -rf {spank_tmp}/*", fatal=True)
43+
atf.run_command(f"touch {spank_tmp}/file_on_host", fatal=True)
5444

5545
atf.make_bash_script(
5646
"job.sh",
57-
"""
47+
f"""
5848
# Check to make sure job_container/tmpfs made a private mount
59-
if [[ -f /tmp/test_147_1_private/file_on_host ]]; then
49+
if [[ -f {spank_tmp}/file_on_host ]]; then
6050
echo "job_container/tmpfs failed to create private mount"
6151
else
6252
echo "job_container/tmpfs created private mount"
@@ -66,21 +56,21 @@ def test_spank_plugin_tmpfs():
6656
srun hostname
6757
6858
# Check if slurm_spank_user_init executed its functions and left behind a file
69-
if [[ -f /tmp/test_147_1_private/slurm_spank_user_init_log ]]; then
59+
if [[ -f {spank_tmp}/slurm_spank_user_init_log ]]; then
7060
echo "Found log for hook slurm_spank_user_init"
7161
else
7262
echo "Couldn't find log for hook slurm_spank_user_init"
7363
fi
7464
7565
# Check if slurm_spank_task_post_fork executed its functions and left behind a file
76-
if [[ -f /tmp/test_147_1_private/slurm_spank_task_post_fork_log ]]; then
66+
if [[ -f {spank_tmp}/slurm_spank_task_post_fork_log ]]; then
7767
echo "Found log for hook slurm_spank_task_post_fork"
7868
else
7969
echo "Couldn't find log for hook slurm_spank_task_post_fork"
8070
fi
8171
8272
# Check if slurm_spank_task_exit executed its functions and left behind a file
83-
if [[ -f /tmp/test_147_1_private/slurm_spank_task_exit_log ]]; then
73+
if [[ -f {spank_tmp}/slurm_spank_task_exit_log ]]; then
8474
echo "Found log for hook slurm_spank_task_exit"
8575
else
8676
echo "Couldn't find log for hook slurm_spank_task_exit"
@@ -115,7 +105,7 @@ def test_spank_plugin_tmpfs():
115105
"job_container/tmpfs created private mount" in content
116106
), "job_container/tmpfs failed to create a private mount because we found a pre-existing file on the host when running a job"
117107
assert not (
118-
os.path.isfile("/tmp/test_147_1_private/slurm_spank_user_init_log")
119-
or os.path.isfile("/tmp/test_147_1_private/slurm_spank_task_post_fork_log")
120-
or os.path.isfile("/tmp/test_147_1_private/slurm_spank_task_exit_log")
108+
os.path.isfile(f"{spank_tmp}/slurm_spank_user_init_log")
109+
or os.path.isfile(f"{spank_tmp}/slurm_spank_task_post_fork_log")
110+
or os.path.isfile(f"{spank_tmp}/slurm_spank_task_exit_log")
121111
), "job_container/tmpfs failed to isolate private mount; files created in container appear on host"

0 commit comments

Comments
 (0)