Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
x86_64)
echo "buildon='ubuntu-latest'" >> $GITHUB_OUTPUT
echo "testson='macos-latest'" >> $GITHUB_OUTPUT
echo "tests=['test-smoke', 'test-upgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT ;;
echo "tests=['test-upgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT ;;
aarch64)
echo "buildon=['self-hosted', 'arm64']" >> $GITHUB_OUTPUT
echo "testson=['self-hosted', 'arm64']" >> $GITHUB_OUTPUT
Expand All @@ -54,7 +54,7 @@ jobs:
enableCrossOsArchive: true
lookup-only: true
with:
path: ${{ github.workspace }}/build/*.iso
path: /tmp/*.iso
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }}
name: Build toolkit
Expand Down Expand Up @@ -182,3 +182,62 @@ jobs:
if: always()
run: |
make test-clean

test-installer:
needs:
- build-iso
- detect
runs-on: ${{ fromJson(needs.detect.outputs.tests-runs-on) }}
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: ${{ inputs.arch }}
COS_TIMEOUT: 1600
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Install deps
run: |
make test-deps
- run: |
git fetch --prune --unshallow
- name: Cached ISO
id: cache-iso
uses: actions/cache/restore@v3
env:
cache-name: pr-iso-build-${{ inputs.arch }}-${{ inputs.flavor }}
with:
path: /tmp/*.iso
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- if: ${{ env.ARCH == 'x86_64' }}
name: Run VM script dependencies
run: |
brew update; brew upgrade qemu
brew install bash coreutils
- if: ${{ env.ARCH == 'x86_64' }}
name: Prepare test (x86_64)
run: |
make ISO=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso ELMNTL_ACCEL=hvf ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=$(find /usr/local/Cellar/qemu -name edk2-${{ env.ARCH }}-code.fd -print -quit) prepare-installer-test
- if: ${{ env.ARCH == 'aarch64' }}
name: Prepare test (aarch64)
run: |
make ISO=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso ELMNTL_ACCEL=none ELMNTL_MACHINETYPE=virt ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=/usr/share/AAVMF/AAVMF_CODE.fd prepare-installer-test
- name: Run installer test
run: |
make ISO=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso test-installer
# TODO include other logs SUT collects on failure
- name: Upload serial console for installer tests
uses: actions/upload-artifact@v3
if: always()
with:
name: serial-${{ env.ARCH }}-${{ env.FLAVOR }}-installer.log
path: tests/serial.log
if-no-files-found: error
- name: Stop test VM
if: always()
run: |
make test-clean
5 changes: 5 additions & 0 deletions make/Makefile.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ test-clean:
@scripts/run_vm.sh stop
@scripts/run_vm.sh clean

.PHONY: test-installer
test-installer: prepare-installer-test
$(GINKGO) run $(GINKGO_ARGS) ./tests/installer
$(GINKGO) run $(GINKGO_ARGS) ./tests/smoke

.PHONY: test-smoke
test-smoke: prepare-test
$(GINKGO) run $(GINKGO_ARGS) ./tests/smoke
Expand Down
8 changes: 4 additions & 4 deletions scripts/run_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function start {
local accel_arg
local memory_arg="-m ${ELMNTL_MEMORY}"
local firmware_arg="-drive if=pflash,format=raw,readonly=on,file=${ELMNTL_FIRMWARE}"
local disk_arg="-hda ${ELMNTL_TESTDISK}"
local disk_arg="-drive file=${ELMNTL_TESTDISK},if=none,id=disk,format=qcow2,media=disk -device virtio-blk-pci,drive=disk,bootindex=1"
local serial_arg="-serial file:${ELMNTL_LOGFILE}"
local pidfile_arg="-pidfile ${ELMNTL_PIDFILE}"
local display_arg="-display ${ELMNTL_DISPLAY}"
Expand All @@ -41,8 +41,6 @@ function start {
local vmpid
local kvm_arg

[ -f "${base_disk}" ] || _abort "Disk not found: ${base_disk}"

if [ -f "${ELMNTL_PIDFILE}" ]; then
vmpid=$(cat "${ELMNTL_PIDFILE}")
if ps -p ${vmpid} > /dev/null; then
Expand All @@ -54,13 +52,15 @@ function start {
fi
fi

[ -f "${base_disk}" ] || _abort "Disk not found: ${base_disk}"

case "${base_disk}" in
*.qcow2)
qemu-img create -f qcow2 -b "${base_disk}" -F qcow2 "${ELMNTL_TESTDISK}" > /dev/null
;;
*.iso)
qemu-img create -f qcow2 "${ELMNTL_TESTDISK}" "${ELMNTL_DISKSIZE}" > /dev/null
cdrom_arg="-cdrom ${base_disk}"
cdrom_arg="-drive file=${base_disk},readonly=on,if=none,id=cdrom,media=cdrom -device virtio-scsi-pci,id=scsi0 -device scsi-cd,bus=scsi0.0,drive=cdrom,bootindex=2"
;;
*)
_abort "Expected a *.qcow2 or *.iso file"
Expand Down
83 changes: 83 additions & 0 deletions tests/installer/installer_efi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package cos_test

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
sut "github.com/rancher-sandbox/ele-testhelpers/vm"
)

var _ = Describe("Elemental Installer EFI tests", func() {
var s *sut.SUT

BeforeEach(func() {
s = sut.NewSUT()
s.EventuallyConnects()
})

Context("Using efi", func() {
// EFI variant tests is not able to set the boot order and there is no plan to let the user do so according to virtualbox
// So we need to manually eject/insert the cd to force the boot order. CD inserted -> boot from cd, CD empty -> boot from disk
BeforeEach(func() {
// Assert we are booting from CD before running the tests
By("Making sure we booted from CD")
ExpectWithOffset(1, s.BootFrom()).To(Equal(sut.LiveCD))
})
AfterEach(func() {
if CurrentSpecReport().Failed() {
s.GatherAllLogs()
}
})

Context("partition layout tests", func() {
Context("with partition layout", func() {
It("performs a standard install", func() {
err := s.SendFile("../assets/custom_partitions.yaml", "/etc/elemental/config.d/custom_partitions.yaml", "0770")
By("Running the elemental install with a layout file")
Expect(err).To(BeNil())
out, err := s.Command(s.ElementalCmd("install", "/dev/vda"))
fmt.Printf(out)
Expect(err).To(BeNil())
Expect(out).To(ContainSubstring("Mounting disk partitions"))
Expect(out).To(ContainSubstring("Partitioning device..."))
Expect(out).To(ContainSubstring("Running after-install hook"))

// Reboot so we boot into the just installed cos
s.Reboot()
By("Checking we booted from the installed cOS")
ExpectWithOffset(1, s.BootFrom()).To(Equal(sut.Active))
// check partition values
// Values have to match the yaml under ../assets/layout.yaml
// That is the file that the installer uses so partitions should match those values
disk := s.GetDiskLayout("/dev/vda")

for _, part := range []sut.PartitionEntry{
{
Label: "COS_STATE",
Size: 6144,
FsType: sut.Ext4,
},
{
Label: "COS_OEM",
Size: 128,
FsType: sut.Ext4,
},
{
Label: "COS_RECOVERY",
Size: 4096,
FsType: sut.Ext2,
},
{
Label: "COS_PERSISTENT",
Size: 8192,
FsType: sut.Ext2,
},
} {
CheckPartitionValues(disk, part)
}
})
})
})
})
})
21 changes: 21 additions & 0 deletions tests/installer/tests_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cos_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
sut "github.com/rancher-sandbox/ele-testhelpers/vm"
)

func TestTests(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Elemental Installer test Suite")
}

func CheckPartitionValues(diskLayout sut.DiskLayout, entry sut.PartitionEntry) {
part, err := diskLayout.GetPartition(entry.Label)
Expect(err).To(BeNil())
Expect((part.Size / 1024) / 1024).To(Equal(entry.Size))
Expect(part.FsType).To(Equal(entry.FsType))
}