Merge lp:~mvo/snappy/15.04-watchdog-config into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Michael Vogt
Status: Merged
Approved by: Michael Vogt
Approved revision: 473
Merged at revision: 476
Proposed branch: lp:~mvo/snappy/15.04-watchdog-config
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Prerequisite: lp:~mvo/snappy/15.04-ppp-config
Diff against target: 229 lines (+125/-15)
2 files modified
coreconfig/config.go (+66/-15)
coreconfig/config_test.go (+59/-0)
To merge this branch: bzr merge lp:~mvo/snappy/15.04-watchdog-config
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Sergio Schvezov Needs Fixing
Review via email: mp+270626@code.launchpad.net

This proposal supersedes a proposal from 2015-09-09.

Commit message

Enable watchdog configuration via ubuntu-core-config

Description of the change

Enable watchdog configuration via ubuntu-core-config

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Looks good, you just have the same error as in the modprobe one:
var [name] [type] = "string" (type is cruft)

review: Needs Fixing
lp:~mvo/snappy/15.04-watchdog-config updated
473. By Michael Vogt

merged parent

Revision history for this message
Michael Vogt (mvo) wrote :

Fixed, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'coreconfig/config.go'
2--- coreconfig/config.go 2015-09-11 16:21:49 +0000
3+++ coreconfig/config.go 2015-09-11 16:21:49 +0000
4@@ -42,9 +42,11 @@
5 )
6
7 var (
8- modprobePath = "/etc/modprobe.d/ubuntu-core.conf"
9- networkRoot = "/etc/network/interfaces.d/"
10- pppRoot = "/etc/ppp/"
11+ modprobePath = "/etc/modprobe.d/ubuntu-core.conf"
12+ networkRoot = "/etc/network/interfaces.d/"
13+ pppRoot = "/etc/ppp/"
14+ watchdogConfigPath = "/etc/watchdog.conf"
15+ watchdogStartupPath = "/etc/default/watchdog"
16 )
17
18 // ErrInvalidUnitStatus signals that a unit is not returning a status
19@@ -58,11 +60,17 @@
20 Modprobe *string `yaml:"modprobe,omitempty"`
21 Network []passthroughConfig `yaml:"network,omitempty"`
22 PPP []passthroughConfig `yaml:"ppp,omitempty"`
23+ Watchdog *watchdogConfig `yaml:"watchdog,omitempty"`
24 }
25
26 type passthroughConfig struct {
27- Name string `yaml:"name"`
28- Content string `yaml:"content"`
29+ Name string `yaml:"name,omitempty"`
30+ Content string `yaml:"content,omitempty"`
31+}
32+
33+type watchdogConfig struct {
34+ Startup string `yaml:"startup,omitempty"`
35+ Config string `yaml:"config,omitempty"`
36 }
37
38 type coreConfig struct {
39@@ -100,6 +108,10 @@
40 if err != nil {
41 return nil, err
42 }
43+ watchdog, err := getWatchdog()
44+ if err != nil {
45+ return nil, err
46+ }
47
48 config := &systemConfig{
49 Autopilot: &autopilot,
50@@ -108,6 +120,7 @@
51 Modprobe: &modprobe,
52 Network: network,
53 PPP: ppp,
54+ Watchdog: watchdog,
55 }
56
57 return config, nil
58@@ -218,6 +231,14 @@
59 if err := setPPP(newConfig.PPP); err != nil {
60 return "", err
61 }
62+ case "Watchdog":
63+ if oldConfig.Watchdog != nil && *oldConfig.Watchdog == *newConfig.Watchdog {
64+ continue
65+ }
66+
67+ if err := setWatchdog(newConfig.Watchdog); err != nil {
68+ return "", err
69+ }
70 }
71 }
72
73@@ -251,16 +272,6 @@
74 return ioutil.WriteFile(tzFile(), []byte(timezone), 0644)
75 }
76
77-// getModprobe returns the current modprobe config
78-var getModprobe = func() (string, error) {
79- modprobe, err := ioutil.ReadFile(modprobePath)
80- if err != nil && !os.IsNotExist(err) {
81- return "", err
82- }
83-
84- return string(modprobe), nil
85-}
86-
87 func getPassthrough(rootDir string) (pc []passthroughConfig, err error) {
88 filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
89 if info.IsDir() {
90@@ -312,11 +323,51 @@
91 return setPassthrough(pppRoot, pc)
92 }
93
94+// getModprobe returns the current modprobe config
95+var getModprobe = func() (string, error) {
96+ modprobe, err := ioutil.ReadFile(modprobePath)
97+ if err != nil && !os.IsNotExist(err) {
98+ return "", err
99+ }
100+
101+ return string(modprobe), nil
102+}
103+
104 // setModprobe sets the specified modprobe config
105 var setModprobe = func(modprobe string) error {
106 return ioutil.WriteFile(modprobePath, []byte(modprobe), 0644)
107 }
108
109+// getWatchdog returns the current watchdog config
110+var getWatchdog = func() (*watchdogConfig, error) {
111+ startup, err := ioutil.ReadFile(watchdogStartupPath)
112+ if err != nil && !os.IsNotExist(err) {
113+ return nil, err
114+ }
115+ config, err := ioutil.ReadFile(watchdogConfigPath)
116+ if err != nil && !os.IsNotExist(err) {
117+ return nil, err
118+ }
119+
120+ // nil to make the yaml empty
121+ if len(startup) == 0 && len(config) == 0 {
122+ return nil, nil
123+ }
124+
125+ return &watchdogConfig{
126+ Startup: string(startup),
127+ Config: string(config)}, nil
128+}
129+
130+// setWatchdog sets the specified watchdog config
131+var setWatchdog = func(wf *watchdogConfig) error {
132+ if err := ioutil.WriteFile(watchdogStartupPath, []byte(wf.Startup), 0644); err != nil {
133+ return err
134+ }
135+
136+ return ioutil.WriteFile(watchdogConfigPath, []byte(wf.Config), 0644)
137+}
138+
139 // for testing purposes
140 var (
141 cmdAutopilotEnabled = []string{"is-enabled", autopilotTimer}
142
143=== modified file 'coreconfig/config_test.go'
144--- coreconfig/config_test.go 2015-09-11 16:21:49 +0000
145+++ coreconfig/config_test.go 2015-09-11 16:21:49 +0000
146@@ -50,6 +50,8 @@
147 originalModprobePath = modprobePath
148 originalNetworkRoot = networkRoot
149 originalPppRoot = pppRoot
150+ originalWatchdogStartupPath = watchdogStartupPath
151+ originalWatchdogConfigPath = watchdogConfigPath
152 )
153
154 type ConfigTestSuite struct {
155@@ -79,6 +81,8 @@
156
157 networkRoot = c.MkDir()
158 pppRoot = c.MkDir()
159+ watchdogConfigPath = filepath.Join(c.MkDir(), "watchdog-config")
160+ watchdogStartupPath = filepath.Join(c.MkDir(), "watchdog-startup")
161 }
162
163 func (cts *ConfigTestSuite) TearDownTest(c *C) {
164@@ -100,6 +104,8 @@
165 modprobePath = originalModprobePath
166 networkRoot = originalNetworkRoot
167 pppRoot = originalPppRoot
168+ watchdogStartupPath = originalWatchdogStartupPath
169+ watchdogConfigPath = originalWatchdogConfigPath
170 }
171
172 // TestGet is a broad test, close enough to be an integration test for
173@@ -580,3 +586,56 @@
174 }
175 c.Assert(passthroughEqual(a, b), Equals, false)
176 }
177+
178+func (cts *ConfigTestSuite) TestWatchdogGet(c *C) {
179+ startup := "# some startup watchdog config"
180+ err := ioutil.WriteFile(watchdogStartupPath, []byte(startup), 0644)
181+ c.Assert(err, IsNil)
182+
183+ config := "# some watchdog config"
184+ err = ioutil.WriteFile(watchdogConfigPath, []byte(config), 0644)
185+ c.Assert(err, IsNil)
186+
187+ wc, err := getWatchdog()
188+ c.Assert(err, IsNil)
189+ c.Assert(wc, DeepEquals, &watchdogConfig{
190+ Startup: startup, Config: config,
191+ })
192+}
193+
194+func (cts *ConfigTestSuite) TestWatchdogSet(c *C) {
195+ wc := &watchdogConfig{
196+ Startup: "startup", Config: "secret",
197+ }
198+ err := setWatchdog(wc)
199+ c.Assert(err, IsNil)
200+
201+ content, err := ioutil.ReadFile(watchdogStartupPath)
202+ c.Assert(err, IsNil)
203+ c.Assert(string(content), Equals, wc.Startup)
204+
205+ content, err = ioutil.ReadFile(watchdogConfigPath)
206+ c.Assert(err, IsNil)
207+ c.Assert(string(content), Equals, wc.Config)
208+}
209+
210+func (cts *ConfigTestSuite) TestWatchdogSetViaYaml(c *C) {
211+ input := `
212+config:
213+ ubuntu-core:
214+ watchdog:
215+ startup: some startup
216+ config: some config
217+`
218+ _, err := Set(input)
219+ c.Assert(err, IsNil)
220+
221+ // ensure its really there
222+ content, err := ioutil.ReadFile(watchdogStartupPath)
223+ c.Assert(err, IsNil)
224+ c.Assert(string(content), Equals, "some startup")
225+
226+ content, err = ioutil.ReadFile(watchdogConfigPath)
227+ c.Assert(err, IsNil)
228+ c.Assert(string(content), Equals, "some config")
229+}

Subscribers

People subscribed via source and target branches