Skip to content

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 Sep 23, 2024
1 parent c98064e commit cddc008
Showing 1 changed file with 14 additions and 52 deletions.
66 changes: 14 additions & 52 deletions tests/install_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package mos_test

import (
"fmt"
"github.com/google/uuid"
. "github.com/spectrocloud/peg/matcher"
"os"
"strings"
"time"

Expand All @@ -14,12 +14,15 @@ import (
var _ = Describe("kairos install test different targets", Label("install-test-target"), func() {

var vm VM
var label string
var diskUUID uuid.UUID
BeforeEach(func() {

label = "TESTDISK"
diskUUID = uuid.New()
_, vm = startVM()
vm.EventuallyConnects(1200)
// Format the disk so it gets an uuid and label
_, err := vm.Sudo("mkfs.ext4 -L TESTDISK /dev/vda")
_, err := vm.Sudo(fmt.Sprintf("mkfs.ext4 -L %s -U %s /dev/vda", label, diskUUID.String()))
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -30,37 +33,16 @@ var _ = Describe("kairos install test different targets", Label("install-test-ta
Context("Selects the disk by uuid/label", func() {
It("Selects the correct disk if using uuid for target", func() {
expectSecureBootEnabled(vm)
// Get uuid of main disk
uuid, err := vm.Sudo("lsblk /dev/vda -o UUID -n")

cc := `#cloud-config
stages:
initramfs:
- name: "Set user and password"
users:
kairos:
passwd: "kairos"
hostname: kairos-{{ trunc 4 .Random }}
`

By("Using the following config")
fmt.Fprint(GinkgoWriter, cc)

t, err := os.CreateTemp("", "test")
ExpectWithOffset(1, err).ToNot(HaveOccurred())

defer os.RemoveAll(t.Name())
err = os.WriteFile(t.Name(), []byte(cc), os.ModePerm)
Expect(err).ToNot(HaveOccurred())

err = vm.Scp(t.Name(), "/tmp/config.yaml", "0770")
err := vm.Scp("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

var out string
// Test that install works
By("installing kairos", func() {
out, err = vm.Sudo(fmt.Sprintf("kairos-agent --debug manual-install --device /dev/disk/by-uuid/%s /tmp/config.yaml", uuid))
fmt.Fprint(GinkgoWriter, out)
installCmd := fmt.Sprintf("kairos-agent --debug manual-install --device /dev/disk/by-uuid/%s /tmp/config.yaml", diskUUID.String())
By(fmt.Sprintf("Running %s", installCmd))
out, err = vm.Sudo(installCmd)
Expect(err).ToNot(HaveOccurred(), out)
Expect(out).Should(ContainSubstring("Running after-install hook"))
vm.Sudo("sync")
Expand Down Expand Up @@ -109,35 +91,15 @@ stages:
})
It("Selects the correct disk if using label for target", func() {
expectSecureBootEnabled(vm)
// Get label of main disk
label, err := vm.Sudo("lsblk /dev/vda -o LABEL -n")

cc := `#cloud-config
stages:
initramfs:
- name: "Set user and password"
users:
kairos:
passwd: "kairos"
hostname: kairos-{{ trunc 4 .Random }}
`

By("Using the following config")
fmt.Fprintf(GinkgoWriter, cc)

t, err := os.CreateTemp("", "test")
ExpectWithOffset(1, err).ToNot(HaveOccurred())

defer os.RemoveAll(t.Name())
err = os.WriteFile(t.Name(), []byte(cc), os.ModePerm)
Expect(err).ToNot(HaveOccurred())

err = vm.Scp(t.Name(), "/tmp/config.yaml", "0770")
err := vm.Scp("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

var out string
By("installing kairos", func() {
out, err = vm.Sudo(fmt.Sprintf("kairos-agent --debug manual-install --device /dev/disk/by-label/%s /tmp/config.yaml", label))
installCmd := fmt.Sprintf("kairos-agent --debug manual-install --device /dev/disk/by-label/%s /tmp/config.yaml", label)
By(fmt.Sprintf("Running %s", installCmd))
out, err = vm.Sudo(installCmd)
Expect(err).ToNot(HaveOccurred(), out)
fmt.Fprint(GinkgoWriter, out)
Expect(out).Should(ContainSubstring("Running after-install hook"))
Expand Down

0 comments on commit cddc008

Please sign in to comment.