Skip to content

Commit

Permalink
🌱 Add 'found' to partition state (kairos-io#342)
Browse files Browse the repository at this point in the history
* 🌱 Add 'found' to partition state

This allows to programmatically query the state if partitions were found

Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com>

* 🤖 Add tests

Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com>

Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
  • Loading branch information
mudler authored Oct 31, 2022
1 parent 792bc39 commit 43abb17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions sdk/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PartitionState struct {
SizeBytes uint64 `yaml:"size_bytes" json:"size_bytes"`
Type string `yaml:"type" json:"type"`
IsReadOnly bool `yaml:"read_only" json:"read_only"`
Found bool `yaml:"found" json:"found"`
UUID string `yaml:"uuid" json:"uuid"` // This would be volume UUID on macOS, PartUUID on linux, empty on Windows
}

Expand All @@ -53,6 +54,7 @@ func detectPartition(b *block.Partition) PartitionState {
Label: b.Label,
MountPoint: b.MountPoint,
Mounted: b.MountPoint != "",
Found: true,
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/autoinstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
. "github.com/spectrocloud/peg/matcher"
)

var _ = Describe("kairos autoinstall test", Label("autoinstall-test"), func() {
var stateAssert = func(query, expected string) {
out, err := Sudo(fmt.Sprintf("kairos-agent state get %s", query))
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, out).To(ContainSubstring(expected))
}

stateAssert := func(query, expected string) {
out, err := Sudo(fmt.Sprintf("kairos-agent state get %s", query))
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, out).To(ContainSubstring(expected))
}
var _ = Describe("kairos autoinstall test", Label("autoinstall-test"), func() {

BeforeEach(func() {
if os.Getenv("CLOUD_INIT") == "" || !filepath.IsAbs(os.Getenv("CLOUD_INIT")) {
Expand Down Expand Up @@ -62,7 +62,6 @@ var _ = Describe("kairos autoinstall test", Label("autoinstall-test"), func() {

out, _ = Sudo("sudo lsblk")
fmt.Println(out)

})
})

Expand Down Expand Up @@ -154,6 +153,7 @@ var _ = Describe("kairos autoinstall test", Label("autoinstall-test"), func() {
Expect(out).To(ContainSubstring("boot: active_boot"))

stateAssert("oem.mounted", "true")
stateAssert("oem.found", "true")
stateAssert("persistent.mounted", "true")
stateAssert("state.mounted", "true")
stateAssert("oem.type", "ext4")
Expand Down
3 changes: 3 additions & 0 deletions tests/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var _ = Describe("kairos install test", Label("install-test"), func() {
})

testInstall := func(cloudConfig string, actual interface{}, m types.GomegaMatcher) {
stateAssert("persistent.found", "false")

t, err := ioutil.TempFile("", "test")
ExpectWithOffset(1, err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -94,6 +95,8 @@ stages:
out, _ = Sudo("cat /etc/foo")
return out
}, ContainSubstring("bar"))

stateAssert("persistent.found", "true")
})
It("with config_url", func() {
testInstall(`
Expand Down

0 comments on commit 43abb17

Please sign in to comment.