Skip to content

Commit 4adf8df

Browse files
authored
Merge pull request #293 from flatcar-linux/krnowak/ciauto-boilerplate
ci-automation: Reduce boilerplate in vendor tests
2 parents 36d72c4 + d26f2b3 commit 4adf8df

File tree

6 files changed

+197
-135
lines changed

6 files changed

+197
-135
lines changed

ci-automation/test.sh

+23-7
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@
6060
# torcx tarball on the build cache (for the docker.torcx-manifest-pkgs test).
6161
#
6262
# Vendor specific scripts are called with the following positional arguments:
63-
# 1 - working directory for the tests.
63+
# 1 - Toplevel tests directory
64+
# It contains some additional files needed for running the tests (like torcx manifest or file with channel information).
65+
# 2 - Working directory for the tests.
6466
# The vendor script is expected to keep all artifacts it produces in that directory.
65-
# 2 - Architecture to test.
66-
# 3 - version number to test.
67-
# 4 - output TAP file.
67+
# 3 - Architecture to test.
68+
# 4 - Version number to test.
69+
# 5 - Output TAP file.
6870
# All following arguments specify test cases / test case patterns to run.
71+
#
72+
# The vendor tests should source ci-automation/vendor_test.sh script
73+
# as a first step - it will do some common steps that the vendor
74+
# script would need to make anyway. For more information, please refer
75+
# to the vendor_test.sh file.
6976

7077
set -euo pipefail
7178

@@ -107,6 +114,7 @@ function test_run() {
107114

108115
source ci-automation/tapfile_helper_lib.sh
109116
source ci-automation/ci_automation_common.sh
117+
source sdk_lib/sdk_container_common.sh
110118
init_submodules
111119

112120
source sdk_container/.repo/manifests/version.txt
@@ -118,6 +126,13 @@ function test_run() {
118126
local tests_dir="${work_dir}/${image}"
119127
mkdir -p "${tests_dir}"
120128

129+
# Store git version and git channel as files inside ${work_dir}.
130+
# This information might not be available inside the docker
131+
# container if this directory is not a main git repo, but rather a
132+
# git worktree.
133+
get_git_version >"${work_dir}/git_version"
134+
get_git_channel >"${work_dir}/git_channel"
135+
121136
local container_name="flatcar-tests-${arch}-${docker_vernum}-${image}"
122137
local mantle_ref
123138
mantle_ref=$(cat sdk_container/.repo/manifests/mantle-container)
@@ -137,17 +152,18 @@ function test_run() {
137152

138153
# Ignore retcode since tests are flaky. We'll re-run failed tests and
139154
# determine success based on test results (tapfile).
140-
set +e -o noglob
155+
set +e
141156
touch sdk_container/.env
142157
docker run --pull always --rm --name="${container_name}" --privileged --net host -v /dev:/dev \
143158
-w /work -v "$PWD":/work "${mantle_ref}" \
144-
bash -c "set -o noglob && source sdk_container/.env && ci-automation/vendor-testing/\"${image}\".sh \
159+
bash -c "set -o noglob && source sdk_container/.env && ci-automation/vendor-testing/${image}.sh \
160+
\"${work_dir}\" \
145161
\"${tests_dir}\" \
146162
\"${arch}\" \
147163
\"${vernum}\" \
148164
\"${tapfile}\" \
149165
$@"
150-
set -e +o noglob
166+
set -e
151167

152168
docker run --pull always --rm --name="${container_name}" --privileged --net host -v /dev:/dev \
153169
-w /work -v "$PWD":/work "${mantle_ref}" \

ci-automation/vendor-testing/equinix_metal.sh

+11-25
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,37 @@
66
set -euo pipefail
77

88
# Test execution script for the Equinix Metal vendor image.
9-
# This script is supposed to run in the SDK container.
9+
# This script is supposed to run in the mantle container.
1010
# This script requires "pxe" Jenkins job.
1111

12-
work_dir="$1"; shift
13-
arch="$1"; shift
14-
vernum="$1"; shift
15-
tapfile="$1"; shift
16-
17-
# $@ now contains tests / test patterns to run
18-
19-
source ci-automation/ci_automation_common.sh
20-
# required for get_git_channel
21-
source sdk_lib/sdk_container_common.sh
22-
23-
channel="$(get_git_channel)"
24-
25-
mkdir -p "${work_dir}"
26-
cd "${work_dir}"
12+
source ci-automation/vendor_test.sh
2713

2814
# Equinix Metal ARM server are not yet hourly available in the default `SV` metro
29-
equinixmetal_metro_var="EQUINIXMETAL_${arch}_METRO"
15+
equinixmetal_metro_var="EQUINIXMETAL_${CIA_ARCH}_METRO"
3016
equinixmetal_metro="${!equinixmetal_metro_var}"
3117

32-
EQUINIXMETAL_INSTANCE_TYPE_VAR="EQUINIXMETAL_${arch}_INSTANCE_TYPE"
18+
EQUINIXMETAL_INSTANCE_TYPE_VAR="EQUINIXMETAL_${CIA_ARCH}_INSTANCE_TYPE"
3319
EQUINIXMETAL_INSTANCE_TYPE="${!EQUINIXMETAL_INSTANCE_TYPE_VAR}"
34-
MORE_INSTANCE_TYPES_VAR="EQUINIXMETAL_${arch}_MORE_INSTANCE_TYPES"
20+
MORE_INSTANCE_TYPES_VAR="EQUINIXMETAL_${CIA_ARCH}_MORE_INSTANCE_TYPES"
3521
MORE_INSTANCE_TYPES=( ${!MORE_INSTANCE_TYPES_VAR} )
3622

3723
# The maximum is 6h coming from the ore GC duration parameter
3824
timeout=6h
3925

40-
BASE_URL="http://${BUILDCACHE_SERVER}/images/${arch}/${vernum}"
26+
BASE_URL="http://${BUILDCACHE_SERVER}/images/${CIA_ARCH}/${CIA_VERNUM}"
4127

4228
run_equinix_metal_kola_test() {
4329
local instance_type="${1}"
4430
local instance_tapfile="${2}"
4531

4632
timeout --signal=SIGQUIT "${timeout}" \
4733
kola run \
48-
--board="${arch}-usr" \
49-
--basename="ci-${vernum/+/-}" \
34+
--board="${CIA_ARCH}-usr" \
35+
--basename="ci-${CIA_VERNUM/+/-}" \
5036
--platform=equinixmetal \
5137
--tapfile="${instance_tapfile}" \
5238
--parallel="${EQUINIXMETAL_PARALLEL}" \
53-
--torcx-manifest=../torcx_manifest.json \
39+
--torcx-manifest="${CIA_TORCX_MANIFEST}" \
5440
--equinixmetal-image-url="${BASE_URL}/${EQUINIXMETAL_IMAGE_NAME}" \
5541
--equinixmetal-installer-image-kernel-url="${BASE_URL}/${PXE_KERNEL_NAME}" \
5642
--equinixmetal-installer-image-cpio-url="${BASE_URL}/${PXE_IMAGE_NAME}" \
@@ -109,11 +95,11 @@ fi
10995
ARGS="$*"
11096
if [[ -n "${ARGS// }" ]]; then
11197
set -x
112-
run_equinix_metal_kola_test "${EQUINIXMETAL_INSTANCE_TYPE}" "${tapfile}" "${@}"
98+
run_equinix_metal_kola_test "${EQUINIXMETAL_INSTANCE_TYPE}" "${CIA_TAPFILE}" "${@}"
11399
set +x
114100
fi
115101

116102
if [[ "${run_more_tests}" -eq 1 ]]; then
117103
wait
118-
cat validate_*.tap >>"${tapfile}"
104+
cat validate_*.tap >>"${CIA_TAPFILE}"
119105
fi

ci-automation/vendor-testing/gce.sh

+17-34
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,43 @@ set -euo pipefail
88
# Test execution script for the GCE vendor image.
99
# This script is supposed to run in the mantle container.
1010

11-
work_dir="$1"; shift
12-
arch="$1"; shift
13-
vernum="$1"; shift
14-
tapfile="$1"; shift
15-
16-
# $@ now contains tests / test patterns to run
17-
18-
source ci-automation/ci_automation_common.sh
19-
source sdk_lib/sdk_container_common.sh
20-
21-
mkdir -p "${work_dir}"
22-
cd "${work_dir}"
11+
source ci-automation/vendor_test.sh
2312

2413
# We never run GCE on arm64, so for now fail it as an
2514
# unsupported option.
26-
if [[ "${arch}" == "arm64" ]]; then
27-
echo "1..1" > "${tapfile}"
28-
echo "not ok - all GCE tests" >> "${tapfile}"
29-
echo " ---" >> "${tapfile}"
30-
echo " ERROR: ARM64 tests not supported on GCE." | tee -a "${tapfile}"
31-
echo " ..." >> "${tapfile}"
15+
if [[ "${CIA_ARCH}" == "arm64" ]]; then
16+
echo "1..1" > "${CIA_TAPFILE}"
17+
echo "not ok - all GCE tests" >> "${CIA_TAPFILE}"
18+
echo " ---" >> "${CIA_TAPFILE}"
19+
echo " ERROR: ARM64 tests not supported on GCE." | tee -a "${CIA_TAPFILE}"
20+
echo " ..." >> "${CIA_TAPFILE}"
3221
exit 1
3322
fi
3423

35-
channel="$(get_git_channel)"
36-
if [[ "${channel}" = 'developer' ]]; then
37-
channel='alpha'
38-
fi
39-
testscript="$(basename "$0")"
40-
4124
# Create temp file and delete it immediately
4225
echo "${GCP_JSON_KEY}" | base64 --decode > /tmp/gcp_auth
4326
exec {gcp_auth}</tmp/gcp_auth
4427
rm /tmp/gcp_auth
4528
GCP_JSON_KEY_PATH="/proc/$$/fd/${gcp_auth}"
4629

47-
copy_from_buildcache "images/${arch}/${vernum}/${GCE_IMAGE_NAME}" .
30+
copy_from_buildcache "images/${CIA_ARCH}/${CIA_VERNUM}/${GCE_IMAGE_NAME}" .
4831
gcloud auth activate-service-account --key-file "${GCP_JSON_KEY_PATH}"
49-
gsutil rm -r "${GCE_GCS_IMAGE_UPLOAD}/${arch}-usr/${vernum}" || true
50-
gsutil cp "${GCE_IMAGE_NAME}" "${GCE_GCS_IMAGE_UPLOAD}/${arch}-usr/${vernum}/${GCE_IMAGE_NAME}"
32+
gsutil rm -r "${GCE_GCS_IMAGE_UPLOAD}/${CIA_ARCH}-usr/${CIA_VERNUM}" || true
33+
gsutil cp "${GCE_IMAGE_NAME}" "${GCE_GCS_IMAGE_UPLOAD}/${CIA_ARCH}-usr/${CIA_VERNUM}/${GCE_IMAGE_NAME}"
5134
family="ci"
52-
image_name="${family}-${vernum//[+.]/-}"
35+
image_name="${family}-${CIA_VERNUM//[+.]/-}"
5336
ore gcloud delete-images --json-key="${GCP_JSON_KEY_PATH}" "${image_name}" || true
5437
ore gcloud create-image \
55-
--board="${arch}-usr" \
38+
--board="${CIA_ARCH}-usr" \
5639
--family="${family}" \
5740
--json-key="${GCP_JSON_KEY_PATH}" \
5841
--source-root="${GCE_GCS_IMAGE_UPLOAD}" \
5942
--source-name="${GCE_IMAGE_NAME}" \
60-
--version="${vernum}"
43+
--version="${CIA_VERNUM}"
6144

6245
trap 'ore gcloud delete-images \
6346
--json-key="${GCP_JSON_KEY_PATH}" \
64-
"${image_name}" ; gsutil rm -r "${GCE_GCS_IMAGE_UPLOAD}/${arch}-usr/${vernum}" || true' EXIT
47+
"${image_name}" ; gsutil rm -r "${GCE_GCS_IMAGE_UPLOAD}/${CIA_ARCH}-usr/${CIA_VERNUM}" || true' EXIT
6548

6649
set -x
6750

@@ -73,9 +56,9 @@ timeout --signal=SIGQUIT 6h \
7356
--gce-machinetype="${GCE_MACHINE_TYPE}" \
7457
--parallel="${GCE_PARALLEL}" \
7558
--platform=gce \
76-
--channel="${channel}" \
77-
--tapfile="${tapfile}" \
78-
--torcx-manifest='../torcx_manifest.json' \
59+
--channel="${CIA_CHANNEL}" \
60+
--tapfile="${CIA_TAPFILE}" \
61+
--torcx-manifest="${CIA_TORCX_MANIFEST}" \
7962
"${@}"
8063

8164
set +x

ci-automation/vendor-testing/qemu.sh

+21-35
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,49 @@
66
set -euo pipefail
77

88
# Test execution script for the qemu vendor image.
9-
# This script is supposed to run in the SDK container.
9+
# This script is supposed to run in the mantle container.
1010

11-
work_dir="$1"; shift
12-
arch="$1"; shift
13-
vernum="$1"; shift
14-
tapfile="$1"; shift
15-
16-
# $@ now contains tests / test patterns to run
17-
18-
source ci-automation/ci_automation_common.sh
19-
20-
mkdir -p "${work_dir}"
21-
cd "${work_dir}"
22-
23-
testscript="$(basename "$0")"
11+
source ci-automation/vendor_test.sh
2412

2513
# ARM64 qemu tests only supported on UEFI
26-
if [ "${arch}" = "arm64" ] && [ "${testscript}" != "qemu_uefi.sh" ] ; then
27-
echo "1..1" > "${tapfile}"
28-
echo "not ok - all qemu tests" >> "${tapfile}"
29-
echo " ---" >> "${tapfile}"
30-
echo " ERROR: ARM64 tests only supported on qemu_uefi." | tee -a "${tapfile}"
31-
echo " ..." >> "${tapfile}"
14+
if [ "${CIA_ARCH}" = "arm64" ] && [ "${CIA_TESTSCRIPT}" != "qemu_uefi.sh" ] ; then
15+
echo "1..1" > "${CIA_TAPFILE}"
16+
echo "not ok - all qemu tests" >> "${CIA_TAPFILE}"
17+
echo " ---" >> "${CIA_TAPFILE}"
18+
echo " ERROR: ARM64 tests only supported on qemu_uefi." | tee -a "${CIA_TAPFILE}"
19+
echo " ..." >> "${CIA_TAPFILE}"
3220
exit 1
3321
fi
3422

3523
# Fetch image and BIOS if not present
3624
if [ -f "${QEMU_IMAGE_NAME}" ] ; then
37-
echo "++++ ${testscript}: Using existing ${work_dir}/${QEMU_IMAGE_NAME} for testing ${vernum} (${arch}) ++++"
25+
echo "++++ ${CIA_TESTSCRIPT}: Using existing ./${QEMU_IMAGE_NAME} for testing ${CIA_VERNUM} (${CIA_ARCH}) ++++"
3826
else
39-
echo "++++ ${testscript}: downloading ${QEMU_IMAGE_NAME} for ${vernum} (${arch}) ++++"
40-
copy_from_buildcache "images/${arch}/${vernum}/${QEMU_IMAGE_NAME}" .
27+
echo "++++ ${CIA_TESTSCRIPT}: downloading ${QEMU_IMAGE_NAME} for ${CIA_VERNUM} (${CIA_ARCH}) ++++"
28+
copy_from_buildcache "images/${CIA_ARCH}/${CIA_VERNUM}/${QEMU_IMAGE_NAME}" .
4129
fi
4230

4331
bios="${QEMU_BIOS}"
44-
if [ "${testscript}" = "qemu_uefi.sh" ] ; then
32+
if [ "${CIA_TESTSCRIPT}" = "qemu_uefi.sh" ] ; then
4533
bios="${QEMU_UEFI_BIOS}"
4634
if [ -f "${bios}" ] ; then
47-
echo "++++ ${testscript}: Using existing ${work_dir}/${bios} ++++"
35+
echo "++++ ${CIA_TESTSCRIPT}: Using existing ./${bios} ++++"
4836
else
49-
echo "++++ ${testscript}: downloading ${bios} for ${vernum} (${arch}) ++++"
50-
copy_from_buildcache "images/${arch}/${vernum}/${bios}" .
37+
echo "++++ ${CIA_TESTSCRIPT}: downloading ${bios} for ${CIA_VERNUM} (${CIA_ARCH}) ++++"
38+
copy_from_buildcache "images/${CIA_ARCH}/${CIA_VERNUM}/${bios}" .
5139
fi
5240
fi
5341

5442
set -x
55-
set -o noglob
5643

57-
sudo kola run \
58-
--board="${arch}-usr" \
44+
kola run \
45+
--board="${CIA_ARCH}-usr" \
5946
--parallel="${QEMU_PARALLEL}" \
6047
--platform=qemu \
61-
--qemu-bios=${bios} \
48+
--qemu-bios="${bios}" \
6249
--qemu-image="${QEMU_IMAGE_NAME}" \
63-
--tapfile="${tapfile}" \
64-
--torcx-manifest=../torcx_manifest.json \
65-
$@
50+
--tapfile="${CIA_TAPFILE}" \
51+
--torcx-manifest="${CIA_TORCX_MANIFEST}" \
52+
"${@}"
6653

67-
set +o noglob
6854
set +x

0 commit comments

Comments
 (0)