Skip to content

Commit

Permalink
ci: add basic e2e smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
WanzenBug committed Nov 10, 2021
1 parent c8343b3 commit b9483a0
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mocks

/virter

/tests/vms.toml
57 changes: 57 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:latest

RUN apk add openssh-client
33 changes: 33 additions & 0 deletions tests/all-base-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Generate a vms.toml for vmshed, using known base images.
set -e

cat <<EOF
name = "smoke"
provision_file = "provision.toml"
provision_timeout = "2m"
provision_memory = "1G"
provision_cpus = 1
EOF

while read -r name url; do
if echo "$name" | grep -q -E "^($EXCLUDED_BASE_IMAGES)\$" ; then
echo "$name was excluded" >&2
continue
fi

if [ -n "$PULL_LOCATION" ]; then
virter image pull "$name" "$PULL_LOCATION/$name" >&2
else
virter image pull "$name" >&2
fi

cat <<EOF
[[vms]]
vcpus = 1
memory = "1G"
base_image = "$name"
EOF

done < <(virter image ls --available | tail -n +2)
3 changes: 3 additions & 0 deletions tests/data/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789
1 change: 1 addition & 0 deletions tests/data/example.txt.sha256sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134d9234f01411b06bd56ebb4b7ae6208444bc26a91f5755cc9a07131ed78c39 example.txt
16 changes: 16 additions & 0 deletions tests/provision.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[steps]]
[steps.shell]
script = """
set -ex
if ! command -v rsync ; then
if command -v apt-get ; then
apt-get update
apt-get install -y rsync
elif command -v dnf ; then
dnf install -y rsync
elif command -v yum ; then
yum install -y rsync
fi
fi
"""
59 changes: 59 additions & 0 deletions tests/test-run.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[values]
DockerImage = "ssh"

# Check that rsync steps work
[[steps]]
[steps.rsync]
source = "data/"
dest = "/virter"

# Check that docker steps work
[[steps]]
[steps.docker]
image = "{{ .DockerImage }}"
command = ["sh", "-exc", """
mkdir -p /virter/out
test -n "$TARGETS"
IFS=,; for t in $TARGETS; do
test "$t" = "$(ssh $t hostname -s)"
scp -r $t:/virter/example.txt example.txt
sha256sum -c /virter/workspace/data/example.txt.sha256sum
mv example.txt /virter/out/example-$t.txt
done
"""]
[steps.docker.copy]
source = "/virter/out"
dest = "{{ .OutDir }}"

# Checks that the previous docker step copied files as expected
[[steps]]
[steps.docker]
image = "{{ .DockerImage }}"
command = ["sh", "-exc", """
IFS=,; for t in $TARGETS; do
test -f "/virter/workspace/{{ .OutDir }}/out/example-$t.txt"
done
"""]

# Checks that shell steps work as expected
[[steps]]
[steps.shell]
script = """
set -ex
test -f /virter/example.txt
cd /virter
sha256sum -c example.txt.sha256sum
# CentOS 6 doesn't use systemd, Upstart is a mess, so don't even bother...
[ command -v systemctl ] || exit 0
while true; do
running=$(systemctl is-system-running || true)
[ "$running" = initializing -o "$running" = starting ] && { sleep 1; continue; }
[ "$running" = running ] && break
echo "System in unexpected state '$running'; failed units:" 1>&2
systemctl list-units --failed 1>&2
exit 1
done
"""
12 changes: 12 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b9483a0

Please sign in to comment.