With this patch, four kinds of tests are triggered when there is a
pull request created in a Github kexec-tools repo,
- format check using shfmt
- static analysis using shellcheck
- ShellSpec unit tests (test cases in spec/)
- integration tests ( tests cases in tests/)
The tests are run inside a docker image. This docker image has all the
needed software installed including fedpkg, shellspec and etc. This
Docker image also provides
/usr/share/cloud_images/Fedora-Cloud-Base-35-1.2.x86_64.qcow2 to avoid
repeatedly downloading the Fedora 35 cloud base image each time the
tests are triggered.
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
.github/workflows/main.yml | 53 ++++++++++++++++++++++++++++++++++
tools/run-integration-tests.sh | 29 +++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100644 .github/workflows/main.yml
create mode 100755 tools/run-integration-tests.sh
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..a62aa0e
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,53 @@
+name: kexec-tools tests
+
+on: pull_request
+
+jobs:
+ format-check:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: wget
https://github.com/mvdan/sh/releases/download/v3.4.3/shfmt_v3.4.3_linux_a... -O
/usr/local/bin/shfmt && chmod +x /usr/local/bin/shfmt
+ - run: shfmt -d *.sh kdumpctl mk*dumprd
+
+ static-analysis:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: curl -L -O
https://github.com/koalaman/shellcheck/releases/download/v0.8.0/shellchec...
&& tar -xJf shellcheck-v0.8.0.linux.x86_64.tar.xz
+ # Currently, for kexec-tools, there is need for shellcheck to require
+ # the sourced file to give correct warnings about the checked file
+ - run: shellcheck-v0.8.0/shellcheck --exclude=1090,1091 *.sh spec/*.sh kdumpctl
mk*dumprd
+
+ unit-tests:
+ runs-on: ubuntu-latest
+ container: docker.io/fedora:latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: sudo dnf install -y make dracut grubby hostname
+ - run: curl -L -O
https://github.com/shellspec/shellspec/archive/latest.tar.gz
&& tar -xzf latest.tar.gz
+ - run: cd shellspec-latest && sudo make install
+ - run: shellspec
+
+ integration-tests:
+ runs-on: self-hosted
+ timeout-minutes: 45
+ concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{
matrix.test }}
+ cancel-in-progress: true
+ strategy:
+ matrix:
+ container: [
+ "fedora:35",
+ ]
+ fail-fast: false
+ container:
+ image: ghcr.io/coiby/${{ matrix.container }}
+ options: "--privileged -v /dev:/dev -v
/lib/modules:/lib/modules:ro"
+ steps:
+ - name: "Checkout Repository"
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: "${{ matrix.container }} kdump tests"
+ run: bash ./tools/run-integration-tests.sh
diff --git a/tools/run-integration-tests.sh b/tools/run-integration-tests.sh
new file mode 100755
index 0000000..7883c3f
--- /dev/null
+++ b/tools/run-integration-tests.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+set -ex
+
+[[ -d ${0%/*} ]] && cd "${0%/*}"/../
+
+source /etc/os-release
+
+cd tests
+
+# fedpkg fetch sources based on branch.f$VERSION_ID.remote
+if ! git remote show | grep -q fedora_src; then
+ git remote add fedora_src
https://src.fedoraproject.org/rpms/kexec-tools.git
+ git config --add branch.f$VERSION_ID.remote fedora_src
+fi
+
+can_we_use_qemu_nbd()
+{
+ _tmp_img=/tmp/test.qcow2
+
+ (sudo -v && sudo modprobe nbd \
+ && qemu-img create -fqcow2 $_tmp_img 10m \
+ && qemu-nbd -c /dev/nbd0 $_tmp_img && sudo qemu-nbd -d /dev/nbd0
&& rm $_tmp_img) &> /dev/null
+}
+
+if ! can_we_use_qemu_nbd; then
+ USE_GUESTMOUNT=1
+fi
+
+KUMP_TEST_QEMU_TIMEOUT=20m USE_GUESTMOUNT=$USE_GUESTMOUNT
BASE_IMAGE=/usr/share/cloud_images/Fedora-Cloud-Base-35-1.2.x86_64.qcow2
RELEASE=$VERSION_ID make test-run
--
2.37.1