From e6593d49e6f7fc5e0e273b7f70bb7de458dbebc5 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Fri, 21 Nov 2014 10:41:03 -0800 Subject: [PATCH] config/update: add "off" as a valid strategy It was assumed that the user would specify the reboot strategy as an unquoted value. In the case that they turn off updates, `off` is interpreted as a boolean and the normalization pass converts that to `false`. In the event that the user uses `"off"`, it's interpreted as a string and not modified. --- config/config_test.go | 1 + config/update.go | 2 +- system/update.go | 2 +- system/update_test.go | 19 ++++++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index 7d46003..e4c322d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -513,6 +513,7 @@ func TestNormalizeKeys(t *testing.T) { {"a:\n b:\n - key-name: the-value\n", "a:\n b:\n - key_name: the-value\n"}, {"coreos:\n update:\n reboot-strategy: off\n", "coreos:\n update:\n reboot_strategy: false\n"}, + {"coreos:\n update:\n reboot-strategy: 'off'\n", "coreos:\n update:\n reboot_strategy: \"off\"\n"}, } { out, err := normalizeConfig(tt.in) if err != nil { diff --git a/config/update.go b/config/update.go index adbda30..723f244 100644 --- a/config/update.go +++ b/config/update.go @@ -17,7 +17,7 @@ package config type Update struct { - RebootStrategy string `yaml:"reboot_strategy" env:"REBOOT_STRATEGY" valid:"best-effort,etcd-lock,reboot,false"` + RebootStrategy string `yaml:"reboot_strategy" env:"REBOOT_STRATEGY" valid:"best-effort,etcd-lock,reboot,off,false"` Group string `yaml:"group" env:"GROUP"` Server string `yaml:"server" env:"SERVER"` } diff --git a/system/update.go b/system/update.go index 5d6b066..bd745da 100644 --- a/system/update.go +++ b/system/update.go @@ -126,7 +126,7 @@ func (uc Update) Units() []Unit { Runtime: true, }} - if uc.Update.RebootStrategy == "false" { + if uc.Update.RebootStrategy == "false" || uc.Update.RebootStrategy == "off" { ls.Command = "stop" ls.Mask = true } diff --git a/system/update_test.go b/system/update_test.go index 7b68172..4ebf70b 100644 --- a/system/update_test.go +++ b/system/update_test.go @@ -80,6 +80,15 @@ func TestUpdateUnits(t *testing.T) { Mask: true, }}}, }, + { + config: config.Update{RebootStrategy: "off"}, + units: []Unit{{config.Unit{ + Name: "locksmithd.service", + Command: "stop", + Runtime: true, + Mask: true, + }}}, + }, } { units := Update{Update: tt.config, ReadConfig: testReadConfig("")}.Units() if !reflect.DeepEqual(tt.units, units) { @@ -100,7 +109,7 @@ func TestUpdateFile(t *testing.T) { }, { config: config.Update{RebootStrategy: "wizzlewazzle"}, - err: &config.ErrorValid{Value: "wizzlewazzle", Field: "RebootStrategy", Valid: []string{"best-effort", "etcd-lock", "reboot", "false"}}, + err: &config.ErrorValid{Value: "wizzlewazzle", Field: "RebootStrategy", Valid: []string{"best-effort", "etcd-lock", "reboot", "off", "false"}}, }, { config: config.Update{Group: "master", Server: "http://foo.com"}, @@ -142,6 +151,14 @@ func TestUpdateFile(t *testing.T) { RawFilePermissions: "0644", }}, }, + { + config: config.Update{RebootStrategy: "off"}, + file: &File{config.File{ + Content: "REBOOT_STRATEGY=off\n", + Path: "etc/coreos/update.conf", + RawFilePermissions: "0644", + }}, + }, { config: config.Update{RebootStrategy: "etcd-lock"}, orig: "SERVER=https://example.com\nGROUP=thegroupc\nREBOOT_STRATEGY=awesome",