forked from underground-software/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-lib
More file actions
195 lines (166 loc) · 4.9 KB
/
test-lib
File metadata and controls
195 lines (166 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# This line:
# - aborts the script after any pipeline returns nonzero (e)
# - shows all commands as they are run (x)
# - sets any dereference of an unset variable to trigger an error (u)
# - enables job control (m)
# - causes the return value of a pipeline to be the nonzero return value
# of the furthest right failing command or zero if no command failed (o pipefail)
set -exumo pipefail
PODMAN=${PODMAN:-podman}
PODMAN_COMPOSE=${PODMAN_COMPOSE:-podman-compose}
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
WORKDIR=$(mktemp -d)
PINP_CONFIG='-c user.name=PINP -c user.email=podman@podman'
HOSTNAME_FROM_DOTENV="$(sh -c '
set -o allexport
. ./.env
exec jq -r -n "env.SINGULARITY_HOSTNAME"
')"
SINGULARITY_HOSTNAME=${SINGULARITY_HOSTNAME:-"${HOSTNAME_FROM_DOTENV}"}
setup_testdir() {
# Create test dir if it does not exist yet
mkdir -p test
# Reset the test directory
rm -f test/*
# put the cert in there
${PODMAN} cp singularity_nginx_1:/etc/ssl/nginx/fullchain.pem test/ca_cert.pem
}
CURL_OPTS=( \
--verbose \
--cacert test/ca_cert.pem \
--fail \
--no-progress-meter \
)
get_git_port() { pushd "$SCRIPT_DIR" > /dev/null ; podman-compose port git 8000 ; popd > /dev/null ; } ;
# preconditions:
# - SCRIPT_DIR defined (singularity repo root)
# - WORKDIR defined (arbitrary) temp directory
setup_submissions_and_grading_repo() {
pushd "$SCRIPT_DIR"
# crete and push fresh submissions repo
rm -rf repos/submissions
git/admin.sh submissions "course submissions repository"
pushd repos
git init --bare submissions
echo "course submissions repository" > submissions/description
# create a temporary workdir to push an initial commit to the submission repo
git init submissions_init
pushd submissions_init
echo "# submissions" > README.md
git add README.md
git status
git -c user.name=singularity -c user.email=singularity@singularity commit -sm 'init submissions repo'
git push ../submissions master
popd
rm -rf submissions_init
pushd submissions
git push --mirror http://localhost:"$(get_git_port)"/cgi-bin/git-receive-pack/submissions
popd
popd
popd
pushd "$WORKDIR"
mkdir certs
pushd certs
${PODMAN} volume export singularity_ssl-certs > certs.tar
tar xf certs.tar
popd
git clone http://localhost:"$(get_git_port)"/submissions
popd
}
# create or recreate dummy assignment
create_dummy_assignment() {
test -n "$1"
local asn="$1"
pushd "$SCRIPT_DIR"
if denis/configure.sh dump | grep -q "^$asn:"; then
denis/configure.sh remove -a "$asn"
fi
denis/configure.sh dummy -a "$asn"
popd
}
# create or recreate dummy assignment
trigger_deadline() {
test -n "$1"
test -n "$2"
local asn="$1"
local cmp="$2"
pushd "$SCRIPT_DIR"
denis/configure.sh trigger -a "$asn" -c "$cmp"
if [ "$cmp" == "peer" ]; then
cmp="$cmp review"
fi
podman-compose logs -f denis | ( sed "/completed $asn assignment processing for $cmp submission deadline/ q" && kill 0 ) || true
popd
}
# preconditions:
# - called after setup_submissions_and_grading_repo
setup_submissions_for() {
test -n "$1"
local user="$1"
pushd "$SCRIPT_DIR"
orbit/warpdrive.sh -u "$user" -f "$user" -p builder -n || orbit/warpdrive.sh -u "$user" -f "$user" -p builder -m
popd
pushd "$WORKDIR"/submissions
git config user.name "$user"
git config user.email "$user"@localhost.localdomain
git config sendemail.smtpUser "$user"
git config sendemail.smtpPass builder
git config sendemail.smtpserver localhost.localdomain
git config sendemail.smtpserverport 1465
git config sendemail.smtpencryption ssl
popd
}
# preconditions:
# - no non-tracked files in submissions repo
# - called after setup_submissions_for
enter_and_checkout() {
test -n "$1"
local branch="$1"
pushd "$WORKDIR"/submissions
git checkout --orphan "$1"
if [ -n "$(ls)" ]
then
git rm -rf ./*
fi
}
# preconditions:
# - called after a call to enter_and_checkout
exit_after_sending() {
test -n "$1"
local asn="$1"
git send-email \
--confirm=never \
--smtp-ssl-cert-path="$WORKDIR"/certs/fullchain.pem \
--to "$asn"@localhost.localdomain \
./*.patch | tee "$WORKDIR"/last_email
last_id=$(grep -m 1 "Message-ID" "$WORKDIR"/last_email)
rm ./*.patch
popd
podman-compose logs -f mailman | ( sed "/finished processing $last_id/ q" && kill 0 ) || true
}
# preconditions:
# - called after a call to enter_and_checkout
write_commit_to() {
test -n "$1" && test -n "$2"
local content="$1"
local file="$2"
set +u # necessary since $3 is unbound in 2 arg case
local opt="$3"
set -x
mkdir -p $(dirname "$file")
if [ "$opt" == "append" ]; then
echo "$content" >> "$file"
else
echo "$content" > "$file"
fi
git add "$file"
git commit -sm "add $content to $file"
}
# preconditions:
# - called after a call to write_commit_to
fixup_cover() {
test -n "$1"
sed -i "s/\*\*\* SUBJECT HERE \*\*\*/$1/g" *0000-cover-letter.patch
sed -i "s/\*\*\* BLURB HERE \*\*\*/$1/g" *0000-cover-letter.patch
sed -i "\$a\\Signed-off-by: $(git config user.name) <$(git config user.email)>" *0000-cover-letter.patch
}