Skip to content

Commit

Permalink
🤖 Netboot testing (#523)
Browse files Browse the repository at this point in the history
* Create earthly target and test for netboot

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Add new tests to the pipeline

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Fix typo

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Update tests/tests_suite_test.go

Signed-off-by: Ettore Di Giacinto <[email protected]>

Signed-off-by: Dimitris Karakasilis <[email protected]>
Signed-off-by: Ettore Di Giacinto <[email protected]>
Co-authored-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
jimmykarily and mudler authored Dec 3, 2022
1 parent bbf02f4 commit c9d239c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ jobs:
./earthly.sh +datasource-iso --CLOUD_CONFIG=tests/assets/autoinstall.yaml
./earthly.sh +run-qemu-datasource-tests --TEST_SUITE=reset-test --FLAVOR=${{ matrix.flavor }}
qemu-netboot-tests:
needs:
# Not really needs this, but it's a temporary "hack" to run them in sequence
# TODO: Use built artifacts and don't rebuild them in the run-qemu-netboot-tests target
- build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- flavor: "alpine-opensuse-leap"
- flavor: "opensuse"
- flavor: "ubuntu"
steps:
- uses: actions/checkout@v3
- run: |
./earthly.sh +run-qemu-netboot-test --TEST_SUITE=netboot-test --FLAVOR=${{ matrix.flavor }}
upgrade-with-cli-test:
needs:
- build
Expand Down
41 changes: 40 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ netboot:
ARG ISO_NAME=${OS_ID}
ARG FROM_ARTIFACT
WORKDIR /build
ARG RELEASE_URL

COPY . .
IF [ "$FROM_ARTIFACT" = "" ]
Expand Down Expand Up @@ -360,11 +361,12 @@ ipxe-iso:
ARG ISO_NAME=${OS_ID}
COPY +version/VERSION ./
ARG VERSION=$(cat VERSION)
ARG RELEASE_URL
RUN echo "version ${VERSION}"

RUN git clone https://github.com/ipxe/ipxe
IF [ "$ipxe_script" = "" ]
COPY (+netboot/ipxe --VERSION=$VERSION) /build/ipxe/script.ipxe
COPY (+netboot/ipxe --VERSION=$VERSION --RELEASE_URL=$RELEASE_URL) /build/ipxe/script.ipxe
ELSE
COPY $ipxe_script /build/ipxe/script.ipxe
END
Expand Down Expand Up @@ -463,6 +465,43 @@ run-qemu-datasource-tests:

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

run-qemu-netboot-test:
FROM ubuntu

COPY . /test
WORKDIR /test

ARG ISO_NAME=${OS_ID}
COPY +version/VERSION ./
ARG VERSION=$(cat VERSION)

RUN apt update
RUN apt install -y qemu qemu-utils qemu-system golang git

# This is the IP at which qemu vm can see the host
ARG IP="10.0.2.2"

COPY (+netboot/squashfs --VERSION=$VERSION --RELEASE_URL=http://$IP) ./build/$VERSION/$ISO_NAME.squashfs
COPY (+netboot/kernel --VERSION=$VERSION --RELEASE_URL=http://$IP) ./build/$VERSION/$ISO_NAME-kernel
COPY (+netboot/initrd --VERSION=$VERSION --RELEASE_URL=http://$IP) ./build/$VERSION/$ISO_NAME-initrd
COPY (+netboot/ipxe --VERSION=$VERSION --RELEASE_URL=http://$IP) ./build/$VERSION/$ISO_NAME.ipxe
COPY (+ipxe-iso/iso --VERSION=$VERSION --RELEASE_URL=http://$IP) ./build/${ISO_NAME}-ipxe.iso

ENV ISO=/test/build/$ISO_NAME-ipxe.iso

ENV CREATE_VM=true
ENV USE_QEMU=true
ARG TEST_SUITE=netboot-test
ENV GOPATH="/go"
RUN go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo

# TODO: use --pull or something to cache the python image in Earthly
WITH DOCKER
RUN docker run -d -v $PWD/build:/build --workdir=/build \
--net=host -it python:3.11.0-bullseye python3 -m http.server 80 && \
PATH=$PATH:$GOPATH/bin ginkgo --label-filter "$TEST_SUITE" --fail-fast -r ./tests/
END

run-qemu-test:
FROM opensuse/leap
WORKDIR /test
Expand Down
22 changes: 22 additions & 0 deletions tests/netboot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mos_test

import (
"context"

. "github.com/spectrocloud/peg/matcher"

. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("kairos netboot test", Label("netboot-test"), func() {
BeforeEach(func() {
Machine.Create(context.Background())
})
AfterEach(func() {
Machine.Clean()
})

It("eventually boots", func() {
EventuallyConnects(1200)
})
})
4 changes: 4 additions & 0 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var _ = BeforeSuite(func() {

if os.Getenv("CREATE_VM") == "true" {
t, err := os.MkdirTemp("", "")
fmt.Printf("State dir = %+v\n", t)
Expect(err).ToNot(HaveOccurred())

sshPort = "2222"
Expand All @@ -91,9 +92,12 @@ var _ = BeforeSuite(func() {
types.WithSSHUser(user()),
types.WithSSHPass(pass()),
types.OnFailure(func(p *process.Process) {
defer GinkgoRecover()
out, _ := os.ReadFile(p.StdoutPath())
err, _ := os.ReadFile(p.StderrPath())
status, _ := p.ExitCode()
// Ginkgo doesn't print?
fmt.Printf("VM Aborted: %s %s Exit status: %s", out, err, status)
Fail(fmt.Sprintf("VM Aborted: %s %s Exit status: %s", out, err, status))
}),
types.WithStateDir(t),
Expand Down

0 comments on commit c9d239c

Please sign in to comment.