Merge lp:~mvo/snappy/snappy-fix-bbb-crash into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt
Status: Work in progress
Proposed branch: lp:~mvo/snappy/snappy-fix-bbb-crash
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 278 lines (+54/-58)
5 files modified
partition/bootloader.go (+15/-2)
partition/bootloader_grub.go (+1/-1)
partition/bootloader_grub_test.go (+14/-29)
partition/bootloader_uboot.go (+7/-10)
partition/bootloader_uboot_test.go (+17/-16)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-fix-bbb-crash
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+263530@code.launchpad.net

Description of the change

Fix crash on the BBB when it tries to call BootloaderDir.

I'm not overly happy with the fix it would be better to have a single
bootloader dir. I hope we get there eventually.

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

please wait for this one, I want to land update-grub today and not deal with another merge

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

it also fixes this issue in some way

Unmerged revisions

547. By Michael Vogt

only set currentBootPath, otherBootPath if we have that

546. By Michael Vogt

no mountinfo anymore in the tests

545. By Michael Vogt

decouple partition/bootloader further

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'partition/bootloader.go'
2--- partition/bootloader.go 2015-06-11 09:38:18 +0000
3+++ partition/bootloader.go 2015-07-01 14:16:22 +0000
4@@ -19,6 +19,8 @@
5
6 package partition
7
8+import "path/filepath"
9+
10 const (
11 // bootloader variable used to denote which rootfs to boot from
12 bootloaderRootfsVar = "snappy_ab"
13@@ -84,13 +86,24 @@
14 var bootloader = bootloaderImpl
15
16 func bootloaderImpl(p *Partition) (bootLoader, error) {
17+ var currentBootPath, otherBootPath string
18+
19+ // FIXME: ugly
20+ if p != nil {
21+ currentRootfs := p.rootPartition().shortName
22+ currentBootPath = filepath.Join(bootloaderUbootDir, currentRootfs)
23+
24+ otherRootfs := p.otherRootPartition().shortName
25+ otherBootPath = filepath.Join(bootloaderUbootDir, otherRootfs)
26+ }
27+
28 // try uboot
29- if uboot := newUboot(p); uboot != nil {
30+ if uboot := newUboot(currentBootPath, otherBootPath); uboot != nil {
31 return uboot, nil
32 }
33
34 // no, try grub
35- if grub := newGrub(p); grub != nil {
36+ if grub := newGrub(currentBootPath, otherBootPath); grub != nil {
37 return grub, nil
38 }
39
40
41=== modified file 'partition/bootloader_grub.go'
42--- partition/bootloader_grub.go 2015-06-11 09:16:26 +0000
43+++ partition/bootloader_grub.go 2015-07-01 14:16:22 +0000
44@@ -54,7 +54,7 @@
45 const bootloaderNameGrub bootloaderName = "grub"
46
47 // newGrub create a new Grub bootloader object
48-func newGrub(partition *Partition) bootLoader {
49+func newGrub(currentBootPath, otherBootPath string) bootLoader {
50 if !helpers.FileExists(bootloaderGrubConfigFile) || !helpers.FileExists(bootloaderGrubUpdateCmd) {
51 return nil
52 }
53
54=== modified file 'partition/bootloader_grub_test.go'
55--- partition/bootloader_grub_test.go 2015-06-11 09:16:26 +0000
56+++ partition/bootloader_grub_test.go 2015-07-01 14:16:22 +0000
57@@ -49,16 +49,14 @@
58 func (s *PartitionTestSuite) TestNewGrubNoGrubReturnsNil(c *C) {
59 bootloaderGrubConfigFile = "no-such-dir"
60
61- partition := New()
62- g := newGrub(partition)
63+ g := newGrub("a", "b")
64 c.Assert(g, IsNil)
65 }
66
67 func (s *PartitionTestSuite) TestNewGrub(c *C) {
68 s.makeFakeGrubEnv(c)
69
70- partition := New()
71- g := newGrub(partition)
72+ g := newGrub("a", "b")
73 c.Assert(g, NotNil)
74 c.Assert(g.Name(), Equals, bootloaderNameGrub)
75 }
76@@ -76,28 +74,23 @@
77 s.makeFakeGrubEnv(c)
78 allCommands = []singleCommand{}
79
80- partition := New()
81- g := newGrub(partition)
82+ g := newGrub("a", "b")
83 c.Assert(g, NotNil)
84 err := g.ToggleRootFS("b")
85 c.Assert(err, IsNil)
86
87- // this is always called
88- mp := singleCommand{"/bin/mountpoint", mountTarget}
89- c.Assert(allCommands[0], DeepEquals, mp)
90-
91 expectedGrubUpdate := singleCommand{"/usr/sbin/chroot", mountTarget, bootloaderGrubUpdateCmd}
92- c.Assert(allCommands[1], DeepEquals, expectedGrubUpdate)
93+ c.Assert(allCommands[0], DeepEquals, expectedGrubUpdate)
94
95 expectedGrubSet := singleCommand{bootloaderGrubEnvCmd, bootloaderGrubEnvFile, "set", "snappy_mode=try"}
96- c.Assert(allCommands[2], DeepEquals, expectedGrubSet)
97+ c.Assert(allCommands[1], DeepEquals, expectedGrubSet)
98
99 // the https://developer.ubuntu.com/en/snappy/porting guide says
100 // we always use the short names
101 expectedGrubSet = singleCommand{bootloaderGrubEnvCmd, bootloaderGrubEnvFile, "set", "snappy_ab=b"}
102- c.Assert(allCommands[3], DeepEquals, expectedGrubSet)
103+ c.Assert(allCommands[2], DeepEquals, expectedGrubSet)
104
105- c.Assert(len(allCommands), Equals, 4)
106+ c.Assert(len(allCommands), Equals, 3)
107 }
108
109 func mockGrubEditenvList(cmd ...string) (string, error) {
110@@ -109,8 +102,7 @@
111 s.makeFakeGrubEnv(c)
112 runCommandWithStdout = mockGrubEditenvList
113
114- partition := New()
115- g := newGrub(partition)
116+ g := newGrub("a", "b")
117
118 v, err := g.GetBootVar(bootloaderBootmodeVar)
119 c.Assert(err, IsNil)
120@@ -129,26 +121,19 @@
121 s.makeFakeGrubEnv(c)
122 allCommands = []singleCommand{}
123
124- partition := New()
125- g := newGrub(partition)
126+ g := newGrub("a", "b")
127 c.Assert(g, NotNil)
128 err := g.MarkCurrentBootSuccessful("a")
129 c.Assert(err, IsNil)
130
131- // this is always called
132- mp := singleCommand{"/bin/mountpoint", mountTarget}
133- c.Assert(allCommands[0], DeepEquals, mp)
134-
135 expectedGrubSet := singleCommand{bootloaderGrubEnvCmd, bootloaderGrubEnvFile, "unset", "snappy_trial_boot"}
136-
137- c.Assert(allCommands[1], DeepEquals, expectedGrubSet)
138+ c.Assert(allCommands[0], DeepEquals, expectedGrubSet)
139
140 expectedGrubSet2 := singleCommand{bootloaderGrubEnvCmd, bootloaderGrubEnvFile, "set", "snappy_ab=a"}
141-
142- c.Assert(allCommands[2], DeepEquals, expectedGrubSet2)
143+ c.Assert(allCommands[1], DeepEquals, expectedGrubSet2)
144
145 expectedGrubSet3 := singleCommand{bootloaderGrubEnvCmd, bootloaderGrubEnvFile, "set", "snappy_mode=regular"}
146-
147- c.Assert(allCommands[3], DeepEquals, expectedGrubSet3)
148-
149+ c.Assert(allCommands[2], DeepEquals, expectedGrubSet3)
150+
151+ c.Assert(allCommands, HasLen, 3)
152 }
153
154=== modified file 'partition/bootloader_uboot.go'
155--- partition/bootloader_uboot.go 2015-06-11 09:16:26 +0000
156+++ partition/bootloader_uboot.go 2015-07-01 14:16:22 +0000
157@@ -71,20 +71,17 @@
158 }
159
160 // newUboot create a new Grub bootloader object
161-func newUboot(partition *Partition) bootLoader {
162+func newUboot(currentBootPath, otherBootPath string) bootLoader {
163 if !helpers.FileExists(bootloaderUbootConfigFile) {
164 return nil
165 }
166
167- u := uboot{}
168-
169- currentRootfs := partition.rootPartition().shortName
170- u.currentBootPath = filepath.Join(bootloaderUbootDir, currentRootfs)
171-
172- otherRootfs := partition.otherRootPartition().shortName
173- u.otherBootPath = filepath.Join(bootloaderUbootDir, otherRootfs)
174-
175- return &u
176+ u := &uboot{
177+ currentBootPath: currentBootPath,
178+ otherBootPath: otherBootPath,
179+ }
180+
181+ return u
182 }
183
184 func (u *uboot) Name() bootloaderName {
185
186=== modified file 'partition/bootloader_uboot_test.go'
187--- partition/bootloader_uboot_test.go 2015-06-29 23:15:00 +0000
188+++ partition/bootloader_uboot_test.go 2015-07-01 14:16:22 +0000
189@@ -74,26 +74,31 @@
190 c.Assert(err, IsNil)
191 }
192
193+func (s *PartitionTestSuite) TestNewUbootBootDir(c *C) {
194+ s.makeFakeUbootEnv(c)
195+
196+ u := newUboot("a", "b")
197+ c.Assert(u.BootDir(), Matches, ".*/boot/uboot")
198+}
199+
200 func (s *PartitionTestSuite) TestNewUbootNoUbootReturnsNil(c *C) {
201- partition := New()
202- u := newUboot(partition)
203+ u := newUboot("a", "b")
204 c.Assert(u, IsNil)
205 }
206
207 func (s *PartitionTestSuite) TestNewUboot(c *C) {
208 s.makeFakeUbootEnv(c)
209
210- partition := New()
211- u := newUboot(partition)
212+ u := newUboot("a", "b")
213 c.Assert(u, NotNil)
214 c.Assert(u.Name(), Equals, bootloaderNameUboot)
215 }
216
217 func (s *PartitionTestSuite) TestUbootGetBootVar(c *C) {
218 s.makeFakeUbootEnv(c)
219-
220 partition := New()
221- u := newUboot(partition)
222+
223+ u := newUboot("a", "b")
224
225 nextBoot, err := u.GetBootVar(bootloaderRootfsVar)
226 c.Assert(err, IsNil)
227@@ -107,9 +112,9 @@
228
229 func (s *PartitionTestSuite) TestUbootToggleRootFS(c *C) {
230 s.makeFakeUbootEnv(c)
231-
232 partition := New()
233- u := newUboot(partition)
234+
235+ u := newUboot("a", "b")
236 c.Assert(u, NotNil)
237
238 err := u.ToggleRootFS("b")
239@@ -126,8 +131,7 @@
240 func (s *PartitionTestSuite) TestUbootGetEnvVar(c *C) {
241 s.makeFakeUbootEnv(c)
242
243- partition := New()
244- u := newUboot(partition)
245+ u := newUboot("a", "b")
246 c.Assert(u, NotNil)
247
248 v, err := u.GetBootVar(bootloaderBootmodeVar)
249@@ -252,8 +256,7 @@
250 c.Assert(err, IsNil)
251 c.Assert(helpers.FileExists(bootloaderUbootStampFile), Equals, true)
252
253- partition := New()
254- u := newUboot(partition)
255+ u := newUboot("a", "b")
256 c.Assert(u, NotNil)
257
258 // enter "try" mode so that we check to ensure that snappy
259@@ -288,8 +291,7 @@
260 atomiCall := false
261 atomicFileUpdate = func(a string, b []string) error { atomiCall = true; return atomicFileUpdateImpl(a, b) }
262
263- partition := New()
264- u := newUboot(partition)
265+ u := newUboot("a", "b")
266 c.Assert(u, NotNil)
267
268 c.Check(u.MarkCurrentBootSuccessful("a"), IsNil)
269@@ -305,8 +307,7 @@
270 atomiCall := false
271 atomicFileUpdate = func(a string, b []string) error { atomiCall = true; return atomicFileUpdateImpl(a, b) }
272
273- partition := New()
274- u := newUboot(partition)
275+ u := newUboot("a", "b")
276 c.Assert(u, NotNil)
277
278 c.Check(u.MarkCurrentBootSuccessful("a"), IsNil)

Subscribers

People subscribed via source and target branches