Skip to content

Commit 2252767

Browse files
committed
Add test for tar deletion
1 parent a8469ed commit 2252767

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ build/
22
dist/
33
tests/utils/test_follow_symlinks
44
tests/utils/test_follow_symlinks_non_archived
5+
tests/utils/globus_tar_deletion
56
zstash.egg-info/
67
*.pyc
78
*~
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Assertions ##################################################################
2+
check_log_has()
3+
{
4+
local expected_grep="${1}"
5+
local log_file="${2}"
6+
grep -q "${expected_grep}" ${log_file}
7+
if [ $? != 0 ]; then
8+
echo "Expected grep '${expected_grep}' not found in ${log_file}. Test failed."
9+
exit 2
10+
fi
11+
}
12+
13+
check_log_does_not_have()
14+
{
15+
local not_expected_grep="${1}"
16+
local log_file="${2}"
17+
grep -q "${not_expected_grep}" ${log_file}
18+
if [ $? == 0 ]; then
19+
echo "Not-expected grep '${not_expected_grep}' was found in ${log_file}. Test failed."
20+
exit 2
21+
fi
22+
}
23+
24+
# Helper functions ############################################################
25+
setup()
26+
{
27+
echo "##########################################################################################################"
28+
local case_name="${1}"
29+
local src_dir="${2}"
30+
echo "Testing: ${case_name}"
31+
full_dir="${src_dir}/${case_name}"
32+
rm -rf ${full_dir}
33+
mkdir -p ${full_dir}
34+
cd ${full_dir}
35+
36+
mkdir zstash_demo
37+
mkdir zstash_demo/empty_dir
38+
mkdir zstash_demo/dir
39+
echo -n '' > zstash_demo/file_empty.txt
40+
echo 'file0 stuff' > zstash_demo/dir/file0.txt
41+
}
42+
43+
get_endpoint()
44+
{
45+
# Usage example:
46+
# uuid=$(get_endpoint NERSC_PERLMUTTER_ENDPOINT)
47+
48+
local endpoint_name=$1
49+
# Define endpoints; see https://app.globus.org/collections
50+
LCRC_IMPROV_DTN_ENDPOINT=15288284-7006-4041-ba1a-6b52501e49f1
51+
case ${endpoint_name} in
52+
LCRC_IMPROV_DTN_ENDPOINT)
53+
echo ${LCRC_IMPROV_DTN_ENDPOINT}
54+
;;
55+
*)
56+
echo "Unknown endpoint name: ${endpoint_name}" >&2
57+
exit 1
58+
;;
59+
esac
60+
}
61+
62+
confirm() {
63+
read -p "$1 (y/n): " -n 1 -r
64+
echo
65+
[[ $REPLY =~ ^[Yy]$ ]]
66+
}
67+
68+
# Tests #######################################################################
69+
test_globus_tar_deletion()
70+
{
71+
local path_to_repo=$1
72+
local dst_endpoint=$2
73+
local dst_dir=$3
74+
local case_name=$4
75+
76+
src_dir=${path_to_repo}/tests/utils/globus_tar_deletion
77+
rm -rf ${src_dir} # Start fresh
78+
mkdir -p ${src_dir}
79+
dst_endpoint_uuid=$(get_endpoint ${dst_endpoint})
80+
globus_path=globus://${dst_endpoint_uuid}/${dst_dir}
81+
82+
# GLOBUS_CFG=${HOME}/.globus-native-apps.cfg
83+
# INI_PATH=${HOME}/.zstash.ini
84+
# TOKEN_FILE=${HOME}/.zstash_globus_tokens.json
85+
86+
# Start fresh
87+
# echo "Reset Globus consents:"
88+
# echo "https://auth.globus.org/v2/web/consents > Globus Endpoint Performance Monitoring > rescind all"
89+
# if ! confirm "Have you revoked Globus consents?"; then
90+
# exit 1
91+
# fi
92+
# rm -rf ${GLOBUS_CFG}
93+
# rm -rf ${INI_PATH}
94+
# rm -rf ${TOKEN_FILE}
95+
96+
echo "Running test_globus_tar_deletion on case=${case_name}"
97+
echo "Exit codes: 0 -- success, 1 -- zstash failed, 2 -- grep check failed"
98+
99+
setup ${case_name} "${src_dir}"
100+
101+
if [ "$case_name" == "non-blocking" ]; then
102+
blocking_flag="--non-blocking"
103+
else
104+
blocking_flag=""
105+
fi
106+
107+
zstash create ${blocking_flag} --hpss=${globus_path}/${case_name} --maxsize 128 zstash_demo 2>&1 | tee ${case_name}.log
108+
if [ $? != 0 ]; then
109+
echo "${case_name} failed. Check ${case_name}_create.log for details. Cannot continue."
110+
exit 1
111+
fi
112+
echo "${case_name} completed successfully. Checking ${case_name}.log now."
113+
check_log_has "Creating new tar archive 000000.tar" ${case_name}.log
114+
115+
echo "Checking directory status after 'zstash create' has completed. src should only have index.db. dst should have tar and index.db."
116+
117+
echo "Checking src"
118+
ls ${src_dir}/${case_name}/ 2>&1 | tee ls_${case_name}_src_output.log
119+
check_log_has "${case_name}.log" ls_${case_name}_src_output.log
120+
check_log_has "zstash_demo" ls_${case_name}_src_output.log
121+
ls ${src_dir}/${case_name}/zstash_demo 2>&1 | tee ls_${case_name}_src2_output.log
122+
check_log_has "zstash" ls_${case_name}_src2_output.log
123+
ls ${src_dir}/${case_name}/zstash_demo/zstash 2>&1 | tee ls_${case_name}_src3_output.log
124+
check_log_has "index.db" ls_${case_name}_src3_output.log
125+
check_log_does_not_have "tar" ls_${case_name}_src3_output.log # tar is deleted at src
126+
127+
echo "Checking dst"
128+
ls ${dst_dir}/ 2>&1 | tee ls_${case_name}_dst_output.log
129+
check_log_has "${case_name}" ls_${case_name}_dst_output.log
130+
ls ${dst_dir}/${case_name}/ 2>&1 | tee ls_${case_name}_dst2_output.log
131+
check_log_has "index.db" ls_${case_name}_dst2_output.log
132+
check_log_has "000000.tar" ls_${case_name}_dst2_output.log # tar should be at dst
133+
134+
# Cleanup:
135+
#cd ${path_to_repo}/tests/integration/bash_tests/run_from_chrysalis
136+
#rm -rf ${path_to_repo}/tests/utils/globus_tar_deletion
137+
}
138+
139+
# Follow these directions #####################################################
140+
141+
# Example usage:
142+
# ./test_globus_tar_deletion.bash run1 /home/ac.forsyth2/ez/zstash /home/ac.forsyth2/zstash_tests
143+
144+
# Command line parameters:
145+
unique_id="$1"
146+
path_to_repo="$2" # /home/ac.forsyth2/ez/zstash
147+
chrysalis_dst_basedir="$3" # /home/ac.forsyth2/zstash_tests
148+
chrysalis_dst_dir=${chrysalis_dst_basedir}/test_globus_tar_deletion_${unique_id}
149+
150+
151+
echo "You may wish to clear your dst directories for a fresh start:"
152+
echo "Chrysalis: rm -rf ${chrysalis_dst_basedir}/test_globus_tar_deletion*"
153+
echo "It is advisable to just set a unique_id to avoid directory conflicts."
154+
echo "Currently, unique_id=${unique_id}"
155+
if ! confirm "Is the unique_id correct?"; then
156+
exit 1
157+
fi
158+
159+
echo "Go to https://app.globus.org/file-manager?two_pane=true > For "Collection", choose each of the following endpoints and, if needed, authenticate:"
160+
echo "LCRC Improv DTN"
161+
if ! confirm "Have you authenticated into all endpoints?"; then
162+
exit 1
163+
fi
164+
165+
echo "Primary tests: single authentication code tests for each endpoint"
166+
echo "If a test hangs, check if https://app.globus.org/activity reports any errors on your transfers."
167+
test_globus_tar_deletion ${path_to_repo} LCRC_IMPROV_DTN_ENDPOINT ${chrysalis_dst_dir} "blocking"
168+
test_globus_tar_deletion ${path_to_repo} LCRC_IMPROV_DTN_ENDPOINT ${chrysalis_dst_dir} "non-blocking"
169+
170+
echo "All globus tar deletion tests completed successfully."

0 commit comments

Comments
 (0)