Merge lp:~jamesodhunt/snappy/log-commands-that-change-system-state into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by James Hunt
Status: Work in progress
Proposed branch: lp:~jamesodhunt/snappy/log-commands-that-change-system-state
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 351 lines (+120/-9)
12 files modified
cmd/snappy-go/cmd_booted.go (+12/-1)
cmd/snappy-go/cmd_hwassign.go (+8/-1)
cmd/snappy-go/cmd_hwunassign.go (+8/-1)
cmd/snappy-go/cmd_rollback.go (+8/-1)
cmd/snappy-go/cmd_update.go (+4/-0)
partition/partition.go (+16/-0)
partition/partition_test.go (+3/-0)
snappy/click.go (+4/-0)
snappy/install.go (+9/-1)
snappy/snapp.go (+9/-1)
snappy/systemimage.go (+31/-3)
snappy/systemimage_test.go (+8/-0)
To merge this branch: bzr merge lp:~jamesodhunt/snappy/log-commands-that-change-system-state
Reviewer Review Type Date Requested Status
John Lenton (community) Disapprove
Michael Vogt (community) Needs Information
Sergio Schvezov Pending
Review via email: mp+254405@code.launchpad.net

Description of the change

* Added logging calls for commands that modify the system state.
* partition/partition.go:
  - Added RootfsLabel() and OtherRootfsLabel() implementations to enable
    rich log messages.
* Upated tests for new functions.

This branch was rather awkward given the way we handle clicks and s-i parts differently. I've tried to keep the log calls as "high up" in the calling stack as possible, but on occasion you'll see that I had to dive down a little lower than desired to fit in with the current code structure.

Note too that there is a small amount of duplication in the logging output:

a) Installing and then removing a snap gives the following:

INFO:snappy:/home/james/go/src/launchpad.net/snappy/snappy/click.go:735:Installed webdm (version 0.1)
INFO:snappy:/home/james/go/src/launchpad.net/snappy/snappy/install.go:92:Installed com.ubuntu.snappy.webdm (version 0.1)
INFO:snappy:/home/james/go/src/launchpad.net/snappy/snappy/snapp.go:322:Removed webdm (version 0.1)

Which of the 2 "Installed" message do we want to keep?

b) s-i parts:

INFO:snappy:/home/james/go/src/launchpad.net/snappy/snappy/systemimage.go:202:Updated system-b partition to version 346
INFO:snappy:/home/james/go/src/launchpad.net/snappy/snappy/systemimage.go:142:Updated system to boot from system-b partition on next boot
INFO:snappy:/home/james/go/src/launchpad.net/snappy/cmd/snappy-go/cmd_update.go:66:Installed ubuntu-core (version 346)

I wonder if we could retain all the s-i messages since:

a) An installed message should be provided for all parts.
b) The other 2 Updated messages are useful as they provide details of the partition (essential IMHO).

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

I don't have answers to your questions (is an MP the right place to ask the questions? are you really asking, or is it your way of exploring future work?). But the branch looks good.

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

Thanks for working on this!

I started reviewing this branch but I think this needs a quick sync with Sergio before I continue. By doing most of the logging in cmd/snappy webdm will have to duplicate that code.

It seems worthwhile to talk about moving the cmd/ bits into snappy/partition so that he automatically benefits.

I still have some inline comments, it seems like there is value in extracting some of the common pattern(s) into helpers.

review: Needs Information
Revision history for this message
John Lenton (chipaca) wrote :

So, talking with mvo and sergiusens, we need to change the approach entirely: we need to change cmd_* to be as simple as possible, and pass loggers (and the other bits) into the library for the library itself to do the logging on the passed in loggers.

review: Disapprove

Unmerged revisions

268. By James Hunt

* Sync with lp:snappy.

267. By James Hunt

* Added logging calls for commands that modify the system state.
* partition/partition.go:
  - Added RootfsLabel() and OtherRootfsLabel() implementations to enable
    rich log messages.
* Upated tests for new functions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/snappy-go/cmd_booted.go'
2--- cmd/snappy-go/cmd_booted.go 2015-03-26 13:02:07 +0000
3+++ cmd/snappy-go/cmd_booted.go 2015-03-27 15:11:19 +0000
4@@ -21,6 +21,8 @@
5 "launchpad.net/snappy/logger"
6 "launchpad.net/snappy/priv"
7 "launchpad.net/snappy/snappy"
8+
9+ "github.com/juju/loggo"
10 )
11
12 type cmdBooted struct {
13@@ -46,5 +48,14 @@
14 return logger.LogError(err)
15 }
16
17- return logger.LogError(parts[0].(*snappy.SystemImagePart).MarkBootSuccessful())
18+ si := parts[0].(*snappy.SystemImagePart)
19+ if err = si.MarkBootSuccessful(); err != nil {
20+ return logger.LogError(err)
21+ }
22+
23+ l := loggo.GetLogger(logger.LoggerName)
24+ l.Infof("Partition %s (version %s) booted successfully",
25+ si.RootfsLabel(), si.Version())
26+
27+ return nil
28 }
29
30=== modified file 'cmd/snappy-go/cmd_hwassign.go'
31--- cmd/snappy-go/cmd_hwassign.go 2015-03-26 09:12:58 +0000
32+++ cmd/snappy-go/cmd_hwassign.go 2015-03-27 15:11:19 +0000
33@@ -20,6 +20,8 @@
34 import (
35 "fmt"
36
37+ "github.com/juju/loggo"
38+ "launchpad.net/snappy/logger"
39 "launchpad.net/snappy/priv"
40 "launchpad.net/snappy/snappy"
41 )
42@@ -59,6 +61,11 @@
43 return err
44 }
45
46- fmt.Printf("'%s' is now allowed to access '%s'\n", x.Positional.PackageName, x.Positional.DevicePath)
47+ msg := fmt.Sprintf("'%s' is now allowed to access '%s'", x.Positional.PackageName, x.Positional.DevicePath)
48+ fmt.Printf("%s\n", msg)
49+
50+ l := loggo.GetLogger(logger.LoggerName)
51+ l.Infof("%s", msg)
52+
53 return nil
54 }
55
56=== modified file 'cmd/snappy-go/cmd_hwunassign.go'
57--- cmd/snappy-go/cmd_hwunassign.go 2015-03-26 09:12:58 +0000
58+++ cmd/snappy-go/cmd_hwunassign.go 2015-03-27 15:11:19 +0000
59@@ -20,6 +20,8 @@
60 import (
61 "fmt"
62
63+ "github.com/juju/loggo"
64+ "launchpad.net/snappy/logger"
65 "launchpad.net/snappy/priv"
66 "launchpad.net/snappy/snappy"
67 )
68@@ -54,6 +56,11 @@
69 return err
70 }
71
72- fmt.Printf("'%s' is no longer allowed to access '%s'\n", x.Positional.PackageName, x.Positional.DevicePath)
73+ msg := fmt.Sprintf("'%s' is no longer allowed to access '%s'", x.Positional.PackageName, x.Positional.DevicePath)
74+ fmt.Printf("%s\n", msg)
75+
76+ l := loggo.GetLogger(logger.LoggerName)
77+ l.Infof("%s", msg)
78+
79 return nil
80 }
81
82=== modified file 'cmd/snappy-go/cmd_rollback.go'
83--- cmd/snappy-go/cmd_rollback.go 2015-03-26 09:12:58 +0000
84+++ cmd/snappy-go/cmd_rollback.go 2015-03-27 15:11:19 +0000
85@@ -20,6 +20,8 @@
86 import (
87 "fmt"
88
89+ "github.com/juju/loggo"
90+ "launchpad.net/snappy/logger"
91 "launchpad.net/snappy/priv"
92 "launchpad.net/snappy/snappy"
93 )
94@@ -61,7 +63,12 @@
95 if err != nil {
96 return err
97 }
98- fmt.Printf("Setting %s to version %s\n", pkg, nowVersion)
99+
100+ msg := fmt.Sprintf("Set %s to version %s", pkg, nowVersion)
101+ fmt.Printf("%s\n", msg)
102+
103+ l := loggo.GetLogger(logger.LoggerName)
104+ l.Infof("%s", msg)
105
106 return nil
107 }
108
109=== modified file 'cmd/snappy-go/cmd_update.go'
110--- cmd/snappy-go/cmd_update.go 2015-03-26 13:02:07 +0000
111+++ cmd/snappy-go/cmd_update.go 2015-03-27 15:11:19 +0000
112@@ -21,6 +21,8 @@
113 "fmt"
114 "os"
115
116+ "github.com/juju/loggo"
117+ "launchpad.net/snappy/logger"
118 "launchpad.net/snappy/priv"
119 "launchpad.net/snappy/snappy"
120 )
121@@ -60,6 +62,8 @@
122 if err := part.Install(pbar, 0); err != nil {
123 return err
124 }
125+ l := loggo.GetLogger(logger.LoggerName)
126+ l.Infof("Installed %s (version %s)", part.Name(), part.Version())
127 }
128
129 if len(updates) > 0 {
130
131=== modified file 'partition/partition.go'
132--- partition/partition.go 2015-03-26 09:05:27 +0000
133+++ partition/partition.go 2015-03-27 15:11:19 +0000
134@@ -142,6 +142,12 @@
135
136 // run the function f with the otherRoot mounted
137 RunWithOther(rw MountOption, f func(otherRoot string) (err error)) (err error)
138+
139+ // Returns the label for the current partition
140+ RootfsLabel() string
141+
142+ // Returns the label for the other partition
143+ OtherRootfsLabel() string
144 }
145
146 // Partition is the type to interact with the partition
147@@ -623,6 +629,16 @@
148 return nil
149 }
150
151+// RootfsLabel returns the partition label for the current rootfs.
152+func (p *Partition) RootfsLabel() string {
153+ return p.rootPartition().name
154+}
155+
156+// OtherRootfsLabel returns the partition label for the other rootfs.
157+func (p *Partition) OtherRootfsLabel() string {
158+ return p.otherRootPartition().name
159+}
160+
161 // Return pointer to blockDevice representing the "other" root
162 // filesystem (which is not currently mounted)
163 func (p *Partition) otherRootPartition() (result *blockDevice) {
164
165=== modified file 'partition/partition_test.go'
166--- partition/partition_test.go 2015-03-26 09:12:58 +0000
167+++ partition/partition_test.go 2015-03-27 15:11:19 +0000
168@@ -159,6 +159,9 @@
169 c.Assert(other.name, Equals, "system-b")
170 c.Assert(other.device, Equals, "/dev/sda4")
171 c.Assert(other.parentName, Equals, "/dev/sda")
172+
173+ c.Assert(p.RootfsLabel(), Equals, root.name)
174+ c.Assert(p.OtherRootfsLabel(), Equals, other.name)
175 }
176
177 func (s *PartitionTestSuite) TestRunWithOtherDualParitionRO(c *C) {
178
179=== modified file 'snappy/click.go'
180--- snappy/click.go 2015-03-27 11:36:27 +0000
181+++ snappy/click.go 2015-03-27 15:11:19 +0000
182@@ -42,6 +42,7 @@
183 "launchpad.net/snappy/helpers"
184 "launchpad.net/snappy/logger"
185
186+ "github.com/juju/loggo"
187 "github.com/mvo5/goconfigparser"
188 )
189
190@@ -734,6 +735,9 @@
191 return err
192 }
193
194+ l := loggo.GetLogger(logger.LoggerName)
195+ l.Infof("Installed %s (version %s)", manifest.Name, manifest.Version)
196+
197 return nil
198 }
199
200
201=== modified file 'snappy/install.go'
202--- snappy/install.go 2015-03-26 13:02:07 +0000
203+++ snappy/install.go 2015-03-27 15:11:19 +0000
204@@ -22,6 +22,7 @@
205 "os"
206 "strings"
207
208+ "github.com/juju/loggo"
209 "launchpad.net/snappy/logger"
210 )
211
212@@ -81,7 +82,14 @@
213 // act only on parts that are downloadable
214 if !part.IsInstalled() {
215 pbar := NewTextProgress(part.Name())
216- return logger.LogError(part.Install(pbar, flags))
217+ err = part.Install(pbar, flags)
218+
219+ if err != nil {
220+ return logger.LogError(err)
221+ }
222+
223+ l := loggo.GetLogger(logger.LoggerName)
224+ l.Infof("Installed %s (version %s)", part.Name(), part.Version())
225 }
226 }
227
228
229=== modified file 'snappy/snapp.go'
230--- snappy/snapp.go 2015-03-26 13:02:07 +0000
231+++ snappy/snapp.go 2015-03-27 15:11:19 +0000
232@@ -33,7 +33,9 @@
233 "time"
234
235 "launchpad.net/snappy/helpers"
236+ "launchpad.net/snappy/logger"
237
238+ "github.com/juju/loggo"
239 "gopkg.in/yaml.v2"
240 )
241
242@@ -313,7 +315,13 @@
243 return ErrPackageNotRemovable
244 }
245
246- return removeClick(s.basedir)
247+ if err = removeClick(s.basedir); err != nil {
248+ return logger.LogError(err)
249+ }
250+ l := loggo.GetLogger(logger.LoggerName)
251+ l.Infof("Removed %s (version %s)", s.m.Name, s.m.Version)
252+
253+ return nil
254 }
255
256 // Config is used to to configure the snap
257
258=== modified file 'snappy/systemimage.go'
259--- snappy/systemimage.go 2015-03-26 13:02:07 +0000
260+++ snappy/systemimage.go 2015-03-27 15:11:19 +0000
261@@ -27,7 +27,9 @@
262 "strings"
263 "time"
264
265+ "github.com/juju/loggo"
266 "launchpad.net/snappy/coreconfig"
267+ "launchpad.net/snappy/logger"
268 "launchpad.net/snappy/partition"
269
270 "github.com/mvo5/goconfigparser"
271@@ -127,6 +129,21 @@
272 return s.lastUpdate
273 }
274
275+// toggleNextBootAndLog toggles the rootfs that will be used for the
276+// next boot and logs details of the change.
277+func (s *SystemImagePart) toggleNextBootAndLog() (err error) {
278+ err = s.partition.ToggleNextBoot()
279+ if err != nil {
280+ return err
281+ }
282+
283+ l := loggo.GetLogger(logger.LoggerName)
284+ l.Infof("Updated system to boot from %s partition on next boot",
285+ s.partition.OtherRootfsLabel())
286+
287+ return nil
288+}
289+
290 // SetActive sets the snap active
291 func (s *SystemImagePart) SetActive() (err error) {
292 isNextBootOther := s.partition.IsNextBootOther()
293@@ -139,7 +156,7 @@
294 return nil
295 }
296
297- return s.partition.ToggleNextBoot()
298+ return s.toggleNextBootAndLog()
299 }
300
301 // Install installs the snap
302@@ -175,10 +192,16 @@
303
304 // Check that the final system state is as expected.
305 if err = s.verifyUpgradeWasApplied(); err != nil {
306- return err
307+ return logger.LogError(err)
308 }
309
310- return s.partition.ToggleNextBoot()
311+ l := loggo.GetLogger(logger.LoggerName)
312+
313+ l.Infof("Updated %s partition to version %s",
314+ s.partition.OtherRootfsLabel(),
315+ s.version)
316+
317+ return s.toggleNextBootAndLog()
318 }
319
320 // Ensure the expected version update was applied to the expected partition.
321@@ -244,6 +267,11 @@
322 return s.partition.MarkBootSuccessful()
323 }
324
325+// RootfsLabel returns the label for the current root filesystem
326+func (s *SystemImagePart) RootfsLabel() string {
327+ return s.partition.RootfsLabel()
328+}
329+
330 // Channel returns the system-image-server channel used
331 func (s *SystemImagePart) Channel() string {
332 return s.channelName
333
334=== modified file 'snappy/systemimage_test.go'
335--- snappy/systemimage_test.go 2015-03-26 09:12:58 +0000
336+++ snappy/systemimage_test.go 2015-03-27 15:11:19 +0000
337@@ -167,6 +167,14 @@
338 return f("/other")
339 }
340
341+func (p *MockPartition) RootfsLabel() string {
342+ return ""
343+}
344+
345+func (p *MockPartition) OtherRootfsLabel() string {
346+ return ""
347+}
348+
349 func (s *SITestSuite) TestSystemImagePartInstallUpdatesPartition(c *C) {
350 // add a update
351 mockSystemImageIndexJSON = fmt.Sprintf(mockSystemImageIndexJSONTemplate, "2")

Subscribers

People subscribed via source and target branches