Merge lp:~elopio/snappy/normalize_test into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 641
Merged at revision: 665
Proposed branch: lp:~elopio/snappy/normalize_test
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~mvo/snappy/snappy-lp1484457-normalize
Diff against target: 330 lines (+158/-78)
3 files modified
_integration-tests/tests/failover_zero_size_file_test.go (+17/-77)
_integration-tests/tests/update_test.go (+28/-1)
_integration-tests/testutils/partition/bootloader.go (+113/-0)
To merge this branch: bzr merge lp:~elopio/snappy/normalize_test
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+270260@code.launchpad.net

Commit message

Added a check for the bootdir contents.

To post a comment you must log in.
Revision history for this message
Federico Gimenez (fgimenez) wrote :

Very nice Leo, I've added unit tests for the partition package here [1]

Thanks!

[1] https://code.launchpad.net/~fgimenez/snappy/partition-tests/+merge/270379

review: Approve
Revision history for this message
Federico Gimenez (fgimenez) wrote :

I'm getting this in the updateSuite.TestUpdateToSameReleaseAndChannel on bbb, works fine on kvm:

/home/fgimenez/workspace/snappy/partition_tests/_integration-tests/tests/update_test.go:67:
    ...open /home/fgimenez/workspace/snappy/partition_tests/_integration-tests/tests/update_test.go: no such file or directory
/home/fgimenez/workspace/snappy/partition_tests/_integration-tests/tests/update_test.go:53:
    ...open /home/fgimenez/workspace/snappy/partition_tests/_integration-tests/tests/update_test.go: no such file or directory
... obtained []string = []string{"dtbs", "hardware.yaml", "initrd.img", "vmlinuz"}
... expected []string = []string{"hardware.yaml", "initrd.img", "vmlinuz"}
... Wrong files in the other partition boot dir

review: Needs Fixing
Revision history for this message
Leo Arias (elopio) wrote :

Thanks for catching that federico.

ogra and sergio confirmed that the dtbs is required on our uboot devices, so I added that condition.
I know you said you didn't like the if, but the other alternatives are checking that there doesn't exist a file with a name like vmlinuz.* or initrd.img.*, and I didn't like how that code looked.

Let me know what you think, and if you are against the if I'll get the other check.

Revision history for this message
Federico Gimenez (fgimenez) wrote :

No problem with the ifs! Thanks :)

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~elopio/snappy/normalize_test into lp:snappy failed. Below is the output from the failed tests.

Checking docs
Checking formatting
Formatting wrong in following files
_integration-tests/tests/update_test.go

# we always run in a fresh dir in tarmac
export GOPATH=$(mktemp -d)
trap 'rm -rf "$GOPATH"' EXIT

# this is a hack, but not sure tarmac is golang friendly
mkdir -p $GOPATH/src/launchpad.net/snappy
cp -a . $GOPATH/src/launchpad.net/snappy/
cd $GOPATH/src/launchpad.net/snappy

./run-checks

if which goctest >/dev/null; then
    goctest="goctest"
else
    goctest="go test"
fi

echo Checking docs
./mdlint.py docs/*.md

echo Checking formatting
fmt=$(gofmt -l .)

if [ -n "$fmt" ]; then
    echo "Formatting wrong in following files"
    echo "$fmt"
    exit 1
fi

lp:~elopio/snappy/normalize_test updated
641. By Leo Arias

Fixed the format.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/tests/failover_zero_size_file_test.go'
2--- _integration-tests/tests/failover_zero_size_file_test.go 2015-07-31 12:06:24 +0000
3+++ _integration-tests/tests/failover_zero_size_file_test.go 2015-09-10 15:55:38 +0000
4@@ -20,15 +20,15 @@
5 package tests
6
7 import (
8- "bufio"
9 "fmt"
10 "os"
11 "path/filepath"
12 "strings"
13
14 . "launchpad.net/snappy/_integration-tests/testutils/common"
15+ "launchpad.net/snappy/_integration-tests/testutils/partition"
16
17- check "gopkg.in/check.v1"
18+ "gopkg.in/check.v1"
19 )
20
21 const (
22@@ -38,11 +38,6 @@
23 initrdFilename = "initrd"
24 systemdFilename = "systemd"
25 destFilenamePrefix = "snappy-selftest-"
26- bootBase = "/boot"
27- ubootDir = bootBase + "/uboot"
28- grubDir = bootBase + "/grub"
29- ubootConfigFile = ubootDir + "/snappy-system.txt"
30- grubConfigFile = grubDir + "/grubenv"
31 )
32
33 type zeroSizeKernel struct{}
34@@ -61,8 +56,10 @@
35 if classicKernelFiles(c) {
36 commonSet(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)
37 } else {
38- boot := bootSystem(c)
39- dir := bootDirectory(boot)
40+ boot, err := partition.BootSystem()
41+ c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
42+ dir := partition.BootDir(boot)
43+
44 bootFileNamePattern := newKernelFilenamePattern(c, boot, true)
45 commonSet(c, dir, bootFileNamePattern, initrdFilename)
46 }
47@@ -72,8 +69,10 @@
48 if classicKernelFiles(c) {
49 commonUnset(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)
50 } else {
51- boot := bootSystem(c)
52- dir := bootDirectory(boot)
53+ boot, err := partition.BootSystem()
54+ c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
55+ dir := partition.BootDir(boot)
56+
57 bootFileNamePattern := newKernelFilenamePattern(c, boot, false)
58 commonUnset(c, dir, bootFileNamePattern, initrdFilename)
59 }
60@@ -154,68 +153,6 @@
61 return len(matches) == 1
62 }
63
64-func bootSystem(c *check.C) string {
65- matches, err := filepath.Glob(bootBase + "/grub")
66-
67- c.Assert(err, check.IsNil, check.Commentf("Error: %v", err))
68-
69- if len(matches) == 1 {
70- return "grub"
71- }
72- return "uboot"
73-}
74-
75-func bootDirectory(bootSystem string) string {
76- if bootSystem == "grub" {
77- return grubDir
78- }
79- return ubootDir
80-}
81-
82-func bootConfigFile(bootSystem string) string {
83- if bootSystem == "grub" {
84- return grubConfigFile
85- }
86- return ubootConfigFile
87-}
88-
89-func currentPartition(c *check.C, bootSystem string) (partition string) {
90- bootConfigFile := bootConfigFile(bootSystem)
91- file, err := os.Open(bootConfigFile)
92-
93- c.Assert(err, check.IsNil,
94- check.Commentf("Error reading boot config file %s", bootConfigFile))
95-
96- defer file.Close()
97-
98- reader := bufio.NewReader(file)
99- scanner := bufio.NewScanner(reader)
100-
101- scanner.Split(bufio.ScanLines)
102-
103- for scanner.Scan() {
104- if strings.HasPrefix(scanner.Text(), "snappy_ab") {
105- fields := strings.Split(scanner.Text(), "=")
106- if len(fields) > 1 {
107- if bootSystem == "grub" {
108- partition = fields[1]
109- } else {
110- partition = otherPart(fields[1])
111- }
112- }
113- return
114- }
115- }
116- return
117-}
118-
119-func otherPart(current string) string {
120- if current == "a" {
121- return "b"
122- }
123- return "a"
124-}
125-
126 // newKernelFilenamePattern returns the filename pattern to modify files
127 // in the partition declared in the boot config file.
128 //
129@@ -226,11 +163,12 @@
130 // we want to change the files in the other partition
131 func newKernelFilenamePattern(c *check.C, bootSystem string, afterUpdate bool) string {
132 var actualPartition string
133- partition := currentPartition(c, bootSystem)
134+ part, err := partition.CurrentPartition()
135+ c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
136 if afterUpdate {
137- actualPartition = partition
138+ actualPartition = part
139 } else {
140- actualPartition = otherPart(partition)
141+ actualPartition = partition.OtherPartition(part)
142 }
143 return filepath.Join(actualPartition, "%s%s*")
144 }
145@@ -247,7 +185,9 @@
146 func (s *failoverSuite) TestZeroSizeInitrd(c *check.C) {
147 // Skip if on uboot due to https://bugs.launchpad.net/snappy/+bug/1480248
148 // (fgimenez 20150731)
149- if bootSystem(c) == "uboot" {
150+ boot, err := partition.BootSystem()
151+ c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
152+ if boot == "uboot" {
153 c.Skip("Failover for empty initrd not working in uboot")
154 }
155 commonFailoverTest(c, zeroSizeInitrd{})
156
157=== modified file '_integration-tests/tests/update_test.go'
158--- _integration-tests/tests/update_test.go 2015-07-28 04:03:52 +0000
159+++ _integration-tests/tests/update_test.go 2015-09-10 15:55:38 +0000
160@@ -20,9 +20,13 @@
161 package tests
162
163 import (
164+ "io/ioutil"
165+ "path"
166+
167 . "launchpad.net/snappy/_integration-tests/testutils/common"
168+ "launchpad.net/snappy/_integration-tests/testutils/partition"
169
170- check "gopkg.in/check.v1"
171+ "gopkg.in/check.v1"
172 )
173
174 var _ = check.Suite(&updateSuite{})
175@@ -31,6 +35,28 @@
176 SnappySuite
177 }
178
179+func (s *updateSuite) assertBootDirContents(c *check.C) {
180+ system, err := partition.BootSystem()
181+ c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
182+ current, err := partition.CurrentPartition()
183+ c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
184+ files, err := ioutil.ReadDir(
185+ path.Join(partition.BootDir(system), partition.OtherPartition(current)))
186+ c.Assert(err, check.IsNil, check.Commentf("Error reading the other partition boot dir: %s", err))
187+
188+ expectedFileNames := []string{"hardware.yaml", "initrd.img", "vmlinuz"}
189+ if system == "uboot" {
190+ expectedFileNames = append([]string{"dtbs"}, expectedFileNames...)
191+ }
192+
193+ fileNames := []string{}
194+ for _, f := range files {
195+ fileNames = append(fileNames, f.Name())
196+ }
197+ c.Assert(fileNames, check.DeepEquals, expectedFileNames,
198+ check.Commentf("Wrong files in the other partition boot dir"))
199+}
200+
201 // Test that the update to the same release and channel must install a newer
202 // version. If there is no update available, the channel version will be
203 // modified to fake an update. If there is a version available, the image will
204@@ -42,6 +68,7 @@
205 ".*" +
206 "^Reboot to use .*ubuntu-core.\n"
207 c.Assert(updateOutput, check.Matches, expected)
208+ s.assertBootDirContents(c)
209 Reboot(c)
210 } else if AfterReboot(c) {
211 RemoveRebootMark(c)
212
213=== added directory '_integration-tests/testutils/partition'
214=== added file '_integration-tests/testutils/partition/bootloader.go'
215--- _integration-tests/testutils/partition/bootloader.go 1970-01-01 00:00:00 +0000
216+++ _integration-tests/testutils/partition/bootloader.go 2015-09-10 15:55:38 +0000
217@@ -0,0 +1,113 @@
218+// -*- Mode: Go; indent-tabs-mode: t -*-
219+
220+/*
221+ * Copyright (C) 2015 Canonical Ltd
222+ *
223+ * This program is free software: you can redistribute it and/or modify
224+ * it under the terms of the GNU General Public License version 3 as
225+ * published by the Free Software Foundation.
226+ *
227+ * This program is distributed in the hope that it will be useful,
228+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
229+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230+ * GNU General Public License for more details.
231+ *
232+ * You should have received a copy of the GNU General Public License
233+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
234+ *
235+ */
236+
237+package partition
238+
239+import (
240+ "bufio"
241+ "os"
242+ "path/filepath"
243+ "strings"
244+)
245+
246+const (
247+ bootBase = "/boot"
248+ ubootDir = bootBase + "/uboot"
249+ grubDir = bootBase + "/grub"
250+ ubootConfigFile = ubootDir + "/snappy-system.txt"
251+ grubConfigFile = grubDir + "/grubenv"
252+)
253+
254+// BootSystem returns the name of the boot system, grub or uboot.
255+func BootSystem() (string, error) {
256+ matches, err := filepath.Glob(bootBase + "/grub")
257+ if err != nil {
258+ return "", err
259+ }
260+ if len(matches) == 1 {
261+ return "grub", nil
262+ }
263+ return "uboot", nil
264+}
265+
266+// BootDir returns the directory used by the boot system.
267+func BootDir(bootSystem string) string {
268+ if bootSystem == "grub" {
269+ return grubDir
270+ }
271+ return ubootDir
272+}
273+
274+// CurrentPartition returns the current partition, a or b.
275+func CurrentPartition() (partition string, err error) {
276+ bootConfigFile, err := bootConf()
277+ if err != nil {
278+ return
279+ }
280+ file, err := os.Open(bootConfigFile)
281+ if err != nil {
282+ return
283+ }
284+
285+ defer file.Close()
286+
287+ reader := bufio.NewReader(file)
288+ scanner := bufio.NewScanner(reader)
289+
290+ scanner.Split(bufio.ScanLines)
291+
292+ for scanner.Scan() {
293+ if strings.HasPrefix(scanner.Text(), "snappy_ab") {
294+ fields := strings.Split(scanner.Text(), "=")
295+ if len(fields) > 1 {
296+ var system string
297+ system, err = BootSystem()
298+ if err != nil {
299+ return
300+ }
301+ if system == "grub" {
302+ partition = fields[1]
303+ } else {
304+ partition = OtherPartition(fields[1])
305+ }
306+ }
307+ return
308+ }
309+ }
310+ return
311+}
312+
313+func bootConf() (string, error) {
314+ bootSystem, err := BootSystem()
315+ if err != nil {
316+ return "", err
317+ }
318+ if bootSystem == "grub" {
319+ return grubConfigFile, nil
320+ }
321+ return ubootConfigFile, nil
322+}
323+
324+// OtherPartition returns the backup partition, a or b.
325+func OtherPartition(current string) string {
326+ if current == "a" {
327+ return "b"
328+ }
329+ return "a"
330+}

Subscribers

People subscribed via source and target branches