Skip to content

Commit

Permalink
Sync upgrade tests
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed May 25, 2023
1 parent ec443ae commit 905cd54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
19 changes: 10 additions & 9 deletions tests/upgrade_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
. "github.com/spectrocloud/peg/matcher"
)

// test ci
var _ = Describe("k3s upgrade manual test", Label("upgrade-with-cli"), func() {

var vm VM
containerImage := os.Getenv("CONTAINER_IMAGE")

var vm VM
BeforeEach(func() {
if containerImage == "" {
Fail("CONTAINER_IMAGE needs to be set")
}
_, vm = startVM()
vm.EventuallyConnects(1200)
})
Expand All @@ -35,19 +36,19 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-with-cli"), func() {

Context("upgrades", func() {
BeforeEach(func() {
if containerImage == "" {
Fail("CONTAINER_IMAGE needs to be set")
}

expectDefaultService(vm)
By("Copying config file")
err := vm.Scp("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())
By("Manually installing")
out, err := vm.Sudo("kairos-agent --debug manual-install --device auto /tmp/config.yaml")
Expect(err).ToNot(HaveOccurred(), string(out))
out, err := vm.Sudo("/bin/bash -c 'set -o pipefail && kairos-agent manual-install --debug --device auto /tmp/config.yaml 2>&1 | tee manual-install.txt'")
Expect(err).ToNot(HaveOccurred(), out)

Expect(out).Should(ContainSubstring("Running after-install hook"))
vm.Sudo("sync")

err = vm.DetachCD()
Expect(err).ToNot(HaveOccurred())
By("Rebooting")
vm.Reboot()
})
Expand Down
37 changes: 22 additions & 15 deletions tests/upgrade_latest_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mos_test
import (
"fmt"
"os"
"path/filepath"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -15,21 +16,31 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-latest-with-cli"), fu
containerImage := os.Getenv("CONTAINER_IMAGE")

BeforeEach(func() {
if containerImage == "" {
Fail("CONTAINER_IMAGE needs to be set")
}
_, vm = startVM()
vm.EventuallyConnects(1200)
})

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)
fmt.Println(string(serial))
}
Expect(vm.Destroy(nil)).ToNot(HaveOccurred())
})

Context("upgrades", func() {
BeforeEach(func() {
expectDefaultService(vm)

By("Copying config file")
err := vm.Scp("assets/config.yaml", "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

By("Manually installing")
out, err := vm.Sudo("/bin/bash -c 'set -o pipefail && kairos-agent manual-install --device auto /tmp/config.yaml 2>&1 | tee manual-install.txt'")
Expect(err).ToNot(HaveOccurred(), out)

Expand All @@ -38,26 +49,22 @@ var _ = Describe("k3s upgrade manual test", Label("upgrade-latest-with-cli"), fu

err = vm.DetachCD()
Expect(err).ToNot(HaveOccurred())
By("Rebooting")
vm.Reboot()
})

It("can upgrade to current image", func() {
currentVersion, err := vm.Sudo(getVersionCmd)
Expect(err).ToNot(HaveOccurred())
By(fmt.Sprintf("Checking current version: %s", currentVersion))
Expect(currentVersion).To(ContainSubstring("v"))
_, err = vm.Sudo("kairos-agent")
if err == nil {
out, err := vm.Sudo("kairos-agent upgrade --force --image " + containerImage)
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)
} else {
out, err := vm.Sudo("kairos upgrade --force --image " + containerImage)
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
}

By(fmt.Sprintf("Upgrading to: %s", containerImage))
out, err := vm.Sudo("kairos-agent upgrade --force --image " + containerImage)
Expect(err).ToNot(HaveOccurred(), string(out))
Expect(out).To(ContainSubstring("Upgrade completed"))
Expect(out).To(ContainSubstring(containerImage))
fmt.Println(out)

vm.Reboot()

Expand Down

0 comments on commit 905cd54

Please sign in to comment.