forked from seapath/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.sh
executable file
·236 lines (205 loc) · 6.55 KB
/
launch.sh
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
#
# Copyright (C) 2023, RTE (http://www.rte-france.com)
# SPDX-License-Identifier: Apache-2.0
#
# This script download the sources of a specific pull request,
# then test it and upload a report given the test results.
if [ "${RUNNER_DEBUG}" == "1" ] ; then
set -x
fi
set -e
die() {
echo "CI internal failure : $@" 1>&2
exit 1
}
# Source CI configuration file
# This file must at least define the PRIVATE_INVENTORIES_REPO_URL variable
source /etc/seapath-ci.conf
if [ -z "${PRIVATE_INVENTORIES_REPO_URL}" ] ; then
die "PRIVATE_INVENTORIES_REPO_URL not defined!"
fi
# default variables
if [ -z "${SEAPATH_BASE_REPO}" ] ; then
SEAPATH_BASE_REPO="github.com/seapath"
fi
if [ -z "${SEAPATH_SSH_BASE_REPO}" ] ; then
SEAPATH_SSH_BASE_REPO="[email protected]:seapath"
fi
if [ -z "${REPO_PRIVATE_KEYFILE}" ] ; then
REPO_PRIVATE_KEYFILE=inventories_private/ci_rsa
fi
if [ -z "${ANSIBLE_INVENTORY}" ] ; then
ANSIBLE_INVENTORY="inventories_private/seapath_cluster_ci.yml,inventories_private/seapath_standalone_rt.yml"
fi
if [ -z "${SVTOOLS_TARBALL}" ] ; then
SVTOOLS_TARBALL="/home/virtu/ci-latency-tools/IEC61850_svtools/"
fi
if [ -z "${TRAFGEN_TARBALL}" ] ; then
TRAFGEN_TARBALL="/home/virtu/ci-latency-tools/sv_generator/"
fi
CQFD_EXTRA_RUN_ARGS="-e ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY} -v ${SVTOOLS_TARBALL}:$WORK_DIR/ansible/src/svtools/ -v ${TRAFGEN_TARBALL}:$WORK_DIR/ansible/src/trafgen/"
# If REPO_PRIVATE_KEYFILE is an absolute path bind it inside cqfd
if [[ "${REPO_PRIVATE_KEYFILE}" == /* ]] ; then
CQFD_EXTRA_RUN_ARGS="${CQFD_EXTRA_RUN_ARGS} -v $REPO_PRIVATE_KEYFILE:/tmp/ci_ssh_key "
PRIVATE_KEYFILE_PATH=/tmp/ci_ssh_key
else
PRIVATE_KEYFILE_PATH="${REPO_PRIVATE_KEYFILE}"
fi
if [ -n "${CA_DIR}" ] ; then
CQFD_EXTRA_RUN_ARGS="${CQFD_EXTRA_RUN_ARGS} -v ${CA_DIR}:$WORK_DIR/ansible/src/ca"
fi
export CQFD_EXTRA_RUN_ARGS
# Standard help message
usage()
{
cat <<EOF
This script is the main launcher for the SEAPATH CI.
It is separated in many functions in order to display logs properly.
They should be called one after another.
USAGE:
./launch.sh <init|conf|system|latency|report>
DESCRIPTION:
- init : download and prepare the sources.
- conf : configure the debian OS to build SEAPATH.
- system : launch system tests and gather results.
- latency: launch latency tests and gather results.
- report: build and upload the test report.
EOF
}
# Download and prepare the pull request sources
initialization() {
if ! type -p cqfd > /dev/null; then
die "cqfd not found"
fi
# Get sources
git clone -q "https://${SEAPATH_BASE_REPO}/ansible"
cd ansible
git fetch -q origin "${GITHUB_REF}"
git checkout -q FETCH_HEAD
echo "Pull request sources got succesfully"
# Get inventories
git clone -q "${PRIVATE_INVENTORIES_REPO_URL}" inventories_private
chmod 600 "${PRIVATE_KEYFILE_PATH}"
# Prepare ansible repository
cqfd init
cqfd -b prepare
echo "Sources prepared succesfully"
}
# Launch Debian configuration and hardening
configure_debian() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--skip-tags "package-install" \
playbooks/ci_configure.yaml
echo "Debian set up succesfully"
}
# Prepare and launch cukinia test
# Send the result of the tests as return code
launch_system_tests() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--skip-tags "package-install" \
playbooks/ci_test.yaml
echo "System tests launched successfully"
# Generate test report part
INCLUDE_DIR=${WORK_DIR}/ci/report-generator/include
mkdir "$INCLUDE_DIR"
mv ${WORK_DIR}/ansible/*.xml $INCLUDE_DIR # Test files
cp ${WORK_DIR}/ansible/src/cukinia-tests/*.csv $INCLUDE_DIR # Compliance matrix
cd ${WORK_DIR}/ci/report-generator
cqfd -q init
if ! cqfd -q -b generate_test_part; then
die "cqfd error"
fi
# Check for kernel backtrace error. This is a random error so it must not
# stop the CI but just display a warning
# See https://github.com/seapath/ansible/issues/164
if grep '<failure' $INCLUDE_DIR/*.xml | grep -q '00080'; then
echo -e "\033[0;33mWarning :\033[0m kernel back trace detected, see \
https://github.com/seapath/ansible/issues/164"
fi
# Display test results
if grep '<failure' $INCLUDE_DIR/*.xml | grep -q -v '00080'; then
echo "Test fails, See test report in the section 'Upload test report'"
exit 1
else
echo "All tests pass"
exit 0
fi
}
# Deploy subscriber and publisher, generate SV and measure latency time
launch_latency_tests() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--skip-tags "package-install" \
playbooks/test_run_latency_tests.yaml
# Generate latency report part
LATENCY_TEST_DIR="${WORK_DIR}/latency"
mkdir $LATENCY_TEST_DIR
mv -v ${WORK_DIR}/ansible/tests_results/* $LATENCY_TEST_DIR
cd ${WORK_DIR}/ci/report-generator
if ! CQFD_EXTRA_RUN_ARGS="-v $LATENCY_TEST_DIR:/tmp/tests_results" \
cqfd -q -b generate_latency_part; then
die "cqfd error"
fi
echo "See latency report in the section 'Upload test report'"
# TODO : Add return value : false if we exceed max latency
}
# Generate the test report and upload it
generate_report() {
# Generate pdf
cd "${WORK_DIR}/ci/report-generator"
if ! CQFD_EXTRA_RUN_ARGS="" cqfd -q run; then
die "cqfd error"
fi
echo "Test report generated successfully"
# Upload report
PR_N=`echo $GITHUB_REF | cut -d '/' -f 3`
TIME=`date +%F_%Hh%Mm%S`
REPORT_NAME="test-report_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}_${TIME}.pdf"
REPORT_DIR="${WORK_DIR}/reports/docs/reports/PR-${PR_N}"
git clone -q --depth 1 -b reports "${SEAPATH_SSH_BASE_REPO}/ci.git" \
--config core.sshCommand="ssh -i ~/.ssh/ci_rsa" "$WORK_DIR/reports"
mkdir -p "$REPORT_DIR"
mv "${WORK_DIR}"/ci/report-generator/test-report.pdf "$REPORT_DIR/$REPORT_NAME"
cd "$REPORT_DIR"
git config --local user.email "[email protected]"
git config --local user.name "Seapath CI"
git config --local core.sshCommand "ssh -i ~/.ssh/ci_rsa"
git add "$REPORT_NAME"
git commit -q -m "upload report $REPORT_NAME"
git push -q origin reports
echo "Test report uploaded successfully"
echo See test Report at \
"https://${SEAPATH_BASE_REPO}/ci/blob/reports/docs/reports/PR-${PR_N}/${REPORT_NAME}"
}
case "$1" in
init)
initialization
exit 0
;;
conf)
configure_debian
exit 0
;;
system)
launch_system_tests
exit 0
;;
latency)
launch_latency_tests
exit 0
;;
report)
generate_report
exit 0
;;
*)
usage
die "Unknown command"
;;
esac