From fdb08f17cc1161fb1fdd2c7ec94714dc4709b430 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 11 Jan 2023 14:57:45 +0100 Subject: [PATCH] ci-automation: Test vendor --- ci-automation/vendor-testing/test-kola.sh | 181 ++++++++++++++++++++++ ci-automation/vendor-testing/test.sh | 55 +++++++ 2 files changed, 236 insertions(+) create mode 100755 ci-automation/vendor-testing/test-kola.sh create mode 100755 ci-automation/vendor-testing/test.sh diff --git a/ci-automation/vendor-testing/test-kola.sh b/ci-automation/vendor-testing/test-kola.sh new file mode 100755 index 0000000000..08ccb8c836 --- /dev/null +++ b/ci-automation/vendor-testing/test-kola.sh @@ -0,0 +1,181 @@ +#!/bin/bash + +set -euo pipefail + +msg() { + printf 'test-kola.sh: %s\n' "$*" +} + +fail() { + msg "$*" >&2 + exit 1 +} + +if [[ ${#} -eq 0 ]]; then + fail "needs to be run with either 'run' or 'list' command" +fi + +all_tests=( + 'fail.setup' + 'fail.kola' + 'fail.timeout' + 'cl.internet' + 'cl.basic' +) + +new_args=() +for arg; do + if [[ "${arg}" = --*=* ]]; then + value="${arg#*=}" + arg="${arg%%=*}" + new_args+=( "${arg}" "${value}" ) + else + new_args+=( "${arg}" ) + fi +done + +set -- "${new_args[@]}" + +case "${1}" in + list) + shift + platform='' + filter=0 + while [[ "${#}" -gt 0 ]]; do + case "${1}" in + --platform) + platform="${2}" + shift 2 + ;; + --filter) + filter=1 + shift + ;; + --*) + fail "unknown flag '${1}' for list" + ;; + *) + break + ;; + esac + done + if [[ "${platform}" != 'test' ]]; then + fail "wrong platform '${platform}', should be 'test'" + fi + if [[ "${filter}" -eq 0 ]]; then + fail 'missing --filter flag' + fi + print_all=0 + if [[ "${#}" -eq 0 ]]; then + print_all=1 + elif [[ "${#}" -eq 1 ]] && [[ "${1}" = '*' ]]; then + print_all=1 + fi + printf 'headers line\nempty line\n' + if [[ ${print_all} -eq 1 ]]; then + printf '%s\n' "${all_tests[@]}" + else + for test_name; do + for known_test_name in "${all_tests[@]}"; do + if [[ "${test_name}" = "${known_test_name}" ]]; then + printf '%s\n' "${test_name}" + fi + done + done + fi + exit 0 + ;; + run) + shift + board='' + channel='' + tapfile='' + torcx_manifest='' + platform='' + parallel='0' + fail=-0 + while [[ "${#}" -gt 0 ]]; do + case "${1}" in + --board) + board="${2}" + shift 2 + ;; + --channel) + channel="${2}" + shift 2 + ;; + --platform) + platform="${2}" + shift 2 + ;; + --tapfile) + tapfile="${2}" + shift 2 + ;; + --torcx-manifest) + torcx_manifest="${2}" + shift 2 + ;; + --parallel) + parallel="${2}" + shift 2 + ;; + *) + break + ;; + esac + done + if [[ -z "${board}" ]]; then + fail 'no --board passed' + fi + if [[ -z "${channel}" ]]; then + fail 'no --channel passed' + fi + if [[ -z "${tapfile}" ]]; then + fail 'no --tapfile passed' + fi + if [[ -z "${torcx_manifest}" ]]; then + fail 'no --torcx-manifest passed' + fi + # doing string comparisons, because parallel and platform can be anything + if [[ "${parallel}" != "42" ]]; then + fail "expected --parallel with 42, got '${parallel}'" + fi + if [[ "${platform}" != "test" ]]; then + fail "expected --platform with 'test', got '${platform}'" + fi + + for test_name; do + case "${test_name}" in + 'fail.kola') + fail=1 + break + ;; + 'fail.timeout') + sleep 20s + break + ;; + esac + done + result='ok' + if [[ ${fail} -eq 1 ]]; then + result='not ok' + fi + wildcard=0 + if [[ ${#} -eq 0 ]]; then + wildcard=1 + elif [[ ${#} -eq 1 ]] && [[ "${1}" = '*' ]]; then + wildcard=1 + fi + if [[ ${wildcard} -eq 1 ]]; then + set -- "${all_tests[@]}" + fi + printf '1..%s\n' ${#} >"${tapfile}" + format="${result}"' - %s\n' + printf "${format}" "${@}" >>"${tapfile}" + exit ${fail} + ;; + *) + fail "unknown command '${1}'" + ;; +esac diff --git a/ci-automation/vendor-testing/test.sh b/ci-automation/vendor-testing/test.sh new file mode 100755 index 0000000000..2c50ff8967 --- /dev/null +++ b/ci-automation/vendor-testing/test.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Copyright (c) 2022 The Flatcar Maintainers. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -euo pipefail + +# Test execution script for the test non-vendor non-image. +# This script is supposed to run in the mantle container. + +source ci-automation/vendor_test.sh + +# $@ now contains tests / test patterns to run + +CIA_OUTPUT_MAIN_INSTANCE='default' +CIA_OUTPUT_ALL_TESTS=( "${@}" ) +CIA_OUTPUT_EXTRA_INSTANCES=( 'extra1' 'extra2' ) +CIA_OUTPUT_EXTRA_INSTANCE_TESTS=( 'cl.internet' ) +CIA_OUTPUT_TIMEOUT=10s + +query_kola_tests() { + shift; # ignore the instance type + kola list --platform=test --filter "${@}" +} + +if [[ ! -d path-override ]]; then + mkdir path-override +fi +if [[ ! -e 'path-override/kola' ]]; then + cp "${CIA_VENDOR_SCRIPTS_DIR}/test-kola.sh" 'path-override/kola' +fi +if [[ ! -x 'path-override/kola' ]]; then + chmod a+x 'path-override/kola' +fi +export PATH="${PWD}/path-override:${PATH}" + +for test_name; do + case "${test_name}" in + 'fail.setup') + echo 'failing setup' + false + ;; + esac +done + +run_kola_tests() { + local instance_type="${1}"; shift + + kola_run \ + --parallel=42 \ + --platform=test \ + "${@}" +} + +run_default_kola_tests