Skip to content

Commit bc444ce

Browse files
authored
Merge pull request #380 from E3SM-Project/issue-339-globus
Better handle Globus authentications
2 parents ce1e38b + 3acd967 commit bc444ce

File tree

5 files changed

+442
-331
lines changed

5 files changed

+442
-331
lines changed

conda/dev.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ dependencies:
88
- pip=22.2.2
99
- python=3.9.13
1010
- six=1.16.0
11-
- globus-sdk=3.2.1
12-
- fair-research-login=0.2.6
11+
- globus-sdk=3.15.0
1312
# Developer Tools
1413
# =================
1514
# If versions are updated, also update 'rev' in `.pre-commit.config.yaml`

tests/scripts/globus_auth.bash

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
setup()
2+
{
3+
echo "##########################################################################################################"
4+
local case_name="${1}"
5+
local src_dir="${2}"
6+
echo "Testing: ${case_name}"
7+
full_dir="${src_dir}/${case_name}"
8+
rm -rf ${full_dir}
9+
mkdir -p ${full_dir}
10+
cd ${full_dir}
11+
12+
mkdir zstash_demo
13+
mkdir zstash_demo/empty_dir
14+
mkdir zstash_demo/dir
15+
echo -n '' > zstash_demo/file_empty.txt
16+
echo 'file0 stuff' > zstash_demo/dir/file0.txt
17+
}
18+
19+
check_log_has()
20+
{
21+
local expected_grep="${1}"
22+
local log_file="${2}"
23+
grep "${expected_grep}" ${log_file}
24+
if [ $? != 0 ]; then
25+
echo "Expected grep '${expected_grep}' not found in ${log_file}. Test failed."
26+
exit 2
27+
fi
28+
}
29+
30+
check_log_does_not_have()
31+
{
32+
local not_expected_grep="${1}"
33+
local log_file="${2}"
34+
grep "${not_expected_grep}" ${log_file}
35+
if [ $? == 0 ]; then
36+
echo "Not-expected grep '${expected_grep}' was found in ${log_file}. Test failed."
37+
exit 2
38+
fi
39+
}
40+
41+
run_test_cases()
42+
{
43+
# This script requires user input and thus cannot be run automatically as part of a test suite.
44+
45+
# To start fresh with Globus:
46+
# 1. Log into endpoints (LCRC Improv DTN, NERSC Perlmutter) at globus.org: File Manager > Add the endpoints in the "Collection" fields
47+
# 2. To start fresh, with no consents: https://auth.globus.org/v2/web/consents > Manage Your Consents > Globus Endpoint Performance Monitoring > rescind all"
48+
49+
# Before each run:
50+
# Perlmutter:
51+
# cd /global/homes/f/forsyth/zstash/tests/
52+
# rm -rf test_globus_auth_try1 # Or just change $DST_DIR to a new directory
53+
#
54+
# Chrysalis:
55+
# cd ~/ez/zstash/
56+
# conda activate <env-name>
57+
# pre-commit run --all-files
58+
# python -m pip install .
59+
# cd tests/scripts
60+
# ./globus_auth.bash
61+
62+
PERLMUTTER_ENDPOINT=6bdc7956-fc0f-4ad2-989c-7aa5ee643a79
63+
64+
TRY_NUM=8
65+
SRC_DIR=/lcrc/group/e3sm/ac.forsyth2/zstash_testing/test_globus_auth # Chrysalis
66+
DST_DIR=globus://${PERLMUTTER_ENDPOINT}/global/homes/f/forsyth/zstash/tests/test_globus_auth_try${TRY_NUM}
67+
68+
GLOBUS_CFG=/home/ac.forsyth2/.globus-native-apps.cfg
69+
INI_PATH=/home/ac.forsyth2/.zstash.ini
70+
TOKEN_FILE=/home/ac.forsyth2/.zstash_globus_tokens.json
71+
72+
# Start fresh
73+
rm -rf ${GLOBUS_CFG}
74+
rm -rf ${INI_PATH}
75+
rm -rf ${TOKEN_FILE}
76+
77+
echo "Running globus_auth test"
78+
echo "Exit codes: 0 -- success, 1 -- zstash failed, 2 -- grep check failed"
79+
80+
case_name="run1"
81+
setup ${case_name} "${SRC_DIR}"
82+
# Expecting to see exactly 1 authentication prompt
83+
zstash create --hpss=${DST_DIR}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
84+
if [ $? != 0 ]; then
85+
echo "${case_name} failed. Check ${case_name}_create.log for details. Cannot continue."
86+
exit 1
87+
fi
88+
echo "${case_name} completed successfully. Checking ${case_name}.log now."
89+
# From check_state_files
90+
check_log_does_not_have "WARNING: Globus CFG ${GLOBUS_CFG} exists. This may be left over from earlier versions of zstash, and may cause issues. Consider deleting." ${case_name}.log
91+
check_log_has "INFO: ${INI_PATH} does NOT exist. This means we won't be able to read the local endpoint ID from it." ${case_name}.log
92+
check_log_has "INFO: Token file ${TOKEN_FILE} does NOT exist. This means we won't be able to load tokens from it." ${case_name}.log
93+
# From get_local_endpoint_id
94+
check_log_has "INFO: Writing to empty ${INI_PATH}" ${case_name}.log
95+
check_log_has "INFO: Setting local_endpoint_id based on FQDN chrlogin2.lcrc.anl.gov:" ${case_name}.log
96+
# From get_transfer_client_with_auth
97+
check_log_has "INFO: No stored tokens found - starting authentication" ${case_name}.log
98+
check_log_has "Please go to this URL and login:" ${case_name}.log # Our one expected authentication prompt
99+
# From save_tokens
100+
check_log_has "INFO: Tokens saved successfully" ${case_name}.log
101+
102+
103+
case_name="run2"
104+
setup ${case_name} "${SRC_DIR}"
105+
# Expecting to see exactly 0 authentication prompts
106+
zstash create --hpss=${DST_DIR}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
107+
if [ $? != 0 ]; then
108+
echo "${case_name} failed. Check ${case_name}_create.log for details. Cannot continue."
109+
exit 1
110+
fi
111+
echo "${case_name} completed successfully. Checking ${case_name}.log now."
112+
# From check_state_files
113+
check_log_does_not_have "WARNING: Globus CFG ${GLOBUS_CFG} exists. This may be left over from earlier versions of zstash, and may cause issues. Consider deleting." ${case_name}.log
114+
check_log_has "INFO: ${INI_PATH} exists. We can try to read the local endpoint ID from it." ${case_name}.log # Differs from run1
115+
check_log_has "INFO: Token file ${TOKEN_FILE} exists. We can try to load tokens from it." ${case_name}.log # Differs from run1
116+
# From get_local_endpoint_id
117+
check_log_has "INFO: Setting local_endpoint_id based on ${INI_PATH}" ${case_name}.log # Differs from run1
118+
check_log_has "INFO: Setting local_endpoint_id based on FQDN chrlogin2.lcrc.anl.gov:" ${case_name}.log
119+
# From get_transfer_client_with_auth
120+
check_log_has "INFO: Found stored refresh token - using it" ${case_name}.log # Differs from run1
121+
check_log_does_not_have "Please go to this URL and login:" ${case_name}.log # There should be no login prompts for run2!
122+
# From save_tokens
123+
check_log_does_not_have "INFO: Tokens saved successfully" ${case_name}.log # Differs from run1
124+
125+
# This part replaces the original test_globus.py `testLs` function.
126+
zstash ls --hpss=${DST_DIR}/run1 2>&1 | tee run1_ls.log
127+
check_log_has "file_empty.txt" run1_ls.log
128+
check_log_has "dir/file0.txt" run1_ls.log
129+
check_log_has "empty_dir" run1_ls.log
130+
zstash ls --hpss=${DST_DIR}/run2 2>&1 | tee run2_ls.log
131+
check_log_has "file_empty.txt" run2_ls.log
132+
check_log_has "dir/file0.txt" run2_ls.log
133+
check_log_has "empty_dir" run2_ls.log
134+
# Could also test -l and -v options, but the above code covers the important part.
135+
}
136+
137+
run_test_cases

tests/test_globus.py

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

0 commit comments

Comments
 (0)