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
=== modified file '_integration-tests/tests/failover_zero_size_file_test.go'
--- _integration-tests/tests/failover_zero_size_file_test.go 2015-07-31 12:06:24 +0000
+++ _integration-tests/tests/failover_zero_size_file_test.go 2015-09-10 15:55:38 +0000
@@ -20,15 +20,15 @@
20package tests20package tests
2121
22import (22import (
23 "bufio"
24 "fmt"23 "fmt"
25 "os"24 "os"
26 "path/filepath"25 "path/filepath"
27 "strings"26 "strings"
2827
29 . "launchpad.net/snappy/_integration-tests/testutils/common"28 . "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/partition"
3030
31 check "gopkg.in/check.v1"31 "gopkg.in/check.v1"
32)32)
3333
34const (34const (
@@ -38,11 +38,6 @@
38 initrdFilename = "initrd"38 initrdFilename = "initrd"
39 systemdFilename = "systemd"39 systemdFilename = "systemd"
40 destFilenamePrefix = "snappy-selftest-"40 destFilenamePrefix = "snappy-selftest-"
41 bootBase = "/boot"
42 ubootDir = bootBase + "/uboot"
43 grubDir = bootBase + "/grub"
44 ubootConfigFile = ubootDir + "/snappy-system.txt"
45 grubConfigFile = grubDir + "/grubenv"
46)41)
4742
48type zeroSizeKernel struct{}43type zeroSizeKernel struct{}
@@ -61,8 +56,10 @@
61 if classicKernelFiles(c) {56 if classicKernelFiles(c) {
62 commonSet(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)57 commonSet(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)
63 } else {58 } else {
64 boot := bootSystem(c)59 boot, err := partition.BootSystem()
65 dir := bootDirectory(boot)60 c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
61 dir := partition.BootDir(boot)
62
66 bootFileNamePattern := newKernelFilenamePattern(c, boot, true)63 bootFileNamePattern := newKernelFilenamePattern(c, boot, true)
67 commonSet(c, dir, bootFileNamePattern, initrdFilename)64 commonSet(c, dir, bootFileNamePattern, initrdFilename)
68 }65 }
@@ -72,8 +69,10 @@
72 if classicKernelFiles(c) {69 if classicKernelFiles(c) {
73 commonUnset(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)70 commonUnset(c, BaseAltPartitionPath, origBootFilenamePattern, initrdFilename)
74 } else {71 } else {
75 boot := bootSystem(c)72 boot, err := partition.BootSystem()
76 dir := bootDirectory(boot)73 c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
74 dir := partition.BootDir(boot)
75
77 bootFileNamePattern := newKernelFilenamePattern(c, boot, false)76 bootFileNamePattern := newKernelFilenamePattern(c, boot, false)
78 commonUnset(c, dir, bootFileNamePattern, initrdFilename)77 commonUnset(c, dir, bootFileNamePattern, initrdFilename)
79 }78 }
@@ -154,68 +153,6 @@
154 return len(matches) == 1153 return len(matches) == 1
155}154}
156155
157func bootSystem(c *check.C) string {
158 matches, err := filepath.Glob(bootBase + "/grub")
159
160 c.Assert(err, check.IsNil, check.Commentf("Error: %v", err))
161
162 if len(matches) == 1 {
163 return "grub"
164 }
165 return "uboot"
166}
167
168func bootDirectory(bootSystem string) string {
169 if bootSystem == "grub" {
170 return grubDir
171 }
172 return ubootDir
173}
174
175func bootConfigFile(bootSystem string) string {
176 if bootSystem == "grub" {
177 return grubConfigFile
178 }
179 return ubootConfigFile
180}
181
182func currentPartition(c *check.C, bootSystem string) (partition string) {
183 bootConfigFile := bootConfigFile(bootSystem)
184 file, err := os.Open(bootConfigFile)
185
186 c.Assert(err, check.IsNil,
187 check.Commentf("Error reading boot config file %s", bootConfigFile))
188
189 defer file.Close()
190
191 reader := bufio.NewReader(file)
192 scanner := bufio.NewScanner(reader)
193
194 scanner.Split(bufio.ScanLines)
195
196 for scanner.Scan() {
197 if strings.HasPrefix(scanner.Text(), "snappy_ab") {
198 fields := strings.Split(scanner.Text(), "=")
199 if len(fields) > 1 {
200 if bootSystem == "grub" {
201 partition = fields[1]
202 } else {
203 partition = otherPart(fields[1])
204 }
205 }
206 return
207 }
208 }
209 return
210}
211
212func otherPart(current string) string {
213 if current == "a" {
214 return "b"
215 }
216 return "a"
217}
218
219// newKernelFilenamePattern returns the filename pattern to modify files156// newKernelFilenamePattern returns the filename pattern to modify files
220// in the partition declared in the boot config file.157// in the partition declared in the boot config file.
221//158//
@@ -226,11 +163,12 @@
226// we want to change the files in the other partition163// we want to change the files in the other partition
227func newKernelFilenamePattern(c *check.C, bootSystem string, afterUpdate bool) string {164func newKernelFilenamePattern(c *check.C, bootSystem string, afterUpdate bool) string {
228 var actualPartition string165 var actualPartition string
229 partition := currentPartition(c, bootSystem)166 part, err := partition.CurrentPartition()
167 c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
230 if afterUpdate {168 if afterUpdate {
231 actualPartition = partition169 actualPartition = part
232 } else {170 } else {
233 actualPartition = otherPart(partition)171 actualPartition = partition.OtherPartition(part)
234 }172 }
235 return filepath.Join(actualPartition, "%s%s*")173 return filepath.Join(actualPartition, "%s%s*")
236}174}
@@ -247,7 +185,9 @@
247func (s *failoverSuite) TestZeroSizeInitrd(c *check.C) {185func (s *failoverSuite) TestZeroSizeInitrd(c *check.C) {
248 // Skip if on uboot due to https://bugs.launchpad.net/snappy/+bug/1480248186 // Skip if on uboot due to https://bugs.launchpad.net/snappy/+bug/1480248
249 // (fgimenez 20150731)187 // (fgimenez 20150731)
250 if bootSystem(c) == "uboot" {188 boot, err := partition.BootSystem()
189 c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
190 if boot == "uboot" {
251 c.Skip("Failover for empty initrd not working in uboot")191 c.Skip("Failover for empty initrd not working in uboot")
252 }192 }
253 commonFailoverTest(c, zeroSizeInitrd{})193 commonFailoverTest(c, zeroSizeInitrd{})
254194
=== modified file '_integration-tests/tests/update_test.go'
--- _integration-tests/tests/update_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/update_test.go 2015-09-10 15:55:38 +0000
@@ -20,9 +20,13 @@
20package tests20package tests
2121
22import (22import (
23 "io/ioutil"
24 "path"
25
23 . "launchpad.net/snappy/_integration-tests/testutils/common"26 . "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/partition"
2428
25 check "gopkg.in/check.v1"29 "gopkg.in/check.v1"
26)30)
2731
28var _ = check.Suite(&updateSuite{})32var _ = check.Suite(&updateSuite{})
@@ -31,6 +35,28 @@
31 SnappySuite35 SnappySuite
32}36}
3337
38func (s *updateSuite) assertBootDirContents(c *check.C) {
39 system, err := partition.BootSystem()
40 c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
41 current, err := partition.CurrentPartition()
42 c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
43 files, err := ioutil.ReadDir(
44 path.Join(partition.BootDir(system), partition.OtherPartition(current)))
45 c.Assert(err, check.IsNil, check.Commentf("Error reading the other partition boot dir: %s", err))
46
47 expectedFileNames := []string{"hardware.yaml", "initrd.img", "vmlinuz"}
48 if system == "uboot" {
49 expectedFileNames = append([]string{"dtbs"}, expectedFileNames...)
50 }
51
52 fileNames := []string{}
53 for _, f := range files {
54 fileNames = append(fileNames, f.Name())
55 }
56 c.Assert(fileNames, check.DeepEquals, expectedFileNames,
57 check.Commentf("Wrong files in the other partition boot dir"))
58}
59
34// Test that the update to the same release and channel must install a newer60// Test that the update to the same release and channel must install a newer
35// version. If there is no update available, the channel version will be61// version. If there is no update available, the channel version will be
36// modified to fake an update. If there is a version available, the image will62// modified to fake an update. If there is a version available, the image will
@@ -42,6 +68,7 @@
42 ".*" +68 ".*" +
43 "^Reboot to use .*ubuntu-core.\n"69 "^Reboot to use .*ubuntu-core.\n"
44 c.Assert(updateOutput, check.Matches, expected)70 c.Assert(updateOutput, check.Matches, expected)
71 s.assertBootDirContents(c)
45 Reboot(c)72 Reboot(c)
46 } else if AfterReboot(c) {73 } else if AfterReboot(c) {
47 RemoveRebootMark(c)74 RemoveRebootMark(c)
4875
=== added directory '_integration-tests/testutils/partition'
=== added file '_integration-tests/testutils/partition/bootloader.go'
--- _integration-tests/testutils/partition/bootloader.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/partition/bootloader.go 2015-09-10 15:55:38 +0000
@@ -0,0 +1,113 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package partition
21
22import (
23 "bufio"
24 "os"
25 "path/filepath"
26 "strings"
27)
28
29const (
30 bootBase = "/boot"
31 ubootDir = bootBase + "/uboot"
32 grubDir = bootBase + "/grub"
33 ubootConfigFile = ubootDir + "/snappy-system.txt"
34 grubConfigFile = grubDir + "/grubenv"
35)
36
37// BootSystem returns the name of the boot system, grub or uboot.
38func BootSystem() (string, error) {
39 matches, err := filepath.Glob(bootBase + "/grub")
40 if err != nil {
41 return "", err
42 }
43 if len(matches) == 1 {
44 return "grub", nil
45 }
46 return "uboot", nil
47}
48
49// BootDir returns the directory used by the boot system.
50func BootDir(bootSystem string) string {
51 if bootSystem == "grub" {
52 return grubDir
53 }
54 return ubootDir
55}
56
57// CurrentPartition returns the current partition, a or b.
58func CurrentPartition() (partition string, err error) {
59 bootConfigFile, err := bootConf()
60 if err != nil {
61 return
62 }
63 file, err := os.Open(bootConfigFile)
64 if err != nil {
65 return
66 }
67
68 defer file.Close()
69
70 reader := bufio.NewReader(file)
71 scanner := bufio.NewScanner(reader)
72
73 scanner.Split(bufio.ScanLines)
74
75 for scanner.Scan() {
76 if strings.HasPrefix(scanner.Text(), "snappy_ab") {
77 fields := strings.Split(scanner.Text(), "=")
78 if len(fields) > 1 {
79 var system string
80 system, err = BootSystem()
81 if err != nil {
82 return
83 }
84 if system == "grub" {
85 partition = fields[1]
86 } else {
87 partition = OtherPartition(fields[1])
88 }
89 }
90 return
91 }
92 }
93 return
94}
95
96func bootConf() (string, error) {
97 bootSystem, err := BootSystem()
98 if err != nil {
99 return "", err
100 }
101 if bootSystem == "grub" {
102 return grubConfigFile, nil
103 }
104 return ubootConfigFile, nil
105}
106
107// OtherPartition returns the backup partition, a or b.
108func OtherPartition(current string) string {
109 if current == "a" {
110 return "b"
111 }
112 return "a"
113}

Subscribers

People subscribed via source and target branches