system: embed config within EtcHosts and Update

This commit is contained in:
Alex Crawford 2014-10-23 11:44:15 -07:00
parent 5c5834863b
commit 562c474275
3 changed files with 13 additions and 13 deletions

View File

@ -28,11 +28,11 @@ import (
const DefaultIpv4Address = "127.0.0.1" const DefaultIpv4Address = "127.0.0.1"
type EtcHosts struct { type EtcHosts struct {
Config config.EtcHosts config.EtcHosts
} }
func (eh EtcHosts) generateEtcHosts() (out string, err error) { func (eh EtcHosts) generateEtcHosts() (out string, err error) {
if eh.Config != "localhost" { if eh.EtcHosts != "localhost" {
return "", errors.New("Invalid option to manage_etc_hosts") return "", errors.New("Invalid option to manage_etc_hosts")
} }
@ -47,7 +47,7 @@ func (eh EtcHosts) generateEtcHosts() (out string, err error) {
} }
func (eh EtcHosts) File() (*File, error) { func (eh EtcHosts) File() (*File, error) {
if eh.Config == "" { if eh.EtcHosts == "" {
return nil, nil return nil, nil
} }

View File

@ -39,8 +39,8 @@ const (
// implementation reading from the filesystem), and provides the system-specific // implementation reading from the filesystem), and provides the system-specific
// File() and Unit(). // File() and Unit().
type Update struct { type Update struct {
Config config.Update
ReadConfig func() (io.Reader, error) ReadConfig func() (io.Reader, error)
config.Update
} }
func DefaultReadConfig() (io.Reader, error) { func DefaultReadConfig() (io.Reader, error) {
@ -58,17 +58,17 @@ func DefaultReadConfig() (io.Reader, error) {
// configuration options are set in cloud-config) by either rewriting the // configuration options are set in cloud-config) by either rewriting the
// existing file on disk, or starting from `/usr/share/coreos/update.conf` // existing file on disk, or starting from `/usr/share/coreos/update.conf`
func (uc Update) File() (*File, error) { func (uc Update) File() (*File, error) {
if config.IsZero(uc.Config) { if config.IsZero(uc.Update) {
return nil, nil return nil, nil
} }
if err := config.AssertValid(uc.Config); err != nil { if err := config.AssertValid(uc.Update); err != nil {
return nil, err return nil, err
} }
// Generate the list of possible substitutions to be performed based on the options that are configured // Generate the list of possible substitutions to be performed based on the options that are configured
subs := map[string]string{} subs := map[string]string{}
uct := reflect.TypeOf(uc.Config) uct := reflect.TypeOf(uc.Update)
ucv := reflect.ValueOf(uc.Config) ucv := reflect.ValueOf(uc.Update)
for i := 0; i < uct.NumField(); i++ { for i := 0; i < uct.NumField(); i++ {
val := ucv.Field(i).String() val := ucv.Field(i).String()
if val == "" { if val == "" {
@ -118,7 +118,7 @@ func (uc Update) File() (*File, error) {
// - an update_engine Unit, if "group" or "server" was set in cloud-config // - an update_engine Unit, if "group" or "server" was set in cloud-config
func (uc Update) Units() []Unit { func (uc Update) Units() []Unit {
var units []Unit var units []Unit
if uc.Config.RebootStrategy != "" { if uc.Update.RebootStrategy != "" {
ls := &Unit{config.Unit{ ls := &Unit{config.Unit{
Name: locksmithUnit, Name: locksmithUnit,
Command: "restart", Command: "restart",
@ -126,14 +126,14 @@ func (uc Update) Units() []Unit {
Runtime: true, Runtime: true,
}} }}
if uc.Config.RebootStrategy == "off" { if uc.Update.RebootStrategy == "off" {
ls.Command = "stop" ls.Command = "stop"
ls.Mask = true ls.Mask = true
} }
units = append(units, *ls) units = append(units, *ls)
} }
if uc.Config.Group != "" || uc.Config.Server != "" { if uc.Update.Group != "" || uc.Update.Server != "" {
ue := Unit{config.Unit{ ue := Unit{config.Unit{
Name: updateEngineUnit, Name: updateEngineUnit,
Command: "restart", Command: "restart",

View File

@ -82,7 +82,7 @@ func TestUpdateUnits(t *testing.T) {
}}}, }}},
}, },
} { } {
units := Update{tt.config, testReadConfig("")}.Units() units := Update{Update: tt.config, ReadConfig: testReadConfig("")}.Units()
if !reflect.DeepEqual(tt.units, units) { if !reflect.DeepEqual(tt.units, units) {
t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.units, units) t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.units, units)
} }
@ -153,7 +153,7 @@ func TestUpdateFile(t *testing.T) {
}}, }},
}, },
} { } {
file, err := Update{tt.config, testReadConfig(tt.orig)}.File() file, err := Update{Update: tt.config, ReadConfig: testReadConfig(tt.orig)}.File()
if !reflect.DeepEqual(tt.err, err) { if !reflect.DeepEqual(tt.err, err) {
t.Errorf("bad error (%q): want %q, got %q", tt.config, tt.err, err) t.Errorf("bad error (%q): want %q, got %q", tt.config, tt.err, err)
} }