Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <itxaka@kairos.io>
  • Loading branch information
Itxaka committed Jul 31, 2024
1 parent c9fe769 commit 71b6b0a
Showing 1 changed file with 91 additions and 46 deletions.
137 changes: 91 additions & 46 deletions e2e/bootable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,61 @@ package e2e_test
import (
"context"
"fmt"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"

"github.com/google/uuid"
process "github.com/mudler/go-processmanager"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sanity-io/litter"
. "github.com/spectrocloud/peg/matcher"
"github.com/spectrocloud/peg/pkg/machine"
"github.com/spectrocloud/peg/pkg/machine/types"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
)

var _ = Describe("bootable artifacts", Label("bootable"), func() {
When("when running a built iso", func() {
var vm VM
var vm VM
var err error

BeforeEach(func() {
_, ok := os.Stat(os.Getenv("ISO"))
Expect(ok).To(BeNil(), "ISO should exist")
vm, err := startVM()
Expect(err).ToNot(HaveOccurred())
By("Before connects")
vm.EventuallyConnects(1200)
By("After connects")
})
AfterEach(func() {
BeforeEach(func() {
_, ok := os.Stat(os.Getenv("ISO"))
Expect(ok).To(BeNil(), "ISO should exist")
vm, err = startVM()
Expect(err).ToNot(HaveOccurred())
By("Before connects")
vm.EventuallyConnects(1200)
By("After connects")
})
AfterEach(func() {
if CurrentSpecReport().Failed() {
gatherLogs(vm)
serial, _ := os.ReadFile(filepath.Join(vm.StateDir, "serial.log"))
//_ = os.MkdirAll("logs", os.ModePerm|os.ModeDir)
//_ = os.WriteFile(filepath.Join("logs", "serial.log"), serial, os.ModePerm)
GinkgoWriter.Print(serial)
_ = os.MkdirAll("logs", os.ModePerm|os.ModeDir)
_ = os.WriteFile(filepath.Join("logs", "serial.log"), serial, os.ModePerm)
fmt.Println(string(serial))
}

err := vm.Destroy(nil)
Expect(err).ToNot(HaveOccurred())
err := vm.Destroy(nil)
Expect(err).ToNot(HaveOccurred())
})
It("Should boot as expected", func() {
By("Have secureboot enabled", func() {
output, err := vm.Sudo("dmesg | grep -i secure")
Expect(err).ToNot(HaveOccurred(), output)
Expect(output).To(ContainSubstring("Secure boot enabled"))
})
It("Should boot as expected", func() {
By("Have secureboot enabled", func() {
//sudo, err := Sudo("dmesg | grep -i secure")
//fmt.Fprintf(GinkgoWriter, sudo)
//Expect(err).ToNot(HaveOccurred())
//output, err := vm.Sudo("dmesg | grep -i secure")
//Expect(err).ToNot(HaveOccurred(), output)
//Expect(output).To(ContainSubstring("Secure boot enabled"))
})

By("Have our custom keys only", func() {
//output, err := vm.Sudo("kairos-agent state get \"kairos.eficerts|tojson\"")
//Expect(err).ToNot(HaveOccurred(), output)
//fmt.Println(output)
//Expect(output).To(ContainSubstring("CIKEYS"))
})
By("Before second connect")
vm.EventuallyConnects(1200)
By("After second connect")

Expect(nil).To(BeNil())

By("Have our custom keys", func() {
output, err := vm.Sudo("kairos-agent state get \"kairos.eficerts|tojson\"")
Expect(err).ToNot(HaveOccurred(), output)
// Check the test keys we created for this
Expect(output).To(ContainSubstring("CIKEYS-db"))
Expect(output).To(ContainSubstring("CIKEYS-KEK"))
Expect(output).To(ContainSubstring("CIKEYS-PK"))
})
})
})
Expand Down Expand Up @@ -92,7 +88,6 @@ func startVM() (VM, error) {

m, err := machine.New(opts...)
Expect(err).ToNot(HaveOccurred())
fmt.Println(litter.Sdump(m.Config()))

vm := NewVM(m, stateDir)
_, err = vm.Start(context.Background())
Expand Down Expand Up @@ -261,3 +256,53 @@ func getFreePort() (port int, err error) {
}
return
}

func gatherLogs(vm VM) {
vm.Scp("assets/kubernetes_logs.sh", "/tmp/logs.sh", "0770")
vm.Sudo("sh /tmp/logs.sh > /run/kube_logs")
vm.Sudo("cat /oem/* > /run/oem.yaml")
vm.Sudo("cat /etc/resolv.conf > /run/resolv.conf")
vm.Sudo("k3s kubectl get pods -A -o json > /run/pods.json")
vm.Sudo("k3s kubectl get events -A -o json > /run/events.json")
vm.Sudo("cat /proc/cmdline > /run/cmdline")
vm.Sudo("chmod 777 /run/events.json")

vm.Sudo("df -h > /run/disk")
vm.Sudo("mount > /run/mounts")
vm.Sudo("blkid > /run/blkid")
vm.Sudo("dmesg > /run/dmesg.log")

// zip all files under /var/log/kairos
vm.Sudo("tar -czf /run/kairos-agent-logs.tar.gz /var/log/kairos")

vm.GatherAllLogs(
[]string{
"edgevpn@kairos",
"kairos-agent",
"cos-setup-boot",
"cos-setup-network",
"cos-setup-reconcile",
"kairos",
"k3s",
"k3s-agent",
},
[]string{
"/var/log/edgevpn.log",
"/var/log/kairos/agent.log",
"/run/pods.json",
"/run/disk",
"/run/mounts",
"/run/blkid",
"/run/events.json",
"/run/kube_logs",
"/run/cmdline",
"/run/oem.yaml",
"/run/resolv.conf",
"/run/dmesg.log",
"/run/immucore/immucore.log",
"/run/immucore/initramfs_stage.log",
"/run/immucore/rootfs_stage.log",
"/tmp/ovmf_debug.log",
"/run/kairos-agent-logs.tar.gz",
})
}

0 comments on commit 71b6b0a

Please sign in to comment.