initialize: use correct heuristic to check if etcdenvironment is set

In some circumstances (e.g. nova-agent-watcher) cloudconfig files will
be created where the EtcdEnvironment is an empty map, and hence != nil.
If this is the case we should not do anything at all (because the user
hasn't explicitly asked us to configure etcd). This change standardises
behaviour with the check that we already do for FleetEnvironment.
This commit is contained in:
Jonathan Boulle 2014-08-11 15:34:35 -07:00
parent 97d5538533
commit dfb5b4fc3a
2 changed files with 14 additions and 2 deletions

View File

@ -39,7 +39,7 @@ func (ee EtcdEnvironment) String() (out string) {
// Units creates a Unit file drop-in for etcd, using any configured // Units creates a Unit file drop-in for etcd, using any configured
// options and adding a default MachineID if unset. // options and adding a default MachineID if unset.
func (ee EtcdEnvironment) Units(root string) ([]system.Unit, error) { func (ee EtcdEnvironment) Units(root string) ([]system.Unit, error) {
if ee == nil { if len(ee) < 1 {
return nil, nil return nil, nil
} }

View File

@ -113,8 +113,19 @@ Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
} }
} }
func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) { func TestEtcdEnvironmentEmptyNoOp(t *testing.T) {
ee := EtcdEnvironment{} ee := EtcdEnvironment{}
uu, err := ee.Units("")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(uu) > 0 {
t.Fatalf("Generated etcd units unexpectedly: %v")
}
}
func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) {
ee := EtcdEnvironment{"foo": "bar"}
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-") dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
@ -152,6 +163,7 @@ func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) {
} }
expect := `[Service] expect := `[Service]
Environment="ETCD_FOO=bar"
Environment="ETCD_NAME=node007" Environment="ETCD_NAME=node007"
` `
if string(contents) != expect { if string(contents) != expect {