From 6adb83fbab381c5ab16f28f8317138cebb8ffaac Mon Sep 17 00:00:00 2001 From: Youjung Kim <126618609+ykim-akamai@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:14:39 -0800 Subject: [PATCH] test: Add smoke test suite and GHA workflow (#629) * gha test * gha test 2 * gha test 3 * gha test 4 * gha test 4 * add smoke test suite * add smoke test suite --------- Co-authored-by: Ye Chen <127243817+yec-akamai@users.noreply.github.com> --- .github/workflows/nightly-smoke-tests.yml | 88 +++++++++++++++++++++++ Makefile | 5 +- scripts/test_basic_smoke.sh | 29 ++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/nightly-smoke-tests.yml create mode 100755 scripts/test_basic_smoke.sh diff --git a/.github/workflows/nightly-smoke-tests.yml b/.github/workflows/nightly-smoke-tests.yml new file mode 100644 index 00000000..da150285 --- /dev/null +++ b/.github/workflows/nightly-smoke-tests.yml @@ -0,0 +1,88 @@ +name: Nightly Smoke Tests + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + inputs: + sha: + description: 'Commit SHA to test' + required: false + default: '' + type: string + +jobs: + smoke_tests: + if: github.repository == 'linode/ansible_linode' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + env: + EXIT_STATUS: 0 + defaults: + run: + working-directory: .ansible/collections/ansible_collections/linode/cloud + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + path: .ansible/collections/ansible_collections/linode/cloud + fetch-depth: 0 + submodules: 'recursive' + + - name: Update packages + run: sudo apt-get update -y + + - name: Setup Python 3 + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.run-eol-python-version == 'true' && env.EOL_PYTHON_VERSION || inputs.python-version || env.DEFAULT_PYTHON_VERSION }} + + - name: Install dependencies + run: make deps + + - name: Install ansible dependencies + run: ansible-galaxy collection install amazon.aws:==6.0.1 + + - name: Install Collection + run: make install + + - name: Replace Existing Keys + run: rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa + + - name: Run smoke tests + id: smoke_tests + run: | + make smoketest + env: + LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }} + + - name: Notify Slack + if: (success() || failure()) && github.repository == 'linode/ansible_linode' + uses: slackapi/slack-github-action@v2.0.0 + with: + method: chat.postMessage + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + channel: ${{ secrets.SLACK_CHANNEL_ID }} + blocks: + - type: section + text: + type: mrkdwn + text: ":rocket: *${{ github.workflow }} Completed in: ${{ github.repository }}* :white_check_mark:" + - type: divider + - type: section + fields: + - type: mrkdwn + text: "*Build Result:*\n${{ steps.smoke_tests.outcome == 'success' && ':large_green_circle: Build Passed' || ':red_circle: Build Failed' }}" + - type: mrkdwn + text: "*Branch:*\n`${{ github.ref_name }}`" + - type: section + fields: + - type: mrkdwn + text: "*Commit Hash:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>" + - type: mrkdwn + text: "*Run URL:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run Details>" + - type: divider + - type: context + elements: + - type: mrkdwn + text: "Triggered by: :bust_in_silhouette: `${{ github.actor }}`" \ No newline at end of file diff --git a/Makefile b/Makefile index 60e3a4c3..7adcf5cc 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ delete-e2e-firewall: update-test-submodules echo "$$OUTPUT"; \ exit 1; \ else \ - echo "E2E Cloud firewall created successfully."; \ + echo "E2E Cloud firewall deleted successfully."; \ fi update-test-submodules: @@ -102,6 +102,9 @@ test: integration-test testall: ./scripts/test_all.sh +smoketest: + ./scripts/test_basic_smoke.sh + unittest: ansible-test units --target-python default diff --git a/scripts/test_basic_smoke.sh b/scripts/test_basic_smoke.sh new file mode 100755 index 00000000..8ace65bd --- /dev/null +++ b/scripts/test_basic_smoke.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +PARALLEL_JOBS="${PARALLEL_JOBS:=3}" + +run_test() { + ansible-test integration $1 +} + +cleanup() { + if [[ -z "$CLEANUP_DONE" ]]; then + make delete-e2e-firewall + CLEANUP_DONE=1 + fi +} + +trap cleanup EXIT + +CLEANUP_DONE=0 + +make create-integration-config || exit 1 +make create-e2e-firewall || exit 1 + +export -f run_test + +parallel -j $PARALLEL_JOBS --group --keep-order --retries 3 run_test ::: $(ls tests/integration/targets | grep _basic) +TEST_EXIT_CODE=$? + + +exit $TEST_EXIT_CODE \ No newline at end of file