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