Skip to content

Commit 0742cdd

Browse files
authored
Merge pull request #219 from boegel/abort_failed_lmod_cache_update
abort transaction if Lmod cache update failed
2 parents 0fb91a4 + 9fa46f7 commit 0742cdd

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

scripts/ingest-tarball.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
# Only if it passes these checks, the tarball gets ingested to the base dir in the repository specified below.
1414

15+
CVMFS_ROOT=${CUSTOM_CVMFS_ROOT:-/cvmfs}
16+
1517
basedir=versions
1618
decompress="gunzip -c"
1719
cvmfs_server="cvmfs_server"
@@ -180,8 +182,14 @@ function update_lmod_caches() {
180182
error "the script for updating the Lmod caches (${update_caches_script}) does not have execute permissions!"
181183
fi
182184
${cvmfs_server} transaction "${cvmfs_repo}"
183-
${update_caches_script} /cvmfs/${cvmfs_repo}/${basedir}/${version}
184-
${cvmfs_server} publish -m "update Lmod caches after ingesting ${tar_file_basename}" "${cvmfs_repo}"
185+
${update_caches_script} "${CVMFS_ROOT}/${cvmfs_repo}/${basedir}/${version}"
186+
ec=$?
187+
if [ $ec -eq 0 ]; then
188+
${cvmfs_server} publish -m "update Lmod caches after ingesting ${tar_file_basename}" "${cvmfs_repo}"
189+
else
190+
${cvmfs_server} abort -f "${cvmfs_repo}"
191+
error "Update of Lmod caches after ingesting ${tar_file_basename} for ${cvmfs_repo} failed!"
192+
fi
185193
}
186194

187195
function ingest_init_tarball() {
@@ -206,7 +214,7 @@ function ingest_compat_tarball() {
206214
# Handle the ingestion of tarballs containing a compatibility layer
207215
check_arch
208216
check_os
209-
compat_layer_path="/cvmfs/${cvmfs_repo}/${basedir}/${version}/compat/${os}/${arch}"
217+
compat_layer_path="${CVMFS_ROOT}/${cvmfs_repo}/${basedir}/${version}/compat/${os}/${arch}"
210218
# Assume that we already had a compat layer in place if there is a startprefix script in the corresponding CVMFS directory
211219
if [ -f "${compat_layer_path}/startprefix" ];
212220
then
@@ -217,7 +225,7 @@ function ingest_compat_tarball() {
217225
old_layer_suffixed_path="${compat_layer_path}-${new_suffix}"
218226
echo_yellow "Moving the existing compat layer from ${compat_layer_path} to ${old_layer_suffixed_path}..."
219227
mv ${compat_layer_path} ${old_layer_suffixed_path}
220-
tar -C "/cvmfs/${cvmfs_repo}/${basedir}/" -xzf "${tar_file}"
228+
tar -C "${CVMFS_ROOT}/${cvmfs_repo}/${basedir}/" -xzf "${tar_file}"
221229
${cvmfs_server} publish -m "updated compat layer for ${version}, ${os}, ${arch}" "${cvmfs_repo}"
222230
ec=$?
223231
if [ $ec -eq 0 ]

scripts/test-ingest-tarball.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash
22

3-
INGEST_SCRIPT=$(dirname "$(realpath $0)")/ingest-tarball.sh
4-
TEST_OUTPUT=/dev/null # change to /dev/stdout to print test outputs for debugging purposes
5-
63
# Temporary base dir for the tests
74
tstdir=$(mktemp -d)
85

6+
# let ingest-tarball.sh script not use /cvmfs, but a temporary directory we can create
7+
export CUSTOM_CVMFS_ROOT=${tstdir}/cvmfs
8+
9+
INGEST_SCRIPT=$(dirname "$(realpath $0)")/ingest-tarball.sh
10+
TEST_OUTPUT=${tstdir}/out.txt
11+
912
# Statistics
1013
num_tests=0
1114
num_tests_failed=0
@@ -87,15 +90,30 @@ tarballs_fail=(
8790
"$tstdir/eessi-2000.01-compat-123456.tar.gz 2000.01 compat"
8891
)
8992

93+
# update_lmod_caches.sh script requires that directory exists,
94+
# and that script to update Lmod cache is found in there
95+
repo_version_root="${CUSTOM_CVMFS_ROOT}/my.repo.tld/versions/2000.01"
96+
lmod_libexec_path="${repo_version_root}/compat/linux/$(uname -m)/usr/share/Lmod/libexec/"
97+
mkdir -p "${lmod_libexec_path}"
98+
lmod_update_script="${lmod_libexec_path}/update_lmod_system_cache_files"
99+
touch "${lmod_update_script}"
100+
chmod u+x "${lmod_update_script}"
101+
102+
90103
# Run the tests that should succeed
91104
for ((i = 0; i < ${#tarballs_success[@]}; i++)); do
92105
t=$(create_tarball ${tarballs_success[$i]})
93106
"${INGEST_SCRIPT}" "my.repo.tld" "$t" >& "${TEST_OUTPUT}"
94107
if [ ! $? -eq 0 ]; then
108+
echo ">> ${tarballs_success[$i]} test with existing repo FAILed!" >&2
109+
echo ">> output:" >&2
110+
cat "${TEST_OUTPUT}" >&2
111+
echo >&2
95112
num_tests_failed=$((num_tests_failed + 1))
96113
else
97114
num_tests_succeeded=$((num_tests_succeeded + 1))
98115
fi
116+
rm -f "${TEST_OUTPUT}"
99117
num_tests=$((num_tests + 1))
100118
done
101119

@@ -104,10 +122,15 @@ for ((i = 0; i < ${#tarballs_fail[@]}; i++)); do
104122
t=$(create_tarball ${tarballs_fail[$i]})
105123
"${INGEST_SCRIPT}" "my.repo.tld" "$t" >& "${TEST_OUTPUT}"
106124
if [ ! $? -eq 1 ]; then
125+
echo ">> ${tarballs_fail[$i]} test passed, but should have failed!" >&2
126+
echo ">> output:" >&2
127+
cat "${TEST_OUTPUT}" >&2
128+
echo >&2
107129
num_tests_failed=$((num_tests_failed + 1))
108130
else
109131
num_tests_succeeded=$((num_tests_succeeded + 1))
110132
fi
133+
rm -f "${TEST_OUTPUT}"
111134
num_tests=$((num_tests + 1))
112135
done
113136

@@ -116,10 +139,15 @@ for ((i = 0; i < ${#tarballs_success[@]}; i++)); do
116139
t=$(create_tarball ${tarballs_success[$i]})
117140
"${INGEST_SCRIPT}" "my.nonexistingrepo.tld" "$t" >& "${TEST_OUTPUT}"
118141
if [ ! $? -eq 1 ]; then
142+
echo ">> ${tarballs_success[$i]} test passed with non-existing repo, should have failed!" >&2
143+
echo ">> output:" >&2
144+
cat "${TEST_OUTPUT}" >&2
145+
echo >&2
119146
num_tests_failed=$((num_tests_failed + 1))
120147
else
121148
num_tests_succeeded=$((num_tests_succeeded + 1))
122149
fi
150+
rm -f "${TEST_OUTPUT}"
123151
num_tests=$((num_tests + 1))
124152
done
125153

0 commit comments

Comments
 (0)