diff --git a/tests/install_target_test.go b/tests/install_target_test.go index 914949292..7274de9e0 100644 --- a/tests/install_target_test.go +++ b/tests/install_target_test.go @@ -2,8 +2,8 @@ package mos_test import ( "fmt" + "github.com/google/uuid" . "github.com/spectrocloud/peg/matcher" - "os" "strings" "time" @@ -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()) }) @@ -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") @@ -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"))