From 69a0e97a7b9db2c8a6533242b5aff0c5bf7f2995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=CC=81lvaro?= Date: Sat, 23 Oct 2021 10:45:13 +0200 Subject: [PATCH] ref: Change tests architecture --- .dockerignore | 3 + .github/workflows/build-and-test.yml | 72 ++++-------------------- assets/build/install.sh | 2 +- tests/basic/README.md | 6 ++ tests/basic/test.sh | 41 ++++++++++++++ tests/salt-api/README.md | 7 +++ tests/salt-api/test.sh | 84 ++++++++++++++++++++++++++++ 7 files changed, 153 insertions(+), 62 deletions(-) create mode 100644 tests/basic/README.md create mode 100755 tests/basic/test.sh create mode 100644 tests/salt-api/README.md create mode 100755 tests/salt-api/test.sh diff --git a/.dockerignore b/.dockerignore index 0c79fa2..83ded1e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,9 @@ .github/ .git/ +# Ignoring tests files +tests/ + # Ignoring markdown files *.md diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a0c567e..ed0685d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -74,11 +74,13 @@ jobs: platform: [linux/amd64, linux/arm64, linux/arm/v7] env: DOCKER_CLI_EXPERIMENTAL: enabled - SALTAPI_URL: https://localhost:8000/ - SALTAPI_USER: salt_api - SALTAPI_PASS: 4wesome-Pass0rd - SALTAPI_EAUTH: pam + PLATFORM: ${{ matrix.platform }} + BOOTUP_WAIT_SECONDS: 90 + steps: + - name: Checkout repository + uses: actions/checkout@v2.3.5 + - name: Download Docker registry data from build job uses: actions/download-artifact@v2 with: @@ -106,69 +108,17 @@ jobs: - name: Docker inspect run: docker buildx imagetools inspect ${IMAGE_NAME} | grep '${{ matrix.platform }}' - - name: Launch docker container - run: | - # Create configuration files - mkdir -p /tmp/config/ - cat > /tmp/config/salt-api.conf < Removing ${CONTAINER_NAME} ..." + docker container rm --force "${CONTAINER_NAME}" +} + +trap cleanup EXIT + +# Run test instance +echo "==> Starting docker-salt-master (${PLATFORM}) ..." +docker run --rm --detach --name "${CONTAINER_NAME}" \ + --publish 4505:4505 --publish 4506:4506 \ + --platform "${PLATFORM}" \ + "${IMAGE_NAME}" || ( echo "container started โŒ"; exit 1 ) +echo "container started โœ…" + +# Wait for salt-master bootup +echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..." +sleep "${BOOTUP_WAIT_SECONDS}" + +# Check salt version +echo "==> Checking salt version ..." +docker exec "${CONTAINER_NAME}" salt --versions +[[ "$(docker exec ${CONTAINER_NAME} salt --version)" == "salt $(cat VERSION)" ]] || ( echo "salt version โŒ"; exit 1 ) +echo "salt version โœ…" + +# Test image calling healthcheck +echo "==> Executing healthcheck ..." +docker exec "${CONTAINER_NAME}" /usr/local/sbin/healthcheck | grep -i 'true' || ( echo "healthcheck โŒ"; exit 1 ) +echo "healthcheck โœ…" diff --git a/tests/salt-api/README.md b/tests/salt-api/README.md new file mode 100644 index 0000000..f957fbc --- /dev/null +++ b/tests/salt-api/README.md @@ -0,0 +1,7 @@ +# Salt API Tests + +Checks: + + - `salt-api` provides a token via `curl`. + - executes `salt-api` command via `curl`. + - installs and tries `salt-pepper`. diff --git a/tests/salt-api/test.sh b/tests/salt-api/test.sh new file mode 100755 index 0000000..aef7731 --- /dev/null +++ b/tests/salt-api/test.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +set -e +[ "${DEBUG}" == true ] && set -vx + +echo "๐Ÿงช Running salt-api tests ..." + +IMAGE_NAME=${IMAGE_NAME:-cdalvaro/docker-salt-master} +CONTAINER_NAME=salt_master +PLATFORM=${PLATFORM:-$(docker version --format='{{.Server.Os}}/{{.Server.Arch}}')} +BOOTUP_WAIT_SECONDS=${BOOTUP_WAIT_SECONDS:-60} + +export SALTAPI_URL="https://localhost:8000/" +export SALTAPI_USER=salt_api +export SALTAPI_PASS=4wesome-Pass0rd +export SALTAPI_EAUTH=pam +export SALTAPI_TMP_DIR=${SALTAPI_TMP_DIR:-/tmp/salt-api} + +function cleanup { + echo "==> Removing ${CONTAINER_NAME} ..." + docker container rm --force "${CONTAINER_NAME}" +} + +trap cleanup EXIT + +# Create configuration files +echo "==> Creating salt-api configuration file ..." +mkdir -p "${SALTAPI_TMP_DIR}/config/" +cat > "${SALTAPI_TMP_DIR}/config/salt-api.conf" < Starting docker-salt-master (${PLATFORM}) with salt-api config ..." +docker run --rm --detach --name "${CONTAINER_NAME}" \ + --publish 4505:4505 --publish 4506:4506 --publish 8000:8000 \ + --env SALT_API_SERVICE_ENABLED=true \ + --env SALT_API_USER_PASS="${SALTAPI_PASS}" \ + --platform "${PLATFORM}" \ + --volume "${SALTAPI_TMP_DIR}/config":/home/salt/data/config:ro \ + "${IMAGE_NAME}" || ( echo "container started โŒ"; exit 1 ) +echo "container started โœ…" + +# Wait for salt-master bootup +echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..." +sleep "${BOOTUP_WAIT_SECONDS}" + + # Test salt-api authentication + echo "==> Getting salt-api token ..." +SALTAPI_TOKEN=$(curl -sSk "${SALTAPI_URL%/}/login" \ + -H "Accept: application/x-yaml" \ + -d username="${SALTAPI_USER}" \ + -d password="${SALTAPI_PASS}" \ + -d eauth="${SALTAPI_EAUTH}" | grep 'token:' | cut -d' ' -f 4) +[ -n "${SALTAPI_TOKEN}" ] || ( echo "salt-api token โŒ"; exit 1 ) +echo "salt-api token โœ…" + + # Test salt-api command + echo "==> Testing curl command ..." +curl -sSk "${SALTAPI_URL}" \ + -H "Accept: application/x-yaml" \ + -H "X-Auth-Token: ${SALTAPI_TOKEN}" \ + -d client=runner \ + -d tgt='*' \ + -d fun=test.stream \ +| grep -i 'true' || ( echo "curl command โŒ"; exit 1 ) +echo "curl command โœ…" + +# Install salt-pepper +echo "==> Installing salt-pepper ..." +pip3 install salt-pepper || ( echo "pepper installed โŒ"; exit 1 ) +echo "pepper installed โœ…" + +# Test salt-pepper +echo "==> Testing salt-pepper ..." +pepper -vvv --debug-http --ignore-ssl-errors --client runner test.stream|| ( echo "pepper test.stream โŒ"; exit 1 ) +echo "pepper test.stream โœ…"