2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-03-23 10:02:54 +01:00
|
|
|
"regexp"
|
2017-01-03 12:29:14 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIngnitionFilesystem(t *testing.T) {
|
|
|
|
testIgnition(t, `
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_filesystem" "foo" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "foo"
|
|
|
|
path = "/foo"
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_filesystem" "qux" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "qux"
|
|
|
|
mount {
|
|
|
|
device = "/qux"
|
|
|
|
format = "ext4"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:02:54 +01:00
|
|
|
data "ignition_filesystem" "baz" {
|
|
|
|
name = "baz"
|
|
|
|
mount {
|
|
|
|
device = "/baz"
|
|
|
|
format = "ext4"
|
|
|
|
create = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_filesystem" "bar" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "bar"
|
|
|
|
mount {
|
|
|
|
device = "/bar"
|
|
|
|
format = "ext4"
|
2017-03-23 10:02:54 +01:00
|
|
|
create = true
|
2017-01-03 12:29:14 +01:00
|
|
|
force = true
|
|
|
|
options = ["rw"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_config" "test" {
|
2017-01-03 12:29:14 +01:00
|
|
|
filesystems = [
|
2017-03-06 13:23:04 +01:00
|
|
|
"${data.ignition_filesystem.foo.id}",
|
|
|
|
"${data.ignition_filesystem.qux.id}",
|
2017-03-23 10:02:54 +01:00
|
|
|
"${data.ignition_filesystem.baz.id}",
|
2017-03-06 13:23:04 +01:00
|
|
|
"${data.ignition_filesystem.bar.id}",
|
2017-01-03 12:29:14 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
`, func(c *types.Config) error {
|
2017-03-23 10:02:54 +01:00
|
|
|
if len(c.Storage.Filesystems) != 4 {
|
2017-01-03 12:29:14 +01:00
|
|
|
return fmt.Errorf("disks, found %d", len(c.Storage.Filesystems))
|
|
|
|
}
|
|
|
|
|
|
|
|
f := c.Storage.Filesystems[0]
|
|
|
|
if f.Name != "foo" {
|
|
|
|
return fmt.Errorf("name, found %q", f.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount != nil {
|
|
|
|
return fmt.Errorf("mount, found %q", f.Mount.Device)
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(*f.Path) != "/foo" {
|
|
|
|
return fmt.Errorf("path, found %q", f.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
f = c.Storage.Filesystems[1]
|
|
|
|
if f.Name != "qux" {
|
|
|
|
return fmt.Errorf("name, found %q", f.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Device != "/qux" {
|
|
|
|
return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Format != "ext4" {
|
|
|
|
return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Create != nil {
|
2017-01-13 23:31:44 +01:00
|
|
|
return fmt.Errorf("mount, create was found %#v", f.Mount.Create)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
f = c.Storage.Filesystems[2]
|
2017-03-23 10:02:54 +01:00
|
|
|
if f.Name != "baz" {
|
|
|
|
return fmt.Errorf("name, found %q", f.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Device != "/baz" {
|
|
|
|
return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Format != "ext4" {
|
|
|
|
return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Create.Force != false {
|
|
|
|
return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
|
|
|
|
}
|
|
|
|
|
|
|
|
f = c.Storage.Filesystems[3]
|
2017-01-03 12:29:14 +01:00
|
|
|
if f.Name != "bar" {
|
|
|
|
return fmt.Errorf("name, found %q", f.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Device != "/bar" {
|
|
|
|
return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Format != "ext4" {
|
|
|
|
return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Mount.Create.Force != true {
|
2017-01-13 23:31:44 +01:00
|
|
|
return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(f.Mount.Create.Options) != 1 || f.Mount.Create.Options[0] != "rw" {
|
|
|
|
return fmt.Errorf("mount.0.options, found %q", f.Mount.Create.Options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2017-03-23 10:02:54 +01:00
|
|
|
|
|
|
|
func TestIngnitionFilesystemMissingCreate(t *testing.T) {
|
|
|
|
testIgnitionError(t, `
|
|
|
|
data "ignition_filesystem" "bar" {
|
|
|
|
name = "bar"
|
|
|
|
mount {
|
|
|
|
device = "/bar"
|
|
|
|
format = "ext4"
|
|
|
|
force = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "ignition_config" "test" {
|
|
|
|
filesystems = [
|
|
|
|
"${data.ignition_filesystem.bar.id}",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`, regexp.MustCompile("create should be true when force or options is used"))
|
|
|
|
}
|