Merge lp:~elopio/snappy/integration-fix-rollback into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Needs review
Proposed branch: lp:~elopio/snappy/integration-fix-rollback
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/assertion_messages
Diff against target: 515 lines (+160/-122) (has conflicts)
4 files modified
_integration-tests/tests/rollback_test.go (+2/-1)
_integration-tests/testutils/partition/bootloader.go (+26/-4)
_integration-tests/testutils/partition/bootloader_test.go (+121/-106)
_integration-tests/testutils/partition/partition_test.go (+11/-11)
Text conflict in _integration-tests/tests/examples_test.go
Text conflict in _integration-tests/testutils/wait/wait_test.go
To merge this branch: bzr merge lp:~elopio/snappy/integration-fix-rollback
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+274651@code.launchpad.net

Commit message

Fixed the integration fake rollback test. It was using the deprecated uboot config file.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

This fixes the queries to the uboot, but doens't yet make the test pass in bbb.
I'm proposing this now as a clear bug fix, and I'll start to think what to do for the bbb. The problem is that it's being extra slow, so we have to increase the timeout. It would be nice to have a solution so the timeout is not hardcoded. And it would be even nicer if the bug that causes this to happen is fixed. Bug #1498293

Unmerged revisions

779. By Leo Arias

Merged with parent.

778. By Leo Arias

Check for the wait error.

777. By Leo Arias

Use the binary uboot configuration file.

776. By Leo Arias

Added a test for the grub confValue.

775. By Leo Arias

Replaced the confValue in the tests for a fake.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/tests/rollback_test.go'
2--- _integration-tests/tests/rollback_test.go 2015-10-16 00:47:50 +0000
3+++ _integration-tests/tests/rollback_test.go 2015-10-16 00:47:50 +0000
4@@ -44,7 +44,8 @@
5 common.RemoveRebootMark(c)
6 // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293
7 // TODO remove once the bug is fixed. --elopio - 2015-09-30
8- wait.ForFunction(c, "regular", partition.Mode)
9+ err := wait.ForFunction(c, "regular", partition.Mode)
10+ c.Assert(err, check.IsNil, check.Commentf("Failed to switch to regular mode: %s", err))
11 currentVersion := common.GetCurrentUbuntuCoreVersion(c)
12 c.Assert(currentVersion > common.GetSavedVersion(c), check.Equals, true,
13 check.Commentf("Rebooted to the wrong version: %d", currentVersion))
14
15=== modified file '_integration-tests/testutils/partition/bootloader.go'
16--- _integration-tests/testutils/partition/bootloader.go 2015-10-02 10:29:29 +0000
17+++ _integration-tests/testutils/partition/bootloader.go 2015-10-16 00:47:50 +0000
18@@ -25,13 +25,15 @@
19 "os"
20 "path/filepath"
21 "strings"
22+
23+ "github.com/mvo5/uboot-go/uenv"
24 )
25
26 const (
27 bootBase = "/boot"
28 ubootDir = bootBase + "/uboot"
29 grubDir = bootBase + "/grub"
30- ubootConfigFile = ubootDir + "/snappy-system.txt"
31+ ubootConfigFile = ubootDir + "/uboot.env"
32 grubConfigFile = grubDir + "/grubenv"
33 )
34
35@@ -41,6 +43,8 @@
36 // BootSystem proxies bootSystem
37 BootSystem = bootSystem
38
39+ confValue = getConfValue
40+
41 configFiles = map[string]string{"uboot": ubootConfigFile, "grub": grubConfigFile}
42 )
43
44@@ -101,14 +105,22 @@
45 return confValue("snappy_mode")
46 }
47
48-func confValue(key string) (partition string, err error) {
49+func getConfValue(key string) (value string, err error) {
50 system, err := BootSystem()
51 if err != nil {
52 return
53 }
54
55- bootConfigFile := configFiles[system]
56+ if system == "grub" {
57+ value, err = getGrubConfValue(key)
58+ } else if system == "uboot" {
59+ value, err = getUbootConfValue(key)
60+ }
61+ return
62+}
63
64+func getGrubConfValue(key string) (value string, err error) {
65+ bootConfigFile := configFiles["grub"]
66 file, err := os.Open(bootConfigFile)
67 if err != nil {
68 return
69@@ -123,7 +135,7 @@
70 if strings.HasPrefix(scanner.Text(), key) {
71 fields := strings.Split(scanner.Text(), "=")
72 if len(fields) > 1 {
73- partition = fields[1]
74+ value = fields[1]
75 }
76 return
77 }
78@@ -131,6 +143,16 @@
79 return
80 }
81
82+func getUbootConfValue(key string) (value string, err error) {
83+ bootConfigFile := configFiles["uboot"]
84+ env, err := uenv.Open(bootConfigFile)
85+ if err != nil {
86+ return "", err
87+ }
88+
89+ return env.Get(key), nil
90+}
91+
92 // OtherPartition returns the backup partition, a or b.
93 func OtherPartition(current string) string {
94 if current == "a" {
95
96=== modified file '_integration-tests/testutils/partition/bootloader_test.go'
97--- _integration-tests/testutils/partition/bootloader_test.go 2015-10-01 15:12:30 +0000
98+++ _integration-tests/testutils/partition/bootloader_test.go 2015-10-16 00:47:50 +0000
99@@ -23,8 +23,10 @@
100 "fmt"
101 "io/ioutil"
102 "os"
103+ "path"
104 "testing"
105
106+ "github.com/mvo5/uboot-go/uenv"
107 "gopkg.in/check.v1"
108 )
109
110@@ -36,25 +38,23 @@
111 backFilepathGlob func(string) ([]string, error)
112 filepathGlobFail bool
113 filepathGlobReturnValues []string
114+ backConfValue func(string) (string, error)
115+ fakeConf map[string]string
116 }
117
118 var _ = check.Suite(&bootloaderTestSuite{})
119
120-func createConfigFile(c *check.C, contents string) (name string) {
121- file, _ := ioutil.TempFile("", "snappy-bootloader-test")
122- err := ioutil.WriteFile(file.Name(), []byte(contents), 0644)
123- c.Assert(err, check.IsNil, check.Commentf("Error writing test bootloader file"))
124-
125- return file.Name()
126-}
127-
128 func (s *bootloaderTestSuite) SetUpSuite(c *check.C) {
129 s.backFilepathGlob = filepathGlob
130 filepathGlob = s.fakeFilepathGlob
131+ s.backConfValue = confValue
132+ confValue = s.fakeConfValue
133+ s.fakeConf = map[string]string{}
134 }
135
136 func (s *bootloaderTestSuite) TearDownSuite(c *check.C) {
137 filepathGlob = s.backFilepathGlob
138+ confValue = s.backConfValue
139 }
140
141 func (s *bootloaderTestSuite) SetUpTest(c *check.C) {
142@@ -73,6 +73,10 @@
143 return s.filepathGlobReturnValues, nil
144 }
145
146+func (s *bootloaderTestSuite) fakeConfValue(key string) (value string, err error) {
147+ return s.fakeConf[key], nil
148+}
149+
150 func (s *bootloaderTestSuite) TestOtherPartition(c *check.C) {
151 c.Assert(OtherPartition("a"), check.Equals, "b",
152 check.Commentf("Expected OtherPartition of 'a' to be 'b'"))
153@@ -98,11 +102,11 @@
154 func (s *bootloaderTestSuite) TestBootSystemCallsFilepathGlob(c *check.C) {
155 BootSystem()
156
157- path := bootBase + "/grub"
158- calls := s.filepathGlobCalls[path]
159+ p := bootBase + "/grub"
160+ calls := s.filepathGlobCalls[p]
161
162 c.Assert(calls, check.Equals, 1,
163- check.Commentf("Expected calls to filepath.Glob with path %s to be 1, %d found", path, calls))
164+ check.Commentf("Expected calls to filepath.Glob with path %s to be 1, %d found", p, calls))
165 }
166
167 func (s *bootloaderTestSuite) TestBootSystemForGrub(c *check.C) {
168@@ -126,6 +130,11 @@
169 }
170
171 func (s *bootloaderTestSuite) TestNextBootPartitionReturnsBootSystemError(c *check.C) {
172+ s.fakeConf = map[string]string{
173+ "snappy_mode": "try",
174+ "snappy_ab": "dummy",
175+ }
176+
177 backBootSystem := BootSystem
178 defer func() { BootSystem = backBootSystem }()
179 expectedErr := fmt.Errorf("Error from BootSystem!")
180@@ -139,30 +148,8 @@
181 check.Commentf("Expected error %v not found, %v", expectedErr, err))
182 }
183
184-func (s *bootloaderTestSuite) TestNextBootPartitionReturnsOsOpenError(c *check.C) {
185- backBootSystem := BootSystem
186- defer func() { BootSystem = backBootSystem }()
187- BootSystem = func() (system string, err error) {
188- return "not-expected-system", nil
189- }
190-
191- backConfigFiles := configFiles
192- defer func() { configFiles = backConfigFiles }()
193- configFiles = map[string]string{"not-expected-system": "not-a-file"}
194-
195- _, err := NextBootPartition()
196-
197- c.Assert(err, check.FitsTypeOf, &os.PathError{},
198- check.Commentf("Expected error type *os.PathError not found, %T", err))
199-}
200-
201 func (s *bootloaderTestSuite) TestNextBootPartitionReturnsEmptyIfPatternsNotFound(c *check.C) {
202- cfgFile := createConfigFile(c, "snappy_mode=try")
203- defer os.Remove(cfgFile)
204-
205- backConfigFiles := configFiles
206- defer func() { configFiles = backConfigFiles }()
207- configFiles = map[string]string{"test-system": cfgFile}
208+ s.fakeConf = map[string]string{"snappy_mode": "try"}
209
210 backBootSystem := BootSystem
211 defer func() { BootSystem = backBootSystem }()
212@@ -178,16 +165,10 @@
213 }
214
215 func (s *bootloaderTestSuite) TestNextBootPartitionReturnsSamePartitionForGrub(c *check.C) {
216- cfgFileContents := `blabla
217-snappy_mode=try
218-snappy_ab=a
219-blabla`
220- cfgFile := createConfigFile(c, cfgFileContents)
221- defer os.Remove(cfgFile)
222-
223- backConfigFiles := configFiles
224- defer func() { configFiles = backConfigFiles }()
225- configFiles = map[string]string{"grub": cfgFile}
226+ s.fakeConf = map[string]string{
227+ "snappy_mode": "try",
228+ "snappy_ab": "a",
229+ }
230
231 backBootSystem := BootSystem
232 defer func() { BootSystem = backBootSystem }()
233@@ -203,16 +184,10 @@
234 }
235
236 func (s *bootloaderTestSuite) TestNextBootPartitionReturnsOtherPartitionForUBoot(c *check.C) {
237- cfgFileContents := `blabla
238-snappy_mode=try
239-snappy_ab=a
240-blabla`
241- cfgFile := createConfigFile(c, cfgFileContents)
242- defer os.Remove(cfgFile)
243-
244- backConfigFiles := configFiles
245- defer func() { configFiles = backConfigFiles }()
246- configFiles = map[string]string{"uboot": cfgFile}
247+ s.fakeConf = map[string]string{
248+ "snappy_mode": "try",
249+ "snappy_ab": "a",
250+ }
251
252 backBootSystem := BootSystem
253 defer func() { BootSystem = backBootSystem }()
254@@ -228,20 +203,8 @@
255 }
256
257 func (s *bootloaderTestSuite) TestModeReturnsSnappyModeFromConf(c *check.C) {
258- cfgFileContents := `blabla
259-snappy_mode=test_mode
260-blabla`
261- cfgFile := createConfigFile(c, cfgFileContents)
262- defer os.Remove(cfgFile)
263-
264- backConfigFiles := configFiles
265- defer func() { configFiles = backConfigFiles }()
266- configFiles = map[string]string{"test-system": cfgFile}
267-
268- backBootSystem := BootSystem
269- defer func() { BootSystem = backBootSystem }()
270- BootSystem = func() (system string, err error) {
271- return "test-system", nil
272+ s.fakeConf = map[string]string{
273+ "snappy_mode": "test_mode",
274 }
275
276 mode, err := Mode()
277@@ -251,40 +214,22 @@
278 }
279
280 func (s *bootloaderTestSuite) TestCurrentPartitionNotOnTryMode(c *check.C) {
281- cfgFileContents := `blabla
282-snappy_mode=nottry
283-snappy_ab=test_partition
284-blabla`
285- cfgFile := createConfigFile(c, cfgFileContents)
286- defer os.Remove(cfgFile)
287-
288- backConfigFiles := configFiles
289- defer func() { configFiles = backConfigFiles }()
290- configFiles = map[string]string{"test-system": cfgFile}
291-
292- backBootSystem := BootSystem
293- defer func() { BootSystem = backBootSystem }()
294- BootSystem = func() (system string, err error) {
295- return "test-system", nil
296+ s.fakeConf = map[string]string{
297+ "snappy_mode": "nottry",
298+ "snappy_ab": "test_partition",
299 }
300
301- mode, err := CurrentPartition()
302+ part, err := CurrentPartition()
303
304 c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err))
305- c.Assert(mode, check.Equals, "test_partition", check.Commentf("Wrong partition"))
306+ c.Assert(part, check.Equals, "test_partition", check.Commentf("Wrong partition"))
307 }
308
309 func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsSamePartitionForUboot(c *check.C) {
310- cfgFileContents := `blabla
311-snappy_mode=try
312-snappy_ab=a
313-blabla`
314- cfgFile := createConfigFile(c, cfgFileContents)
315- defer os.Remove(cfgFile)
316-
317- backConfigFiles := configFiles
318- defer func() { configFiles = backConfigFiles }()
319- configFiles = map[string]string{"uboot": cfgFile}
320+ s.fakeConf = map[string]string{
321+ "snappy_mode": "try",
322+ "snappy_ab": "a",
323+ }
324
325 backBootSystem := BootSystem
326 defer func() { BootSystem = backBootSystem }()
327@@ -298,17 +243,11 @@
328 c.Assert(mode, check.Equals, "a", check.Commentf("Wrong partition"))
329 }
330
331-func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsOtherPartitionForUboot(c *check.C) {
332- cfgFileContents := `blabla
333-snappy_mode=try
334-snappy_ab=a
335-blabla`
336- cfgFile := createConfigFile(c, cfgFileContents)
337- defer os.Remove(cfgFile)
338-
339- backConfigFiles := configFiles
340- defer func() { configFiles = backConfigFiles }()
341- configFiles = map[string]string{"grub": cfgFile}
342+func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsOtherPartitionForGrub(c *check.C) {
343+ s.fakeConf = map[string]string{
344+ "snappy_mode": "try",
345+ "snappy_ab": "a",
346+ }
347
348 backBootSystem := BootSystem
349 defer func() { BootSystem = backBootSystem }()
350@@ -321,3 +260,79 @@
351 c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err))
352 c.Assert(mode, check.Equals, "b", check.Commentf("Wrong partition"))
353 }
354+
355+type confTestSuite struct {
356+ backBootSystem func() (string, error)
357+ system string
358+ backConfigFiles map[string]string
359+}
360+
361+var _ = check.Suite(&confTestSuite{})
362+
363+func (s *confTestSuite) SetUpSuite(c *check.C) {
364+ s.backBootSystem = BootSystem
365+ BootSystem = s.fakeBootSystem
366+ s.backConfigFiles = configFiles
367+}
368+
369+func (s *confTestSuite) fakeBootSystem() (system string, err error) {
370+ return s.system, nil
371+}
372+
373+func (s *confTestSuite) TearDownSuite(c *check.C) {
374+ BootSystem = s.backBootSystem
375+ configFiles = s.backConfigFiles
376+}
377+
378+func createConfigFile(c *check.C, system string, contents map[string]string) (name string) {
379+ if system == "grub" {
380+ name = createGrubConfigFile(c, contents)
381+ } else if system == "uboot" {
382+ name = createUbootConfigFile(c, contents)
383+ }
384+ return
385+}
386+
387+func createGrubConfigFile(c *check.C, contents map[string]string) (name string) {
388+ var contentsStr string
389+ for key, value := range contents {
390+ contentsStr += fmt.Sprintf("%s=%s\n", key, value)
391+ }
392+ file, err := ioutil.TempFile("", "snappy-grub-test")
393+ c.Assert(err, check.IsNil, check.Commentf("Error creating temp file: %s", err))
394+ err = ioutil.WriteFile(file.Name(), []byte(contentsStr), 0644)
395+ c.Assert(err, check.IsNil, check.Commentf("Error writing test bootloader file: %s", err))
396+
397+ return file.Name()
398+}
399+
400+func createUbootConfigFile(c *check.C, contents map[string]string) (name string) {
401+ tmpDir, err := ioutil.TempDir("", "snappy-uboot-test")
402+ c.Assert(err, check.IsNil, check.Commentf("Error creating temp dir: %s", err))
403+ fileName := path.Join(tmpDir, "uboot.env")
404+ env, err := uenv.Create(fileName, 4096)
405+ c.Assert(err, check.IsNil, check.Commentf("Error creating the uboot env file: %s", err))
406+ for key, value := range contents {
407+ env.Set(key, value)
408+ }
409+ err = env.Save()
410+ c.Assert(err, check.IsNil, check.Commentf("Error saving the uboot env file: %s", err))
411+ return fileName
412+}
413+
414+func (s *confTestSuite) TestGetConfValue(c *check.C) {
415+ for _, s.system = range []string{"grub", "uboot"} {
416+ cfgFileContents := map[string]string{
417+ "blabla1": "bla",
418+ "testkey": "testvalue",
419+ "blabla2": "bla",
420+ }
421+ cfgFile := createConfigFile(c, s.system, cfgFileContents)
422+ defer os.Remove(cfgFile)
423+ configFiles = map[string]string{s.system: cfgFile}
424+
425+ value, err := confValue("testkey")
426+ c.Check(err, check.IsNil, check.Commentf("Error getting configuration value: %s", err))
427+ c.Check(value, check.Equals, "testvalue", check.Commentf("Wrong configuration value"))
428+ }
429+}
430
431=== modified file '_integration-tests/testutils/partition/partition_test.go'
432--- _integration-tests/testutils/partition/partition_test.go 2015-10-02 13:10:24 +0000
433+++ _integration-tests/testutils/partition/partition_test.go 2015-10-16 00:47:50 +0000
434@@ -27,9 +27,9 @@
435 )
436
437 const (
438- path = "mypath"
439- writableCmd = "sudo mount -o remount,rw " + path
440- readonlyCmd = "sudo mount -o remount,ro " + path
441+ testPath = "mypath"
442+ writableCmd = "sudo mount -o remount,rw " + testPath
443+ readonlyCmd = "sudo mount -o remount,ro " + testPath
444 waitCmd = lsofNotBeingWritten
445 )
446
447@@ -86,14 +86,14 @@
448 }
449
450 func (s *partitionTestSuite) TestMakeWritableCallsExecCommand(c *check.C) {
451- err := MakeWritable(c, path)
452+ err := MakeWritable(c, testPath)
453
454 c.Assert(err, check.IsNil)
455 c.Assert(s.execCalls[writableCmd], check.Equals, 1)
456 }
457
458 func (s *partitionTestSuite) TestMakeWritableWaitsForIdlePartition(c *check.C) {
459- err := MakeWritable(c, path)
460+ err := MakeWritable(c, testPath)
461
462 c.Assert(err, check.IsNil)
463 c.Assert(s.waitCalls[waitCmd], check.Equals, 1)
464@@ -101,7 +101,7 @@
465
466 func (s *partitionTestSuite) TestMakeWritableReturnsWaitError(c *check.C) {
467 s.waitError = true
468- err := MakeWritable(c, path)
469+ err := MakeWritable(c, testPath)
470
471 c.Assert(err, check.NotNil)
472 c.Assert(s.waitCalls[waitCmd], check.Equals, 1)
473@@ -109,14 +109,14 @@
474 }
475
476 func (s *partitionTestSuite) TestMakeReadOnlyCallsExecCommand(c *check.C) {
477- err := MakeReadonly(c, path)
478+ err := MakeReadonly(c, testPath)
479
480 c.Assert(err, check.IsNil)
481 c.Assert(s.execCalls[readonlyCmd], check.Equals, 1)
482 }
483
484 func (s *partitionTestSuite) TestMakeReadonlyWaitsForIdlePartition(c *check.C) {
485- err := MakeReadonly(c, path)
486+ err := MakeReadonly(c, testPath)
487
488 c.Assert(err, check.IsNil)
489 c.Assert(s.waitCalls[waitCmd], check.Equals, 1)
490@@ -124,7 +124,7 @@
491
492 func (s *partitionTestSuite) TestMakeReadonlyReturnsWaitError(c *check.C) {
493 s.waitError = true
494- err := MakeReadonly(c, path)
495+ err := MakeReadonly(c, testPath)
496
497 c.Assert(err, check.NotNil)
498 c.Assert(s.waitCalls[waitCmd], check.Equals, 1)
499@@ -147,7 +147,7 @@
500
501 for _, testCase := range testCases {
502 s.execOutput = testCase.execCommandOutput
503- f := checkPathBusyFunc(path)
504+ f := checkPathBusyFunc(testPath)
505
506 actual, err := f()
507 c.Check(err, check.IsNil)
508@@ -161,7 +161,7 @@
509 s.execOutput = "not a lsof common output on not used partitions"
510 s.execError = true
511
512- f := checkPathBusyFunc(path)
513+ f := checkPathBusyFunc(testPath)
514
515 actual, err := f()
516

Subscribers

People subscribed via source and target branches