From b9483a0fdb30f45402eb82f3d558d70c06d18f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=22WanzenBug=22=20Wanzenb=C3=B6ck?= Date: Tue, 9 Nov 2021 13:56:57 +0100 Subject: [PATCH] ci: add basic e2e smoke test --- .gitignore | 2 ++ .gitlab-ci.yml | 57 ++++++++++++++++++++++++++++++ tests/Dockerfile | 3 ++ tests/all-base-images.sh | 33 ++++++++++++++++++ tests/data/example.txt | 3 ++ tests/data/example.txt.sha256sum | 1 + tests/provision.toml | 16 +++++++++ tests/test-run.toml | 59 ++++++++++++++++++++++++++++++++ tests/tests.toml | 12 +++++++ 9 files changed, 186 insertions(+) create mode 100644 tests/Dockerfile create mode 100755 tests/all-base-images.sh create mode 100644 tests/data/example.txt create mode 100644 tests/data/example.txt.sha256sum create mode 100644 tests/provision.toml create mode 100644 tests/test-run.toml create mode 100644 tests/tests.toml diff --git a/.gitignore b/.gitignore index 970e95f..3b76297 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ mocks /virter + +/tests/vms.toml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4df8bec..9d1c8bf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,38 @@ stages: - test - deploy +variables: + VMSHED_VERSION: v0.14.4 + BUILD_HELPERS_VERSION: a87d4f95c35fa24eebe1a157408ef59cebd1f3f4 + +prepare-bins: + stage: build + image: ${LINBIT_DOCKER_REGISTRY}/build-helpers:${BUILD_HELPERS_VERSION} + script: + - . /usr/local/bin/gitlab-utils.sh + - ci_prepare_tools + - ci_fetch_binary vmshed vmshed-$VMSHED_VERSION https://github.com/LINBIT/vmshed/releases/download/$VMSHED_VERSION/vmshed-linux-amd64 + cache: + paths: + - download + artifacts: + paths: + - download + - bin + +prepare-docker: + stage: build + image: + # Pinned to 1.6.0 until https://github.com/GoogleContainerTools/kaniko/issues/1790 is resolved + name: gcr.io/kaniko-project/executor:v1.6.0-debug + entrypoint: [ "" ] + script: + - set -ex + - mkdir -p /kaniko/.docker + - ln -snf "$DOCKER_AUTH_CONFIG_FILE" /kaniko/.docker/config.json + - /kaniko/executor --registry-mirror $DOCKER_REGISTRY_MIRROR --dockerfile $CI_PROJECT_DIR/tests/Dockerfile --context $CI_PROJECT_DIR/tests --cache --destination ${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG + + build: stage: build script: @@ -53,6 +85,31 @@ lint: junit: - lint.xml +e2e-test: + stage: test + variables: + EXCLUDED: amazonlinux-2 + tags: + - libvirt + script: + - ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json + - docker pull ${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG + - cp virter bin/virter + - export "PATH=$PWD/bin:$PATH" + - virter registry update + - cd tests/ + - EXCLUDED_BASE_IMAGES=$EXCLUDED PULL_LOCATION=${LINBIT_DOCKER_REGISTRY}/vm ./all-base-images.sh > vms.toml + - vmshed --set values.DockerImage=${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG --nvms ${LINBIT_CI_MAX_CPUS:-20} + artifacts: + when: always + paths: + - tests/tests-out/ + reports: + junit: + # These reports are created by vmshed, reporting if the test command itself succeeded. + - tests/tests-out/test-results/*.xml + + sync-images: stage: deploy rules: diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..a5f7b99 --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:latest + +RUN apk add openssh-client diff --git a/tests/all-base-images.sh b/tests/all-base-images.sh new file mode 100755 index 0000000..07d920a --- /dev/null +++ b/tests/all-base-images.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Generate a vms.toml for vmshed, using known base images. +set -e + +cat <&2 + continue + fi + + if [ -n "$PULL_LOCATION" ]; then + virter image pull "$name" "$PULL_LOCATION/$name" >&2 + else + virter image pull "$name" >&2 + fi + + cat <&2 + systemctl list-units --failed 1>&2 + exit 1 +done +""" diff --git a/tests/tests.toml b/tests/tests.toml new file mode 100644 index 0000000..e7816f9 --- /dev/null +++ b/tests/tests.toml @@ -0,0 +1,12 @@ +test_suite_file = "test-run.toml" +test_timeout = "1m" +artifacts = [ + "/var/log/journal", + "/var/log/messages", + "/run/log/journal", +] + +[tests] +[tests.smoke] +vms = [1] +needallplatforms = true