examples/profiles,bootcfg: Add basic profile validation and add profile names

This commit is contained in:
Dalton Hubble
2016-03-25 10:31:29 -07:00
parent 7d1fc770f4
commit d72c136590
14 changed files with 47 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ import (
// Config initializes a fileStore.
type Config struct {
Dir string
Root string
Groups []*storagepb.Group
}
@@ -27,7 +27,7 @@ func NewFileStore(config *Config) Store {
groups[group.Id] = group
}
return &fileStore{
root: config.Dir,
root: config.Root,
groups: groups,
}
}
@@ -63,6 +63,9 @@ func (s *fileStore) ProfileGet(id string) (*storagepb.Profile, error) {
if err != nil {
return nil, err
}
if err := profile.AssertValid(); err != nil {
return nil, err
}
return profile, err
}

View File

@@ -34,7 +34,7 @@ func TestProfileGet(t *testing.T) {
assert.Nil(t, err)
defer os.RemoveAll(dir)
store := NewFileStore(&Config{Dir: dir})
store := NewFileStore(&Config{Root: dir})
profile, err := store.ProfileGet(testProfile.Id)
assert.Equal(t, testProfile, profile)
assert.Nil(t, err)
@@ -51,7 +51,7 @@ func TestProfileList(t *testing.T) {
assert.Nil(t, err)
defer os.RemoveAll(dir)
store := NewFileStore(&Config{Dir: dir})
store := NewFileStore(&Config{Root: dir})
profiles, err := store.ProfileList()
assert.Nil(t, err)
if assert.Equal(t, 1, len(profiles)) {
@@ -67,7 +67,7 @@ func TestIgnitionGet(t *testing.T) {
assert.Nil(t, err)
defer os.RemoveAll(dir)
store := NewFileStore(&Config{Dir: dir})
store := NewFileStore(&Config{Root: dir})
ign, err := store.IgnitionGet("myignition.json")
assert.Equal(t, contents, ign)
assert.Nil(t, err)
@@ -81,7 +81,7 @@ func TestCloudGet(t *testing.T) {
assert.Nil(t, err)
defer os.RemoveAll(dir)
store := NewFileStore(&Config{Dir: dir})
store := NewFileStore(&Config{Root: dir})
cfg, err := store.CloudGet("cloudcfg.yaml")
assert.Nil(t, err)
assert.Equal(t, contents, cfg)

View File

@@ -6,6 +6,7 @@ import (
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
)
// fixedStore is used for testing purposes.
type fixedStore struct {
Groups map[string]*storagepb.Group
Profiles map[string]*storagepb.Profile

View File

@@ -0,0 +1,27 @@
package storagepb
import (
"encoding/json"
"errors"
)
var (
ErrIdRequired = errors.New("Profile Id is required")
)
// ParseProfile parses bytes into a Profile.
func ParseProfile(data []byte) (*Profile, error) {
profile := new(Profile)
err := json.Unmarshal(data, profile)
return profile, err
}
// AssertValid validates a Profile. Returns nil if there are no validation
// errors.
func (p *Profile) AssertValid() error {
// Id is required
if p.Id == "" {
return ErrIdRequired
}
return nil
}

View File

@@ -109,7 +109,7 @@ func main() {
// storage
store := storage.NewFileStore(&storage.Config{
Dir: flags.dataPath,
Root: flags.dataPath,
Groups: cfg.Groups,
})

View File

@@ -1,5 +1,6 @@
{
"id": "etcd",
"name": "etcd",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "etcd_proxy",
"name": "etcd_proxy",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "grub",
"name": "CoreOS via GRUB2",
"boot": {
"kernel": "(http;bootcfg.foo:8080)/assets/coreos/899.6.0/coreos_production_pxe.vmlinuz",
"initrd": ["(http;bootcfg.foo:8080)/assets/coreos/899.6.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "k8s-master-install",
"name": "Kubernetes Master Install",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "k8s-master",
"name": "Kubernetes Master",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "k8s-worker-install",
"name": "Kubernetes Worker Install",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "k8s-worker",
"name": "Kubernetes Worker",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "pxe-disk",
"name": "CoreOS with SSH",
"boot": {
"kernel": "/assets/coreos/962.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/962.0.0/coreos_production_pxe_image.cpio.gz"],

View File

@@ -1,5 +1,6 @@
{
"id": "pxe",
"name": "CoreOS with SSH",
"boot": {
"kernel": "/assets/coreos/962.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/962.0.0/coreos_production_pxe_image.cpio.gz"],