Skip to content

Commit 4fc45a7

Browse files
committed
Install mock scontrol only when the real one is not there
1 parent 272e2a6 commit 4fc45a7

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

tests/assets/scontrol-mock

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

tests/test_pmix_hook.bats

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,25 @@ setup() {
1414
HOOK_ERR_PID=$!
1515

1616
# Prepare mock 'scontrol'
17-
TMP_BIN_DIR=$(mktemp -d)
18-
cp ${BATS_TEST_DIRNAME}/assets/scontrol-mock ${TMP_BIN_DIR}/scontrol
17+
if ! which scontrol >/dev/null 2>&1; then
18+
echo "$0: info: scontrol not found. installing scontrol-mock..."
19+
20+
TMP_BIN_DIR=$(mktemp -d)
21+
cat <<EOS >${TMP_BIN_DIR}/scontrol
22+
#!/bin/bash
23+
24+
if [[ "\$1" == "show" ]] && [[ "\$2" == "config" ]]; then
25+
cat <<EOF
26+
Configuration data as of 2025-09-16T10:59:04
27+
SlurmdSpoolDir = /tmp/spool/slurmd
28+
TmpFS = /tmp
29+
Slurmctld(primary) at zinal-slurmctl is UP
30+
EOF
31+
fi
32+
EOS
33+
chmod +x ${TMP_BIN_DIR}/scontrol
34+
export PATH=${TMP_BIN_DIR}:${PATH}
35+
fi
1936

2037
# Prepare mock PMIx directories
2138
SLURM_JOB_UID=0
@@ -25,7 +42,6 @@ setup() {
2542
mkdir -p ${PMIX_DIR}
2643

2744
# Export test environment variables
28-
export PATH=${TMP_BIN_DIR}:${PATH}
2945
export SLURM_MPI_TYPE=pmix
3046
export PMIX_WHATEVER=yes
3147
export SLURM_JOB_ID=${SLURM_JOB_ID}
@@ -46,7 +62,11 @@ EOF
4662

4763
teardown() {
4864
kill "${HOOK_OUT_PID}" "${HOOK_ERR_PID}"
49-
rm -rf "${TMP_HOOKS_DIR}" "${TMP_HOOK_LOG_DIR}" "${TMP_BIN_DIR}" "${PMIX_DIR}"
65+
rm -rf "${TMP_HOOKS_DIR}" "${TMP_HOOK_LOG_DIR}" "${PMIX_DIR}"
66+
67+
if [[ -v TMP_BIN_DIR ]]; then
68+
rm -rf "${TMP_BIN_DIR}"
69+
fi
5070
}
5171

5272
@test "pmix_hook binds directory (nofail spmix_appdir)" {
@@ -65,6 +85,7 @@ teardown() {
6585
@test "pmix_hook binds directory (with SLURM_JOB_UID)" {
6686
SPMIX_APPDIR_UID_DIR=/tmp/spmix_appdir_${SLURM_JOB_UID}_${SLURM_JOB_ID}.${SLURM_STEP_ID}
6787
mkdir -p ${SPMIX_APPDIR_UID_DIR}
88+
chown $(whoami) ${SPMIX_APPDIR_UID_DIR}
6889
export SLURM_JOB_UID=${SLURM_JOB_UID}
6990

7091
podman --runtime=crun \
@@ -81,6 +102,7 @@ teardown() {
81102
@test "pmix_hook binds directory (no SLURM_JOB_UID)" {
82103
SPMIX_APPDIR_NO_UID_DIR=/tmp/spmix_appdir_${SLURM_JOB_ID}.${SLURM_STEP_ID}
83104
mkdir -p ${SPMIX_APPDIR_NO_UID_DIR}
105+
chown $(whoami) ${SPMIX_APPDIR_NO_UID_DIR}
84106
unset SLURM_JOB_UID
85107

86108
podman --runtime=crun \

0 commit comments

Comments
 (0)