Skip to content

Commit

Permalink
🤖 Run test suites on qemu/ubuntu (kairos-io#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler authored Sep 22, 2022
1 parent 111a1ad commit d68c9b7
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 77 deletions.
102 changes: 72 additions & 30 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
upgrade-with-cli-test:
needs:
- build
runs-on: macos-12
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -224,23 +224,44 @@ jobs:
uses: actions/download-artifact@v2
with:
name: kairos-${{ matrix.flavor }}.iso.zip
- name: Install deps
- name: Release space from worker
run: |
brew install cdrtools jq
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo
df -h
echo
sudo apt-get remove -y '^llvm-.*|^libllvm.*' || true
sudo apt-get remove --auto-remove android-sdk-platform-tools || true
sudo apt-get purge --auto-remove android-sdk-platform-tools || true
sudo rm -rf /usr/local/lib/android
sudo apt-get remove -y '^dotnet-.*|^aspnetcore-.*' || true
sudo rm -rf /usr/share/dotnet
sudo apt-get remove -y '^mono-.*' || true
sudo apt-get remove -y '^ghc-.*' || true
sudo apt-get remove -y '.*jdk.*|.*jre.*' || true
sudo apt-get remove -y 'php.*' || true
sudo apt-get remove -y hhvm powershell firefox monodoc-manual msbuild || true
sudo apt-get remove -y '^google-.*' || true
sudo apt-get remove -y azure-cli || true
sudo apt-get remove -y '^mongo.*-.*|^postgresql-.*|^mysql-.*|^mssql-.*' || true
sudo apt-get remove -y '^gfortran-.*' || true
sudo apt-get autoremove -y
sudo apt-get clean
echo
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo
sudo rm -rfv build || true
df -h
- run: |
ls -liah
export ISO=$PWD/$(ls kairos-core-*.iso)
export GOPATH="/Users/runner/go"
export CONTAINER_IMAGE=ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:8h
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/tests/assets/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "upgrade-with-cli"
export ISO=$PWD/$(ls *.iso)
sudo mkdir build
sudo mv $ISO build/
./earthly.sh +run-qemu-upgrade-test --FLAVOR=${{ matrix.flavor }} --CONTAINER_IMAGE=ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:8h --TEST_SUITE=upgrade-with-cli
- uses: actions/upload-artifact@v2
if: failure()
with:
Expand All @@ -252,7 +273,7 @@ jobs:
needs:
- build
- latest-release
runs-on: macos-12
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -266,23 +287,44 @@ jobs:
uses: actions/download-artifact@v2
with:
name: latest-release.zip
- name: Install deps
- name: Release space from worker
run: |
brew install cdrtools jq
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo
df -h
echo
sudo apt-get remove -y '^llvm-.*|^libllvm.*' || true
sudo apt-get remove --auto-remove android-sdk-platform-tools || true
sudo apt-get purge --auto-remove android-sdk-platform-tools || true
sudo rm -rf /usr/local/lib/android
sudo apt-get remove -y '^dotnet-.*|^aspnetcore-.*' || true
sudo rm -rf /usr/share/dotnet
sudo apt-get remove -y '^mono-.*' || true
sudo apt-get remove -y '^ghc-.*' || true
sudo apt-get remove -y '.*jdk.*|.*jre.*' || true
sudo apt-get remove -y 'php.*' || true
sudo apt-get remove -y hhvm powershell firefox monodoc-manual msbuild || true
sudo apt-get remove -y '^google-.*' || true
sudo apt-get remove -y azure-cli || true
sudo apt-get remove -y '^mongo.*-.*|^postgresql-.*|^mysql-.*|^mssql-.*' || true
sudo apt-get remove -y '^gfortran-.*' || true
sudo apt-get autoremove -y
sudo apt-get clean
echo
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo
sudo rm -rfv build || true
df -h
- run: |
ls -liah
export ISO=$PWD/$(ls kairos-${{ matrix.flavor }}-*.iso)
export GOPATH="/Users/runner/go"
export CONTAINER_IMAGE=ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:8h
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/tests/assets/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "upgrade-latest-with-cli"
export ISO=$PWD/$(ls kairos-${{matrix.flavor}}-*.iso)
sudo mkdir build
sudo mv $ISO build/
./earthly.sh +run-qemu-upgrade-test --FLAVOR=${{ matrix.flavor }} --CONTAINER_IMAGE=ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:8h --TEST_SUITE=upgrade-latest-with-cli
- uses: actions/upload-artifact@v2
if: failure()
with:
Expand Down
24 changes: 24 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,27 @@ run-qemu-tests:
ENV CLOUD_INIT=$CLOUD_CONFIG

RUN PATH=$PATH:$GOPATH/bin ginkgo --label-filter "$TEST_SUITE" --fail-fast -r ./tests/

run-qemu-upgrade-test:
FROM opensuse/leap
WORKDIR /test
RUN zypper in -y qemu-x86 qemu-arm qemu-tools go
ARG FLAVOR
ARG TEST_SUITE=upgrade-with-cli
ARG FROM_ARTIFACTS
ARG CONTAINER_IMAGE
ENV CONTAINER_IMAGE=$CONTAINER_IMAGE
ENV FLAVOR=$FLAVOR
ENV SSH_PORT=60022
ENV CREATE_VM=true
ENV USE_QEMU=true

ENV GOPATH="/go"

RUN go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo

COPY . .
ARG ISO=$(ls /test/build/*.iso)
ENV ISO=$ISO

RUN PATH=$PATH:$GOPATH/bin ginkgo --label-filter "$TEST_SUITE" --fail-fast -r ./tests/
5 changes: 5 additions & 0 deletions tests/autoinstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mos_test
import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/kairos-io/kairos/tests/machine"
Expand All @@ -12,6 +13,10 @@ import (

var _ = Describe("kairos autoinstall test", Label("autoinstall-test"), func() {
BeforeEach(func() {
if os.Getenv("CLOUD_INIT") == "" || !filepath.IsAbs(os.Getenv("CLOUD_INIT")) {
Fail("CLOUD_INIT must be set and must be pointing to a file as an absolute path")
}

machine.EventuallyConnects()
})

Expand Down
6 changes: 6 additions & 0 deletions tests/machine/vbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func HasDir(s string) {
Expect(out).Should(Equal("ok\n"))
}

func Reboot() {
Sudo("reboot") //nolint:errcheck
time.Sleep(1 * time.Minute)
EventuallyConnects(750)
}

func EventuallyConnects(t ...int) {
dur := 360
if len(t) > 0 {
Expand Down
33 changes: 0 additions & 33 deletions tests/register_qrcode_test.go

This file was deleted.

5 changes: 0 additions & 5 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"

"github.com/kairos-io/kairos/pkg/utils"
Expand Down Expand Up @@ -38,10 +37,6 @@ var _ = AfterSuite(func() {

var _ = BeforeSuite(func() {

if os.Getenv("CLOUD_INIT") == "" || !filepath.IsAbs(os.Getenv("CLOUD_INIT")) {
Fail("CLOUD_INIT must be set and must be pointing to a file as an absolute path")
}

if machineID == "" {
machineID = "testvm"
}
Expand Down
9 changes: 5 additions & 4 deletions tests/upgrade_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-with-cli"), func() {
err := machine.SendFile("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

out, _ := machine.Sudo("elemental install --cloud-init /tmp/config.yaml /dev/sda")
out, _ := machine.Sudo("kairos-agent manual-install --device auto /tmp/config.yaml")
Expect(out).Should(ContainSubstring("Running after-install hook"))
fmt.Println(out)
machine.Sudo("sync")
Expand All @@ -73,14 +73,15 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-with-cli"), func() {
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)
} else {
out, err := machine.Sudo("kairos upgrade --force --image " + containerImage)
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)
}
machine.Sudo("reboot")
machine.EventuallyConnects(750)
machine.Reboot()

Eventually(func() error {
_, err := machine.SSHCommand("source /etc/os-release; echo $VERSION")
Expand All @@ -92,7 +93,7 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-with-cli"), func() {
v, _ = machine.SSHCommand("source /etc/os-release; echo $VERSION")
return v
// TODO: Add regex semver check here
}, 10*time.Minute, 10*time.Second).Should(ContainSubstring("v"))
}, 10*time.Minute, 10*time.Second).Should(ContainSubstring("v"), v)
})
})
})
11 changes: 6 additions & 5 deletions tests/upgrade_latest_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-latest-with-cli"), fu
err := machine.SendFile("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

out, _ := machine.Sudo("elemental install --cloud-init /tmp/config.yaml /dev/sda")
out, _ := machine.Sudo("kairos-agent manual-install --device auto /tmp/config.yaml")
Expect(out).Should(ContainSubstring("Running after-install hook"))
fmt.Println(out)
machine.Sudo("sync")
Expand All @@ -73,14 +73,16 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-latest-with-cli"), fu
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)
} else {
out, err := machine.Sudo("kairos upgrade --force --image " + containerImage)
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)
}
machine.Sudo("reboot")
machine.EventuallyConnects(750)

machine.Reboot()

Eventually(func() error {
_, err := machine.SSHCommand("source /etc/os-release; echo $VERSION")
Expand All @@ -92,8 +94,7 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-latest-with-cli"), fu
v, _ = machine.SSHCommand("source /etc/os-release; echo $VERSION")
return v
// TODO: Add regex semver check here
}, 10*time.Minute, 10*time.Second).Should(ContainSubstring("v"))
Expect(v).ToNot(Equal(currentVersion))
}, 10*time.Minute, 10*time.Second).ShouldNot(Equal(currentVersion))
})
})
})

0 comments on commit d68c9b7

Please sign in to comment.