Skip to content

Commit

Permalink
ci/cli: add checksum check on downloaded OS image
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <ldevulder@suse.com>
  • Loading branch information
ldevulder committed Aug 29, 2024
1 parent 132395b commit 2831c22
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e_test

import (
"os"
"os/exec"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -304,29 +305,49 @@ func DownloadBuiltISO(ns, seedName, filename string) {
// Set minimal ISO file to 250MB
const minimalISOSize = 250 * 1024 * 1024

// Check that the seed image is correctly created
Eventually(func() string {
out, _ := kubectl.RunWithoutErr("get", "SeedImage",
By("Downloading image", func() {
// Check that the seed image is correctly created
Eventually(func() string {
out, _ := kubectl.RunWithoutErr("get", "SeedImage",
"--namespace", ns,
seedName,
"-o", "jsonpath={.status}")
return out
}, tools.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("downloadURL"))

// Get URL
seedImageURL, err := kubectl.RunWithoutErr("get", "SeedImage",
"--namespace", ns,
seedName,
"-o", "jsonpath={.status}")
return out
}, tools.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("downloadURL"))
"-o", "jsonpath={.status.downloadURL}")
Expect(err).To(Not(HaveOccurred()))

// Get URL
seedImageURL, err := kubectl.RunWithoutErr("get", "SeedImage",
"--namespace", ns,
seedName,
"-o", "jsonpath={.status.downloadURL}")
Expect(err).To(Not(HaveOccurred()))
// ISO file size should be greater than 500MB
Eventually(func() int64 {
// No need to check download status, file size at the end is enough
_ = tools.GetFileFromURL(seedImageURL, filename, false)
file, _ := os.Stat(filename)
return file.Size()
}, tools.SetTimeout(2*time.Minute), 10*time.Second).Should(BeNumerically(">", minimalISOSize))
})

By("Checking checksum", func() {
// Get checksum URL
checksumURL, err := kubectl.RunWithoutErr("get", "SeedImage",
"--namespace", ns,
seedName,
"-o", "jsonpath={.status.checksumURL}")
Expect(err).To(Not(HaveOccurred()))

// ISO file size should be greater than 500MB
Eventually(func() int64 {
// No need to check download status, file size at the end is enough
_ = tools.GetFileFromURL(seedImageURL, filename, false)
file, _ := os.Stat(filename)
return file.Size()
}, tools.SetTimeout(2*time.Minute), 10*time.Second).Should(BeNumerically(">", minimalISOSize))
// Download checksum file
checksumFile := filename + ".sha256"
_ = tools.GetFileFromURL(checksumURL, checksumFile, false)

// Check the checksum of downloaded image
// echo "$(cat foo) reset_test.go" | sha256sum --check
err = exec.Command("bash", "-c", "echo '$(cat "+checksumFile+") "+filename+"' | sha256sum --check").Run()
Expect(err).To(Not(HaveOccurred()))
})
}

/*
Expand Down

0 comments on commit 2831c22

Please sign in to comment.