-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlaunch-oraclelinux.sh
More file actions
executable file
·260 lines (223 loc) · 7.1 KB
/
launch-oraclelinux.sh
File metadata and controls
executable file
·260 lines (223 loc) · 7.1 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
#
# Copyright (C) 2023, RTE (http://www.rte-france.com)
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# 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="git@github.com:seapath"
fi
if [ -z "${REPO_PRIVATE_KEYFILE}" ] ; then
REPO_PRIVATE_KEYFILE=inventories_private/ci_rsa
fi
if [ -z "${INVENTORY_VM}" ] ; then
INVENTORY_VM=inventories_private/vm.yml
fi
if [ -z "${ANSIBLE_INVENTORY}" ] ; then
ANSIBLE_INVENTORY="inventories_private/seapath_cluster_ci.yml,inventories_private/seapath_standalone_rt.yml"
fi
CQFD_EXTRA_RUN_ARGS="-e ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY}"
# 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|vm|report>
DESCRIPTION:
- init : download and prepare the sources.
- conf : configure the OracleLinux OS to build SEAPATH.
- system : launch system tests and gather results.
- vm : launch tests inside a virtual machine in the cluster.
- 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 OracleLinux configuration and hardening
configure_ol() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--limit 'all:!ci-tool' \
playbooks/ci_configure.yaml
echo "OracleLinux 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}" \
--limit 'all:!ci-tool' \
playbooks/ci_test.yaml
echo "System tests launched successfully"
# Move tests results to test-report-pdf directory
INCLUDE_DIR=${WORK_DIR}/ci/test-report-pdf/include
mkdir "$INCLUDE_DIR"
mv ${WORK_DIR}/ansible/cukinia_*.xml $INCLUDE_DIR # Test files
# 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
grep FAIL $INCLUDE_DIR/*.xml || true
echo "Test fails, See associated test report"
exit 1
else
echo "All tests pass"
exit 0
fi
}
# Deploy a Virtual machine on the cluster and launch cukinia tests in it.
# Fetch results
launch_vm_tests() {
cd ansible
# Add VM inventory file
# This file cannot be added at the beginnig of launch.sh cause it is used
# only during thes step
ANSIBLE_INVENTORY_VM="${ANSIBLE_INVENTORY},${INVENTORY_VM_CLUSTER}"
CQFD_EXTRA_RUN_ARGS="${CQFD_EXTRA_RUN_ARGS} -e ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY_VM} -v /etc/seapath-ci/vm_file:${WORK_DIR}/ansible/vm_images"
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
playbooks/deploy_vms_cluster.yaml
echo "test VM deployed successfully on cluster"
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--limit VMs \
playbooks/seapath_setup_prerequisdebian.yaml \
playbooks/seapath_setup_hardened_debian.yaml \
playbooks/ci_prepare_VMs.yaml
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--limit VMs \
playbooks/ci_test.yaml
ANSIBLE_INVENTORY_VM="${ANSIBLE_INVENTORY},${INVENTORY_VM_STANDALONE}"
CQFD_EXTRA_RUN_ARGS="${CQFD_EXTRA_RUN_ARGS} -e ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY_VM} -v /etc/seapath-ci/vm_file:${WORK_DIR}/ansible/vm_images"
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
playbooks/deploy_vms_standalone.yaml
echo "test VM deployed successfully on standalone"
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--limit VMs \
playbooks/seapath_setup_prerequisdebian.yaml \
playbooks/seapath_setup_hardened_debian.yaml \
playbooks/ci_prepare_VMs.yaml
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--limit VMs \
playbooks/ci_test.yaml
# Move VM test results to test-report-pdf
INCLUDE_DIR=${WORK_DIR}/ci/test-report-pdf/include
mv ${WORK_DIR}/ansible/cukinia_*.xml $INCLUDE_DIR # Test files
# Display test results
if grep '<failure' $INCLUDE_DIR/*.xml | grep -q -v '00080'; then
grep FAIL $INCLUDE_DIR/*.xml || true
echo "Test fails, See associated test report"
exit 1
else
echo "All tests pass"
exit 0
fi
}
# Generate the test report
generate_report() {
cd "${WORK_DIR}/ci/test-report-pdf"
# Replace test-report-pdf default logo by SEAPATH one
mv ../seapath-themes/logo.png themes/sfl.png
sed -i 's/contact@savoirfairelinux/florent.carli@rte-france.com/g' test-report.adoc
# Change contact mailing list to seapath SFL mailing list
# Generate test report
cqfd -q init
if ! CQFD_EXTRA_RUN_ARGS="" cqfd -q run ./compile.py \
-m -i include -C SEAPATH -p \"SEAPATH OracleLinux\" ; then
die "cqfd error"
fi
echo "Test report generated successfully"
mv "${WORK_DIR}"/ci/test-report-pdf/test-report.pdf "${WORK_DIR}"/seapath-test-report.pdf
}
case "$1" in
init)
initialization
exit 0
;;
conf)
configure_ol
exit 0
;;
system)
launch_system_tests
exit 0
;;
vm)
launch_vm_tests
exit 0
;;
latency)
launch_latency_tests
exit 0
;;
report)
generate_report
exit 0
;;
*)
usage
die "Unknown command"
;;
esac