Skip to content

Commit

Permalink
Merge pull request ciao-project#214 from obedmr/config_initialize
Browse files Browse the repository at this point in the history
configuration: Add Init method for Configure payload default values
  • Loading branch information
Samuel Ortiz committed Jun 7, 2016
2 parents 3fe9832 + a90e59b commit 469ca8e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
11 changes: 1 addition & 10 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ func validMinConf(conf *payloads.Configure) bool {
conf.Configure.IdentityService.URL != "")
}

func fillDefaults(conf *payloads.Configure) {
conf.Configure.Scheduler.ConfigStorageType = payloads.Filesystem
conf.Configure.Controller.ComputePort = 8774
conf.Configure.ImageService.Type = payloads.Glance
conf.Configure.IdentityService.Type = payloads.Keystone
conf.Configure.Launcher.DiskLimit = true
conf.Configure.Launcher.MemoryLimit = true
}

// TODO: add etcd support related scheme(s)
func discoverDriver(uriStr string) (storageType payloads.StorageType, err error) {
uri, err := url.Parse(uriStr)
Expand All @@ -77,7 +68,7 @@ func Payload(blob []byte) (conf payloads.Configure, err error) {
if blob == nil {
return conf, fmt.Errorf("Unable to retrieve configuration from empty definition")
}
fillDefaults(&conf)
conf.InitDefaults()
err = yaml.Unmarshal(blob, &conf)

return conf, err
Expand Down
6 changes: 3 additions & 3 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func emptyPayload(p payloads.Configure) bool {
}

func fillPayload(conf *payloads.Configure) {
fillDefaults(conf)
conf.InitDefaults()
conf.Configure.Scheduler.ConfigStorageURI = storageURI
conf.Configure.Controller.HTTPSCACert = httpsCACert
conf.Configure.Controller.HTTPSKey = httpsKey
Expand Down Expand Up @@ -208,9 +208,9 @@ func saneDefaults(conf *payloads.Configure) bool {
conf.Configure.Launcher.MemoryLimit == true)
}

func TestFillDefaults(t *testing.T) {
func TestInitDefaults(t *testing.T) {
var conf payloads.Configure
fillDefaults(&conf)
conf.InitDefaults()
res := saneDefaults(&conf)
if res != true {
t.Fatalf("Expected true, got %v", res)
Expand Down
2 changes: 1 addition & 1 deletion configuration/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestFileStoreConfiguration(t *testing.T) {
var d driver
var conf payloads.Configure

fillDefaults(&conf)
conf.InitDefaults()
d = &file{}

err := d.storeConfiguration(conf)
Expand Down
10 changes: 10 additions & 0 deletions payloads/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ type ConfigurePayload struct {
type Configure struct {
Configure ConfigurePayload `yaml:"configure"`
}

// InitDefaults initializes default vaulues for Configure structure.
func (conf *Configure) InitDefaults() {
conf.Configure.Scheduler.ConfigStorageType = Filesystem
conf.Configure.Controller.ComputePort = 8774
conf.Configure.ImageService.Type = Glance
conf.Configure.IdentityService.Type = Keystone
conf.Configure.Launcher.DiskLimit = true
conf.Configure.Launcher.MemoryLimit = true
}

0 comments on commit 469ca8e

Please sign in to comment.