Skip to content

Commit

Permalink
[WIP] Add upgrade uki test
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Karakasilis <[email protected]>
  • Loading branch information
jimmykarily committed Aug 5, 2024
1 parent 2a7090f commit 685be83
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/reusable-uki-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,33 @@ jobs:
run: |
earthly +uki-iso \
--BASE_IMAGE=$TEMP_IMAGE \
--ENKI_OVERLAY_DIR=tests/assets/sysext/ --ENKI_KEYS_DIR=tests/assets/keys/
--ENKI_OVERLAY_DIR=tests/assets/sysext/ \
--ENKI_KEYS_DIR=tests/assets/keys/ \
--ENKI_FLAGS="--single-efi-cmdline \"MyEntry: nothing\""
- name: Create datasource iso 🔧
run: |
earthly +datasource-iso --CLOUD_CONFIG=tests/assets/uki-install.yaml
- name: Build uki upgrade image 🔧
run: |
rm -rf /tmp/unpacked
luet util unpack "${TEMP_IMAGE}" /tmp/unpacked
new_version="mynewversion"
sed -i 's/^KAIROS_VERSION=.*/KAIROS_VERSION=/'$new_version /tmp/unpacked/etc/os-release
echo "$new_version" > "${PWD}/build/expected_new_version"
earthly +uki-iso \
--BASE_IMAGE=dir:/tmp/unpacked \
--ENKI_OVERLAY_DIR=tests/assets/sysext/ \
--ENKI_KEYS_DIR=tests/assets/keys/ \
--ENKI_OUTPUT_TYPE=container
docker load -i build/*.tar
image=$(docker load -i build/*.tar | grep "Loaded image" | awk -F: '{ st = index($0,":");print substr($0,st+1)}')
rand=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 7)
temp_image=$(echo $image | sed "s/:6h/-${rand}:6h/")
docker tag $image $temp_image
docker push $temp_image
echo $temp_image > build/upgrade_image_name
- name: Run tests 🔧
env:
USE_QEMU: true
Expand All @@ -88,6 +111,8 @@ jobs:
run: |
export ISO=$(ls $PWD/build/kairos_*.iso)
export DATASOURCE=${PWD}/build/datasource.iso
export UPGRADE_IMAGE=$(cat "${PWD}/build/upgrade_image_name")
export EXPECTED_NEW_VERSION=$(cat "${PWD}/build/expected_new_version")
cp tests/go.* .
go run github.com/onsi/ginkgo/v2/ginkgo -v --label-filter "uki" --fail-fast -r ./tests/
- name: Install kairos-agent (for versioneer)
Expand Down
5 changes: 3 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ uki-iso:

IF [ "$ENKI_OVERLAY_DIR" != "" ]
COPY $ENKI_OVERLAY_DIR /overlay-iso
RUN --no-cache enki build-uki $BASE_IMAGE --output-dir /build/ -k /keys --output-type ${ENKI_OUTPUT_TYPE} --overlay-iso /overlay-iso ${ENKI_FLAGS}

RUN --no-cache echo $ENKI_FLAGS | xargs enki build-uki $BASE_IMAGE --output-dir /build/ -k /keys --output-type ${ENKI_OUTPUT_TYPE} --overlay-iso /overlay-iso
ELSE
RUN --no-cache enki build-uki $BASE_IMAGE --output-dir /build/ -k /keys --output-type ${ENKI_OUTPUT_TYPE} ${ENKI_FLAGS}
RUN --no-cache echo $ENKI_FLAGS | xargs enki build-uki $BASE_IMAGE --output-dir /build/ -k /keys --output-type ${ENKI_OUTPUT_TYPE}
END


Expand Down
22 changes: 22 additions & 0 deletions tests/uki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ var _ = Describe("kairos UKI test", Label("uki"), Ordered, func() {
if os.Getenv("FIRMWARE") == "" {
Fail("FIRMWARE environment variable set to a EFI firmware is needed for UKI test")
}

if os.Getenv("EXPECTED_NEW_VERSION") == "" {
Fail("EXPECTED_NEW_VERSION environment variable is needed for the UKI upgrade test")
}

if os.Getenv("UPGRADE_IMAGE") == "" {
Fail("UPGRADE_IMAGE environment variable is needed for the UKI upgrade test")
}
})

BeforeEach(func() {
Expand Down Expand Up @@ -256,5 +264,19 @@ var _ = Describe("kairos UKI test", Label("uki"), Ordered, func() {
out, err = vm.Sudo("ls /usr/local/after-reset-file")
Expect(err).ToNot(HaveOccurred(), out)
Expect(out).ToNot(MatchRegexp("No such file or directory"))

By("upgrading a single boot entry")
upgradeImage := os.Getenv("UPGRADE_IMAGE")
out, err = vm.Sudo(fmt.Sprintf("kairos-agent --debug upgrade --source oci:%s --single-entry myentry", upgradeImage))
Expect(err).ToNot(HaveOccurred(), out)
out, err = vm.Sudo("kairos-agent --debug bootentry --select myentry")
Expect(err).ToNot(HaveOccurred(), out)
vm.Reboot()
vm.EventuallyConnects(1200)

By("checking if upgrade worked")
out, err = vm.Sudo("cat /etc/os-release")
Expect(err).ToNot(HaveOccurred(), out)
Expect(out).To(MatchRegexp(fmt.Sprintf("KAIROS_VERSION=\"%s\"", os.Getenv("EXPECTED_NEW_VERSION"))))
})
})

0 comments on commit 685be83

Please sign in to comment.