From 8d38af0786a5394ae4a41ee1146542a247d4784a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Kn=C3=B6ppler?= <6317548+theCalcaholic@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:20:12 +0200 Subject: [PATCH] build-lxd.yml, vm-tests.yml: Add explicit dist-upgrade tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com> --- .github/workflows/build-lxd.yml | 150 +++++++++++++- .github/workflows/vm-tests.yml | 341 ++++++++++++++++++++++++-------- 2 files changed, 403 insertions(+), 88 deletions(-) diff --git a/.github/workflows/build-lxd.yml b/.github/workflows/build-lxd.yml index 7bc232685..7d7410364 100644 --- a/.github/workflows/build-lxd.yml +++ b/.github/workflows/build-lxd.yml @@ -320,13 +320,157 @@ jobs: "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true exit 1 } + + test-dist-upgrade: + needs: + - determine-runner + runs-on: [ubuntu-20.04] + env: + VERSION: "${{ inputs.git_ref || github.ref }}" + ARTIFACT_NAME: "${{ needs.build-previous.outputs.artifact_name }}" + LXC: "${{ needs.determine-runner.outputs.lxc_cmd }}" + PREVIOUS_IMAGE_URL: "https://github.com/nextcloud/nextcloudpi/releases/download/v1.53.2/NextcloudPi_LXD_x86_v1.53.2.tar.gz" + steps: + - uses: whywaita/setup-lxd@v1 + if: ${{ needs.determine-runner.outputs.lxc_cmd == 'lxc' }} + continue-on-error: true + with: + lxd_version: latest/stable + - name: Fix LXD + run: | + sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT + sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: "${{ env.VERSION }}" + - name: Setup Firefox + continue-on-error: true + id: setup-firefox-browser-action + uses: browser-actions/setup-firefox@latest + - name: Setup Firefox from packages + if: ${{ steps.setup-firefox-browser-action.outcome == 'failure' }} + run: | + sudo apt-get install -y --no-install-recommends firefox + - name: Setup GeckoDriver + uses: ChlodAlejandro/setup-geckodriver@latest + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Selenium + run: pip install selenium + - name: download LXD image + run: | + wget -O ./ncp.tar.gz "${PREVIOUS_IMAGE_URL?}" + - name: Launch ncp container + run: | + set -x + "$LXC" delete -q -f ncp || true + "$LXC" image import -q "./ncp.tar.gz" --alias "ncp/update" + systemd-run --user --scope -p "Delegate=yes" "$LXC" launch -q "ncp/update" ncp + "$LXC" exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' + "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log + sleep 30 + ip="$("$LXC" list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)" + ip="${ip/% *}" + echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts + - name: Activate and Test LXD Image + working-directory: ./tests + run: | + "$LXC" exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' & + python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || { + echo "Activation test failed!" + echo "Geckodriver logs:" + tail -n 20 geckodriver.log >&2 || true + echo "================" + echo "ncp.log: " + "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true + exit 1 + } + python system_tests.py --non-interactive || { + echo "System test failed!" + exit 1 + } + python nextcloud_tests.py --no-gui --skip-release-check "nextcloudpi.local" 443 4443 || { + echo "Nextcloud test failed!" + echo "Geckodriver logs:" + tail -n 20 geckodriver.log >&2 || true + echo "================" + echo "ncp.log: " + "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true + echo "================" + echo "nextcloud log: " + datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)" + "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true + exit 1 + } + + - name: Update ncp + run: | + set -ex + BRANCH="${VERSION/refs\/heads\//}" + BRANCH="${BRANCH/refs\/tags\//}" + if [[ "$BRANCH" =~ "refs/pull/"* ]] + then + UPDATE_ARGS=("${{ github.base_ref }}" "$VERSION") + else + UPDATE_ARGS=("$BRANCH") + fi + echo "VERSION=${VERSION}" >> "$GITHUB_ENV" + echo "Running update to ${VERSION}" + + current_nc_version="$("$LXC" exec ncp -- ncc status | grep "version:" | awk '{ print $3 }')" + latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')" + + "$LXC" exec ncp -- bash -c "DBG=x ncp-update ${UPDATE_ARGS[*]}" + "$LXC" exec ncp -- /usr/local/bin/ncc status + + if [[ "$current_nc_version" =~ "$latest_nc_version".* ]] + then + echo "Nextcloud is up to date - skipping NC update test." + else + "$LXC" exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}" + fi + + "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log + + "$LXC" stop ncp + - name: Relaunch container + run: | + set -x + systemd-run --user --scope -p "Delegate=yes" "$LXC" start ncp + "$LXC" exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' + sleep 30 + ip="$("$LXC" list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)" + ip="${ip/% *}" + echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts + - name: Test LXD Image + working-directory: ./tests + run: | + "$LXC" exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' & + python system_tests.py --non-interactive || { + echo "System test failed!" + exit 1 + } + python nextcloud_tests.py --no-gui --skip-release-check "nextcloudpi.local" 443 4443 || { + echo "Nextcloud test failed!" + echo "Geckodriver logs:" + tail -n 20 geckodriver.log >&2 || true + echo "================" + echo "ncp.log: " + "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true + echo "================" + echo "nextcloud log: " + datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)" + "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true + exit 1 + } - name: NCP distupgrade id: distupgrade run: | - "$LXC" exec ncp -- cat /etc/os-release | grep VERSION_ID=11 || { - echo "Skipping dist-upgrade - can't upgrade from Debian $("$LXC" exec ncp -- cat /etc/os-release | grep VERSION_ID=)" + "$LXC" exec ncp -- cat /etc/os-release | grep VERSION_ID="11" || { + echo "can't upgrade from Debian $("$LXC" exec ncp -- cat /etc/os-release | grep VERSION_ID=)" echo "skipped=yes" | tee -a $GITHUB_OUTPUT - exit 0 + exit 1 } "$LXC" exec ncp -- bash -c 'ncp-dist-upgrade' echo "skipped=no" | tee -a $GITHUB_OUTPUT diff --git a/.github/workflows/vm-tests.yml b/.github/workflows/vm-tests.yml index ba028fe57..c4b8db5f2 100644 --- a/.github/workflows/vm-tests.yml +++ b/.github/workflows/vm-tests.yml @@ -18,50 +18,118 @@ on: - master jobs: - setup-installation-test-instance: + installation-test: runs-on: ubuntu-latest + container: + image: thecalcaholic/ncp-test-automation:bookworm + env: + HCLOUD_TOKEN: "${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }}" + UID: "${{ github.run_id }}-install" outputs: server_address: ${{ steps.create-test-instance.outputs.server_address }} snapshot_id: ${{ steps.create-test-instance.outputs.snapshot_id }} test_server_id: ${{ steps.create-test-instance.outputs.test_server_id }} version: ${{ env.VERSION }} + test_result: ${{ steps.final_test.outputs.test_result }} + ssh_artifact_name: ${{ env.SSH_ARTIFACT_NAME }} env: VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" + HOME: /root + SSH_ARTIFACT_NAME: "${{ github.run_id }}-install-ssh" + defaults: + run: + shell: bash steps: - uses: actions/checkout@v3 - - run: | + with: + path: /github/workspace/ncp + - name: Generate ssh keypair + working-directory: /github/workspace + run: | set -e mkdir -p .ssh ssh-keygen -t ed25519 -f ".ssh/automation_ssh_key" - name: upload ssh private key to artifact store uses: actions/upload-artifact@v3 with: - name: ${{ github.run_id }}-install-ssh-privkey - path: .ssh + name: "${{ env.SSH_ARTIFACT_NAME }}" + path: /github/workspace/.ssh if-no-files-found: error - id: create-test-instance - uses: ./.github/actions/create-test-instance + uses: /github/workspace/ncp/.github/actions/create-test-instance with: version: ${{ env.VERSION }} uid: "${{ github.run_id }}-install" hcloud_token: ${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }} server_type: "cx11" + - name: set instance variables + run: | + echo "SERVER_ADDRESS=${{ steps.create-test-instance.outputs.server_address }}" >> "$GITHUB_ENV" + echo "SNAPSHOT_ID=${{ steps.create-test-instance.outputs.snapshot_id }}" >> "$GITHUB_ENV" + echo " + - name: Test postinstall VM + id: final_test + working-directory: /ncp-test-automation/bin + run: | + set -e + echo "Setup ssh" + chmod 0600 /github/workspace/.ssh/automation_ssh_key + eval "$(ssh-agent)" + ssh-add /github/workspace/.ssh/automation_ssh_key + + source ./library.sh + + trap '[ $? -eq 0 ] || echo "test_result=failure" >> "$GITHUB_OUTPUT"; terminate-ssh-port-forwarding "${SERVER_ADDRESS}"' EXIT 1 2 + + setup-ssh-port-forwarding "$SERVER_ADDRESS" + + echo "Run integration tests" + ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" "root@${SERVER_ADDRESS}" cat /usr/local/etc/instance.cfg + set -x + test-ncp-instance -a -f "$SNAPSHOT_ID" -b "${VERSION}" --systemtest-args "--skip-update-test" "root@${SERVER_ADDRESS}" "localhost" "8443" "9443" || { + + echo "Integration tests failed" + echo "Here are the last lines of ncp-install.log:" + echo "===========================================" + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" tail /var/log/ncp-install.log; + echo "===========================================" + echo "and ncp.log:" + echo "===========================================" + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" tail /var/log/ncp.log; + echo "===========================================" + exit 1 + } + echo "test_result=success" >> "$GITHUB_OUTPUT"; - setup-update-test-instance: + update-test: runs-on: ubuntu-latest + container: + image: thecalcaholic/ncp-test-automation:bullseye + env: + HCLOUD_TOKEN: "${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }}" + UID: "${{ github.run_id }}-update" + defaults: + run: + shell: bash outputs: server_address: ${{ steps.create-test-instance.outputs.server_address }} snapshot_id: ${{ steps.create-test-instance.outputs.snapshot_id }} test_server_id: ${{ steps.create-test-instance.outputs.test_server_id }} previous_version: ${{ steps.find-version.outputs.previous_version }} version: ${{ env.VERSION }} + test_result: ${{ steps.final_test.test_result }} + ssh_artifact_name: ${{ env.SSH_ARTIFACT_NAME }} env: VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" + HOME: /root + SSH_ARTIFACT_NAME: "${{ github.run_id }}-update-ssh" steps: - uses: actions/checkout@v3 with: fetch-depth: 0 + path: /github/workspace/ncp - name: find reference version + working-directory: /github/workspace/ncp shell: bash id: find-version run: | @@ -81,64 +149,43 @@ jobs: } version="${version%-*-*}" fi - # TODO: REMOVE FOR FUTURE RELEASES - version="v1.53.3" echo "Previous version is '$version'" - echo "previous_version=${version}" >> $GITHUB_OUTPUT + echo "PREVIOUS_VERSION=${version}" >> $GHITHUB_ENV - name: Generate ssh key run: | set -x - mkdir -p ./.ssh - ssh-keygen -t ed25519 -f "./.ssh/automation_ssh_key" + mkdir -p /github/workspace/.ssh + ssh-keygen -t ed25519 -f "/github/workspace/.ssh/automation_ssh_key" - name: upload ssh private key to artifact store uses: actions/upload-artifact@v3 with: - name: ${{ github.run_id }}-update-ssh-privkey - path: ./.ssh + name: "${{ env.SSH_ARTIFACT_NAME }}" + path: /github/workspace/.ssh if-no-files-found: error - id: create-test-instance - uses: ./.github/actions/create-test-instance-bullseye + uses: /github/workspace/ncp/.github/actions/create-test-instance with: - version: "${{ steps.find-version.outputs.previous_version }}" + version: "${{ env.PREVIOUS_VERSION }}" uid: "${{ github.run_id }}-update" hcloud_token: ${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }} server_type: "cx11" - - run-installation-test: - needs: - - setup-installation-test-instance - runs-on: ubuntu-latest - - container: - image: thecalcaholic/ncp-test-automation:bookworm - env: - HCLOUD_TOKEN: "${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }}" - UID: "${{ github.run_id }}-install" - env: - VERSION: ${{ needs.setup-installation-test-instance.outputs.version }} - SERVER_ADDRESS: "${{ needs.setup-installation-test-instance.outputs.server_address }}" - SNAPSHOT_ID: "${{ needs.setup-installation-test-instance.outputs.snapshot_id }}" - HOME: /root - defaults: - run: - shell: bash - steps: - # - uses: actions/checkout@v3 - # with: - # repository: 'theCalcaholic/ncp-test-automation' - - name: download ssh private key from artifact store - uses: actions/download-artifact@v3 + - name: Set instance variables + run: | + echo "SERVER_ADDRESS=${{ steps.create-test-instance.outputs.server_address }}" >> "$GITHUB_ENV" + echo "SNAPSHOT_ID=${{ steps.create-test-instance.outputs.snapshot_id }}" >> "$GITHUB_ENV" + - uses: actions/checkout@v3 with: - name: ${{ github.run_id }}-install-ssh-privkey - path: /github/workspace/.ssh - - name: Test postinstall VM + repository: 'theCalcaholic/ncp-test-automation' + ref: "latest" + path: /github/workspace/ncp-test-automation + - name: Activate and Test postinstall VM working-directory: /ncp-test-automation/bin run: | set -e echo "Setup ssh" - chmod 0600 /github/workspace/.ssh/automation_ssh_key + chmod 0600 ../../.ssh/automation_ssh_key eval "$(ssh-agent)" - ssh-add /github/workspace/.ssh/automation_ssh_key + ssh-add ../../.ssh/automation_ssh_key source ./library.sh @@ -148,8 +195,54 @@ jobs: echo "Run integration tests" ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" "root@${SERVER_ADDRESS}" cat /usr/local/etc/instance.cfg + test-ncp-instance -a -f "$SNAPSHOT_ID" -b "${VERSION}" --systemtest-args "--skip-update-test" --nc-test-args "--skip-release-check" "root@${SERVER_ADDRESS}" "localhost" "8443" "9443" || { + + echo "Integration tests failed" + echo "Here are the last lines of ncp-install.log:" + echo "===========================================" + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" tail /var/log/ncp-install.log; + echo "===========================================" + echo "and ncp.log:" + echo "===========================================" + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" tail /var/log/ncp.log; + echo "===========================================" + exit 1 + } + - name: perform update + working-directory: /ncp-test-automation/bin + run: | + set -e + + echo "Setup ssh" + chmod 0600 /github/workspace/.ssh/automation_ssh_key + eval "$(ssh-agent)" + ssh-add /github/workspace/.ssh/automation_ssh_key + + source ./library.sh + + echo "Updating from $PREVIOUS_VERSION to $VERSION" + ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${SERVER_ADDRESS}" 2> /dev/null || true + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" "ncp-update '$VERSION'" + - name: Run integration tests after update + id: final_test + working-directory: /ncp-test-automation/bin + run: | + set -e + + echo "Setup ssh" + eval "$(ssh-agent)" + ssh-add /github/workspace/.ssh/automation_ssh_key + + source ./library.sh + + trap '[ $? -eq 0 ] || echo "test_result=failure" >> "$GITHUB_OUTPUT"; terminate-ssh-port-forwarding "${SERVER_ADDRESS}"' EXIT 1 2 + + echo "Run integration tests" + setup-ssh-port-forwarding "$SERVER_ADDRESS" + NC_TEST_ARGS=() + ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" cat /etc/os-release | grep VERSION_ID=12 || NC_TEST_ARGS+=("--skip-release-check") set -x - test-ncp-instance -a -f "$SNAPSHOT_ID" -b "${VERSION}" --systemtest-args "--skip-update-test" "root@${SERVER_ADDRESS}" "localhost" "8443" "9443" || { + test-ncp-instance -f "$SNAPSHOT_ID" -b "${VERSION}" --nc-test-args "$NC_TEST_ARGS" --systemtest-args "--skip-update-test" "root@${SERVER_ADDRESS}" "localhost" "8443" "9443" || { echo "Integration tests failed" echo "Here are the last lines of ncp-install.log:" @@ -162,44 +255,67 @@ jobs: echo "===========================================" exit 1 } + + echo "test_result=success" >> "$GITHUB_OUTPUT"; - run-update-test: - needs: - - setup-update-test-instance + dist-upgrade-test: runs-on: ubuntu-latest - container: image: thecalcaholic/ncp-test-automation:bullseye env: HCLOUD_TOKEN: "${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }}" - UID: "${{ github.run_id }}-update" - env: - PREVIOUS_VERSION: ${{ needs.setup-update-test-instance.outputs.previous_version }} - VERSION: ${{ needs.setup-update-test-instance.outputs.version }} - SERVER_ADDRESS: "${{ needs.setup-update-test-instance.outputs.server_address }}" - SNAPSHOT_ID: "${{ needs.setup-update-test-instance.outputs.snapshot_id }}" - HOME: /root + UID: "${{ github.run_id }}-distupgrade" defaults: run: shell: bash + outputs: + test_result: ${{ steps.final_test.test_result }} + env: + PREVIOUS_VERSION: "v1.53.3" + VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" + HOME: /root + SSH_ARTIFACT_NAME: "${{ github.run_id }}-distupgrade-ssh" + ssh_artifact_name: ${{ env.SSH_ARTIFACT_NAME }} steps: - uses: actions/checkout@v3 with: - repository: 'theCalcaholic/ncp-test-automation' - ref: "bullseye" - - name: download ssh private key from artifact store - uses: actions/download-artifact@v3 + fetch-depth: 0 + path: /github/workspace/ncp + - name: Generate ssh key + run: | + set -x + mkdir -p /github/workspace/.ssh + ssh-keygen -t ed25519 -f "/github/workspace/.ssh/automation_ssh_key" + - name: upload ssh private key to artifact store + uses: actions/upload-artifact@v3 with: - name: ${{ github.run_id }}-update-ssh-privkey + name: "${{ env.SSH_ARTIFACT_NAME }}" path: /github/workspace/.ssh + if-no-files-found: error + - id: create-test-instance + uses: ./.github/actions/create-test-instance + with: + version: "${{ env.PREVIOUS_VERSION }}" + uid: "${{ github.run_id }}-update" + hcloud_token: ${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }} + server_type: "cx11" + - name: Set instance variables + run: | + echo "SERVER_ADDRESS=${{ steps.create-test-instance.outputs.server_address }}" >> "$GITHUB_ENV" + echo "SNAPSHOT_ID=${{ steps.create-test-instance.outputs.snapshot_id }}" >> "$GITHUB_ENV" + - uses: actions/checkout@v3 + with: + repository: 'theCalcaholic/ncp-test-automation' + ref: "latest" + path: /github/workspace/ncp-test-automation - name: Activate and Test postinstall VM working-directory: /ncp-test-automation/bin run: | set -e echo "Setup ssh" - chmod 0600 /github/workspace/.ssh/automation_ssh_key + chmod 0600 ../../.ssh/automation_ssh_key eval "$(ssh-agent)" - ssh-add /github/workspace/.ssh/automation_ssh_key + ssh-add ../../.ssh/automation_ssh_key source ./library.sh @@ -237,7 +353,7 @@ jobs: echo "Updating from $PREVIOUS_VERSION to $VERSION" ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${SERVER_ADDRESS}" 2> /dev/null || true ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" "ncp-update '$VERSION'" - - name: Run integration tests + - name: Run integration tests after update working-directory: /ncp-test-automation/bin run: | set -e @@ -282,14 +398,15 @@ jobs: source ./library.sh ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" cat /etc/os-release | grep 'VERSION_ID="11"' || { - echo "Skipping dist-upgrade - can't upgrade from Debian $(ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" grep 'VERSION_ID=' /etc/os-release)" + echo "Can't upgrade from Debian $(ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" grep 'VERSION_ID=' /etc/os-release)" echo "skipped=yes" | tee -a $GITHUB_OUTPUT - exit 0 + exit 1 } ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" DEBIAN_FRONTEND=noninteractive ncp-dist-upgrade echo "skipped=no" | tee -a $GITHUB_OUTPUT - - name: Run integration tests + - name: Run integration tests after dist-upgrade + id: final_test working-directory: /ncp-test-automation/bin run: | set -e @@ -300,7 +417,7 @@ jobs: source ./library.sh - trap 'terminate-ssh-port-forwarding "${SERVER_ADDRESS}"' EXIT 1 2 + trap '[ $? -eq 0 ] || echo "test_result=failure" >> "$GITHUB_OUTPUT"; terminate-ssh-port-forwarding "${SERVER_ADDRESS}"' EXIT 1 2 echo "Run integration tests" setup-ssh-port-forwarding "$SERVER_ADDRESS" @@ -320,12 +437,12 @@ jobs: ssh "${SSH_OPTIONS[@]}" "root@${SERVER_ADDRESS}" tail /opt/ncdata/data/nextcloud.log; exit 1 } + echo "test_result=success" >> "$GITHUB_OUTPUT" install-postactivation-snapshot: if: ${{ always() }} needs: - - setup-installation-test-instance - - run-installation-test + - installation-test runs-on: ubuntu-latest container: image: thecalcaholic/ncp-test-automation:latest @@ -334,18 +451,18 @@ jobs: env: TEST_TYPE: install - SERVER_ADDRESS: ${{ needs.setup-installation-test-instance.outputs.server_address }} - TEST_RESULT: ${{ needs.setup-installation-test-instance.result }} - TEST_SERVER_ID: ${{ needs.setup-installation-test-instance.outputs.test_server_id }} - VERSION: ${{ needs.setup-installation-test-instance.outputs.version }} - + SERVER_ADDRESS: ${{ needs.installation-test.outputs.server_address }} + TEST_RESULT: ${{ needs.installation-test.test_result }} + TEST_SERVER_ID: ${{ needs.installation-test.outputs.test_server_id }} + VERSION: ${{ needs.installation-test.outputs.version }} + SSH_ARTIFACT_NAME: "${{ needs.installation-test.outputs.ssh_artifact_name }}" UID: ${{ github.run_id }}-install steps: - name: download ssh private key from artifact store uses: actions/download-artifact@v3 if: ${{ contains('success|failure', env.TEST_RESULT) }} with: - name: ${{ github.run_id }}-${{ env.TEST_TYPE }}-ssh-privkey + name: ${{ env.SSH_ARTIFACT_NAME }} path: /github/workspace/.ssh - name: Shutdown server if: ${{ contains('success|failure', env.TEST_RESULT) }} @@ -379,8 +496,7 @@ jobs: update-postactivation-snapshot: if: ${{ always() }} needs: - - setup-update-test-instance - - run-update-test + - update-test runs-on: ubuntu-latest container: image: thecalcaholic/ncp-test-automation:latest @@ -389,17 +505,18 @@ jobs: env: TEST_TYPE: update - SERVER_ADDRESS: ${{ needs.setup-update-test-instance.outputs.server_address }} - TEST_RESULT: ${{ needs.setup-update-test-instance.result }} - TEST_SERVER_ID: ${{ needs.setup-update-test-instance.outputs.test_server_id }} - VERSION: ${{ needs.setup-update-test-instance.outputs.version }} + SERVER_ADDRESS: ${{ needs.update-test-instance.outputs.server_address }} + TEST_RESULT: ${{ needs.update-test.test_result }} + TEST_SERVER_ID: ${{ needs.update-test.outputs.test_server_id }} + VERSION: ${{ needs.update-test.outputs.version }} UID: ${{ github.run_id }}-update + SSH_ARTIFACT_NAME: "${{ needs.installation-test.outputs.ssh_artifact_name }}" steps: - name: download ssh private key from artifact store uses: actions/download-artifact@v3 if: ${{ contains('success|failure', env.TEST_RESULT) }} with: - name: ${{ github.run_id }}-${{ env.TEST_TYPE }}-ssh-privkey + name: ${{ env.SSH_ARTIFACT_NAME }} path: /github/workspace/.ssh - name: Shutdown server if: ${{ contains('success|failure', env.TEST_RESULT) }} @@ -430,6 +547,60 @@ jobs: snapshot_id="$(tf-output "$TF_SNAPSHOT" -state="${TF_SNAPSHOT}/${VERSION//\//.}.postactivation.tfstate" snapshot_id)" hcloud image add-label -o "$snapshot_id" "test-result=${TEST_RESULT?}" + dist-upgrade-postactivation-snapshot: + if: ${{ always() }} + needs: + - dist-upgrade-test + runs-on: ubuntu-latest + container: + image: thecalcaholic/ncp-test-automation:latest + env: + HCLOUD_TOKEN: "${{ secrets.TEST_AUTOMATION_HCLOUD_API_TOKEN }}" + + env: + TEST_TYPE: distupgrade + SERVER_ADDRESS: ${{ needs.update-test-instance.outputs.server_address }} + TEST_RESULT: ${{ needs.update-test.test_result }} + TEST_SERVER_ID: ${{ needs.update-test.outputs.test_server_id }} + VERSION: ${{ needs.update-test.outputs.version }} + UID: ${{ github.run_id }}-distupgrade + SSH_ARTIFACT_NAME: "${{ needs.installation-test.outputs.ssh_artifact_name }}" + steps: + - name: download ssh private key from artifact store + uses: actions/download-artifact@v3 + if: ${{ contains('success|failure', env.TEST_RESULT) }} + with: + name: ${{ env.SSH_ARTIFACT_NAME }} + path: /github/workspace/.ssh + - name: Shutdown server + if: ${{ contains('success|failure', env.TEST_RESULT) }} + run: | + chmod 0600 /github/workspace/.ssh/automation_ssh_key + export SSH_PUBLIC_KEY="$(cat /github/workspace/.ssh/automation_ssh_key.pub)" + bash /ncp-test-automation/bin/entrypoint.sh + eval "$(ssh-agent)" + ssh-add /github/workspace/.ssh/automation_ssh_key + + ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" "root@${SERVER_ADDRESS?}" <