Skip to content

Commit

Permalink
Migrate to a non-global VM object
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
  • Loading branch information
jimmykarily committed Apr 3, 2023
1 parent 042f683 commit f096f0d
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 169 deletions.
79 changes: 41 additions & 38 deletions tests/decentralized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ import (
)

var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), func() {
var vm VM

BeforeEach(func() {
EventuallyConnects()
_, vm = startVM()
vm.EventuallyConnects(1200)
})

AfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
gatherLogs()
gatherLogs(vm)
}
vm.Destroy(nil)
})

Context("live cd", func() {
It("has default service active", func() {
if isFlavor("alpine") {
out, _ := Sudo("rc-status")
out, _ := vm.Sudo("rc-status")
Expect(out).Should(ContainSubstring("kairos"))
Expect(out).Should(ContainSubstring("kairos-agent"))
} else {
Expand All @@ -36,30 +40,29 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
// return out
// }, 30*time.Second, 10*time.Second).Should(ContainSubstring("no network token"))

out, _ := Sudo("systemctl status kairos")
out, _ := vm.Sudo("systemctl status kairos")
Expect(out).Should(ContainSubstring("loaded (/etc/systemd/system/kairos.service; enabled; vendor preset: disabled)"))
}
})
})

Context("install", func() {
It("to disk with custom config", func() {
err := Machine.SendFile(os.Getenv("CLOUD_INIT"), "/tmp/config.yaml", "0770")
err := vm.Scp(os.Getenv("CLOUD_INIT"), "/tmp/config.yaml", "0770")
Expect(err).ToNot(HaveOccurred())

out, _ := Sudo("kairos-agent manual-install --device auto /tmp/config.yaml")
out, _ := vm.Sudo("kairos-agent manual-install --device auto /tmp/config.yaml")
Expect(out).Should(ContainSubstring("Running after-install hook"))
fmt.Println(out)
Sudo("sync")
detachAndReboot()
vm.Sudo("sync")
vm.Reboot()
})
})

Context("first-boot", func() {

It("has default services on", func() {
if isFlavor("alpine") {
out, _ := Sudo("rc-status")
out, _ := vm.Sudo("rc-status")
Expect(out).Should(ContainSubstring("kairos"))
Expect(out).Should(ContainSubstring("kairos-agent"))
} else {
Expand All @@ -68,10 +71,10 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
// return out
// }, 30*time.Second, 10*time.Second).Should(ContainSubstring("no network token"))

out, _ := Sudo("systemctl status kairos-agent")
out, _ := vm.Sudo("systemctl status kairos-agent")
Expect(out).Should(ContainSubstring("loaded (/etc/systemd/system/kairos-agent.service; enabled; vendor preset: disabled)"))

out, _ = Sudo("systemctl status systemd-timesyncd")
out, _ = vm.Sudo("systemctl status systemd-timesyncd")
Expect(out).Should(ContainSubstring("loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: disabled)"))
}
})
Expand All @@ -82,30 +85,30 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
}

By("checking entries", func() {
state, _ := Sudo("blkid -L COS_STATE")
state, _ := vm.Sudo("blkid -L COS_STATE")
state = strings.TrimSpace(state)
out, _ := Sudo("blkid")
out, _ := vm.Sudo("blkid")
fmt.Println(out)
out, _ = Sudo("mkdir -p /tmp/mnt/STATE")
out, _ = vm.Sudo("mkdir -p /tmp/mnt/STATE")
fmt.Println(out)
out, _ = Sudo("mount " + state + " /tmp/mnt/STATE")
out, _ = vm.Sudo("mount " + state + " /tmp/mnt/STATE")
fmt.Println(out)
out, _ = Sudo("cat /tmp/mnt/STATE/grubmenu")
out, _ = vm.Sudo("cat /tmp/mnt/STATE/grubmenu")
Expect(out).Should(ContainSubstring("Kairos remote recovery"))

grub, _ := Sudo("cat /tmp/mnt/STATE/grub_oem_env")
grub, _ := vm.Sudo("cat /tmp/mnt/STATE/grub_oem_env")
Expect(grub).Should(ContainSubstring("default_menu_entry=Kairos"))

Sudo("umount /tmp/mnt/STATE")
vm.Sudo("umount /tmp/mnt/STATE")
})
})

It("configure k3s", func() {
_, err := Machine.Command("cat /run/cos/live_mode")
_, err := vm.Sudo("cat /run/cos/live_mode")
Expect(err).To(HaveOccurred())
if isFlavor("alpine") {
Eventually(func() string {
out, _ := Sudo("sudo cat /var/log/kairos/agent.log")
out, _ := vm.Sudo("sudo cat /var/log/kairos/agent.log")
fmt.Println(out)
return out
}, 20*time.Minute, 1*time.Second).Should(
Expand All @@ -115,7 +118,7 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
))
} else {
Eventually(func() string {
out, _ := Sudo("systemctl status kairos-agent")
out, _ := vm.Sudo("systemctl status kairos-agent")
return out
}, 30*time.Minute, 1*time.Second).Should(
Or(
Expand All @@ -127,7 +130,7 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu

PIt("configure edgevpn", func() {
Eventually(func() string {
out, _ := Sudo("cat /etc/systemd/system.conf.d/edgevpn-kairos.env")
out, _ := vm.Sudo("cat /etc/systemd/system.conf.d/edgevpn-kairos.env")
return out
}, 1*time.Minute, 1*time.Second).Should(
And(
Expand All @@ -137,29 +140,29 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu

It("has default image sizes", func() {
for _, p := range []string{"active.img", "passive.img"} {
out, _ := Sudo(`stat -c "%s" /run/initramfs/cos-state/cOS/` + p)
out, _ := vm.Sudo(`stat -c "%s" /run/initramfs/cos-state/cOS/` + p)
Expect(out).Should(ContainSubstring("3145728000"))
}
})

It("propagate kubeconfig", func() {
Eventually(func() string {
out, _ := Machine.Command("kairos get-kubeconfig")
out, _ := vm.Sudo("kairos get-kubeconfig")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("https:"))

Eventually(func() string {
Machine.Command("kairos get-kubeconfig > kubeconfig")
out, _ := Machine.Command("KUBECONFIG=kubeconfig kubectl get nodes -o wide")
vm.Sudo("kairos get-kubeconfig > kubeconfig")
out, _ := vm.Sudo("KUBECONFIG=kubeconfig kubectl get nodes -o wide")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("Ready"))
})

It("has roles", func() {
uuid, _ := Machine.Command("kairos-agent uuid")
uuid, _ := vm.Sudo("kairos-agent uuid")
Expect(uuid).ToNot(Equal(""))
Eventually(func() string {
out, _ := Machine.Command("kairos role list")
out, _ := vm.Sudo("kairos role list")
return out
}, 900*time.Second, 10*time.Second).Should(And(
ContainSubstring(uuid),
Expand All @@ -172,7 +175,7 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu

It("has machines with different IPs", func() {
Eventually(func() string {
out, _ := Machine.Command(`curl http://localhost:8080/api/machines`)
out, _ := vm.Sudo(`curl http://localhost:8080/api/machines`)
return out
}, 900*time.Second, 10*time.Second).Should(And(
ContainSubstring("10.1.0.1"),
Expand All @@ -185,16 +188,16 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
Skip("DNS not working on alpine yet")
}
// FIXUP: DNS needs reboot to take effect
Reboot()
vm.Reboot()
Eventually(func() string {
Machine.Command(`curl -X POST http://localhost:8080/api/dns --header "Content-Type: application/json" -d '{ "Regex": "foo.bar", "Records": { "A": "2.2.2.2" } }'`)
out, _ := Machine.Command("ping -c 1 foo.bar")
vm.Sudo(`curl -X POST http://localhost:8080/api/dns --header "Content-Type: application/json" -d '{ "Regex": "foo.bar", "Records": { "A": "2.2.2.2" } }'`)
out, _ := vm.Sudo("ping -c 1 foo.bar")
return out
}, 900*time.Second, 10*time.Second).Should(And(
ContainSubstring("2.2.2.2"),
))
Eventually(func() string {
out, _ := Machine.Command("ping -c 1 google.com")
out, _ := vm.Sudo("ping -c 1 google.com")
return out
}, 900*time.Second, 10*time.Second).Should(And(
ContainSubstring("64 bytes from"),
Expand All @@ -204,15 +207,15 @@ var _ = Describe("kairos decentralized k8s test", Label("decentralized-k8s"), fu
It("upgrades to a specific version", func() {
version, _ := Machine.Command("source /etc/os-release; echo $VERSION")

out, _ := Sudo("kairos-agent upgrade --image quay.io/kairos/kairos-opensuse:v1.0.0-rc2-k3sv1.21.14-k3s1")
out, _ := vm.Sudo("kairos-agent upgrade --image quay.io/kairos/kairos-opensuse:v1.0.0-rc2-k3sv1.21.14-k3s1")
Expect(out).To(ContainSubstring("Upgrade completed"))

Sudo("sync")
Reboot()
vm.Sudo("sync")
vm.Reboot()

EventuallyConnects(700)

version2, _ := Machine.Command("source /etc/os-release; echo $VERSION")
version2, _ := vm.Sudo("source /etc/os-release; echo $VERSION")
Expect(version).ToNot(Equal(version2))
})
})
Expand Down
24 changes: 14 additions & 10 deletions tests/install_qrcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ import (
)

var _ = Describe("kairos qr code install", Label("qrcode-install"), func() {
var vm VM

BeforeEach(func() {
EventuallyConnects()
_, vm = startVM()
vm.EventuallyConnects(1200)
})

AfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
gatherLogs()
gatherLogs(vm)
}
vm.Destroy(nil)
})

Context("live cd", func() {

It("has default service active", func() {
if isFlavor("alpine") {
out, _ := Sudo("rc-status")
out, _ := vm.Sudo("rc-status")
Expect(out).Should(ContainSubstring("kairos"))
Expect(out).Should(ContainSubstring("kairos-agent"))
} else {
Expand All @@ -35,15 +39,15 @@ var _ = Describe("kairos qr code install", Label("qrcode-install"), func() {
// return out
// }, 30*time.Second, 10*time.Second).Should(ContainSubstring("no network token"))

out, _ := Sudo("systemctl status kairos")
out, _ := vm.Sudo("systemctl status kairos")
Expect(out).Should(ContainSubstring("loaded (/etc/systemd/system/kairos.service; enabled; vendor preset: disabled)"))
}
})
})

Context("install", func() {
It("to disk with custom config", func() {
v, _ := Machine.Command("cat /proc/cmdline")
v, _ := vm.Sudo("cat /proc/cmdline")
Expect(v).To(ContainSubstring("rd.cos.disable"))

// sleep enough to give time to qr code to display.
Expand All @@ -66,23 +70,23 @@ var _ = Describe("kairos qr code install", Label("qrcode-install"), func() {
})
By("checking that the installer is running", func() {
Eventually(func() string {
v, _ = Machine.Command("ps aux")
v, _ = vm.Sudo("ps aux")
return v
}, 20*time.Minute, 10*time.Second).Should(ContainSubstring("elemental install"))
})

By("checking that the installer has terminated", func() {
Eventually(func() string {
v, _ = Machine.Command("ps aux")
v, _ = vm.Sudo("ps aux")
return v
}, 10*time.Minute, 10*time.Second).ShouldNot(ContainSubstring("elemental install"))
})

By("restarting on the installed system", func() {
detachAndReboot()
vm.Reboot()

Eventually(func() string {
v, _ = Machine.Command("cat /proc/cmdline")
v, _ = vm.Sudo("cat /proc/cmdline")
return v
}, 10*time.Minute, 10*time.Second).ShouldNot(ContainSubstring("rd.cos.disable"))
})
Expand Down
10 changes: 7 additions & 3 deletions tests/provider_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ import (
)

var _ = Describe("provider upgrade test", Label("provider-upgrade"), func() {
var vm VM

BeforeEach(func() {
EventuallyConnects()
_, vm = startVM()
vm.EventuallyConnects(1200)
})

AfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
gatherLogs()
gatherLogs(vm)
}
vm.Destroy(nil)
})

Context("agent.available_releases event", func() {
It("returns the available versions ordered, excluding '.img' tags", func() {
resultStr, _ := Sudo(`echo '{}' | /system/providers/agent-provider-kairos agent.available_releases`)
resultStr, _ := vm.Sudo(`echo '{}' | /system/providers/agent-provider-kairos agent.available_releases`)

var result pluggable.EventResponse

Expand Down
13 changes: 13 additions & 0 deletions tests/register_qrcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ import (
"github.com/kairos-io/kairos-sdk/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/spectrocloud/peg/matcher"
)

var _ = Describe("kairos qr code register", Label("qrcode-register"), func() {
var vm VM

BeforeEach(func() {
_, vm = startVM()
})

AfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
gatherLogs(vm)
}
vm.Destroy(nil)
})

Context("register", func() {
It("sends config over", func() {
Expand Down
Loading

0 comments on commit f096f0d

Please sign in to comment.