From cdee32d24585b59b84bd4c7e7c0b597065a29526 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Mon, 12 May 2014 15:20:08 -0700 Subject: [PATCH] refactor(systemd): don't allow users to set DropIn=true yet --- initialize/config_test.go | 22 +++++++++++++++++++++- system/systemd.go | 6 +++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/initialize/config_test.go b/initialize/config_test.go index 4a20e3f..a26af64 100644 --- a/initialize/config_test.go +++ b/initialize/config_test.go @@ -144,7 +144,7 @@ ssh_authorized_keys: ` cfg, err := NewCloudConfig(contents) if err != nil { - t.Fatalf("Encountered unexpected error :%v", err) + t.Fatalf("Encountered unexpected error: %v", err) } keys := cfg.SSHAuthorizedKeys @@ -162,6 +162,26 @@ func TestCloudConfigSerializationHeader(t *testing.T) { } } +// TestDropInIgnored asserts that users are unable to set DropIn=True on units +func TestDropInIgnored(t *testing.T) { + contents := ` +coreos: + units: + - name: test + dropin: true +` + cfg, err := NewCloudConfig(contents) + if err != nil || len(cfg.Coreos.Units) != 1 { + t.Fatalf("Encountered unexpected error: %v", err) + } + if len(cfg.Coreos.Units) != 1 || cfg.Coreos.Units[0].Name != "test" { + t.Fatalf("Expected 1 unit, but got %d: %v", len(cfg.Coreos.Units), cfg.Coreos.Units) + } + if cfg.Coreos.Units[0].DropIn { + t.Errorf("dropin option on unit in cloud-config was not ignored!") + } +} + func TestCloudConfigUsers(t *testing.T) { contents := ` users: diff --git a/system/systemd.go b/system/systemd.go index 0353c5c..48caaaf 100644 --- a/system/systemd.go +++ b/system/systemd.go @@ -27,7 +27,11 @@ type Unit struct { Runtime bool Content string Command string - DropIn bool // drop-in configuration? if so, a cloudinit.conf will be generated + + // For drop-in units, a cloudinit.conf is generated. + // This is currently unbound in YAML (and hence unsettable in cloud-config files) + // until the correct behaviour for multiple drop-in units is determined. + DropIn bool `yaml:"-"` } func (u *Unit) Type() string {