Merge lp:~elopio/snappy/15.04_to_rolling-3 into lp:~snappy-dev/snappy/snappy-moved-to-github
- 15.04_to_rolling-3
- Merge into snappy-moved-to-github
Proposed by
Leo Arias
Status: | Merged |
---|---|
Approved by: | Leo Arias |
Approved revision: | 603 |
Merged at revision: | 593 |
Proposed branch: | lp:~elopio/snappy/15.04_to_rolling-3 |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
474 lines (+123/-75) 15 files modified
_integration-tests/README.md (+19/-0) _integration-tests/main.go (+16/-16) _integration-tests/tests/cmd/apt_test.go (+1/-1) _integration-tests/tests/cmd/base_test.go (+1/-1) _integration-tests/tests/cmd/build_test.go (+1/-1) _integration-tests/tests/cmd/info_test.go (+2/-17) _integration-tests/tests/cmd/installApp_test.go (+1/-1) _integration-tests/tests/cmd/installFramework_test.go (+1/-1) _integration-tests/tests/cmd/list_test.go (+1/-1) _integration-tests/tests/cmd/rollback_test.go (+1/-1) _integration-tests/tests/cmd/search_test.go (+1/-1) _integration-tests/tests/cmd/update_test.go (+7/-11) _integration-tests/tests/cmd/writablePaths_test.go (+1/-1) _integration-tests/tests/common/common.go (+69/-21) run-checks (+1/-1) |
To merge this branch: | bzr merge lp:~elopio/snappy/15.04_to_rolling-3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Federico Gimenez (community) | Approve | ||
Review via email: mp+264941@code.launchpad.net |
This proposal supersedes a proposal from 2015-07-15.
Commit message
Added support for real updates before running the integration tests.
Description of the change
To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote : | # |
Revision history for this message
Federico Gimenez (fgimenez) wrote : | # |
Great Leo, just a couple of nits inline and a question about reverting the si config when there's no update available, otherwise it's a +1. This will give us a lot of flexibility.
Thanks,
Revision history for this message
Leo Arias (elopio) wrote : | # |
Thanks for the review Federico. I replied, and pushed. What should we do with this? Land or wait until ssh into the image if fixed?
Revision history for this message
Federico Gimenez (fgimenez) wrote : | # |
Thanks, I'm ok with landing it already, we can fix any pending issues later.
Cheers!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '_integration-tests/README.md' |
2 | --- _integration-tests/README.md 2015-07-15 07:37:35 +0000 |
3 | +++ _integration-tests/README.md 2015-07-21 00:41:17 +0000 |
4 | @@ -77,3 +77,22 @@ |
5 | Run the tests with: |
6 | |
7 | go run _integration-tests/main.go --ip {beaglebone-ip} --arch arm |
8 | + |
9 | +## Testing an update |
10 | + |
11 | +You can flash an old image, update to the latest and then run the whole suite |
12 | +on the updated system. The release, the channel and the revision flags specify |
13 | +the image that will be flashed, and the target-release and target-channel flags |
14 | +specify the values to be used in the update. |
15 | + |
16 | +For example, to update from rolling edge -1 to the latest and then run the |
17 | +integration tests: |
18 | + |
19 | + go run _integration-tests/main.go --snappy-from-branch \ |
20 | + --revision=-1 --target-release=rolling --target-channel=edge |
21 | + |
22 | +To update from 15.04 edge to rolling edge and then run the integration tests: |
23 | + |
24 | + go run _integration-tests/main.go --snappy-from-branch \ |
25 | + --release=15.04 --channel=edge \ |
26 | + --target-release=rolling --target-channel=edge |
27 | |
28 | === modified file '_integration-tests/main.go' |
29 | --- _integration-tests/main.go 2015-07-17 15:43:11 +0000 |
30 | +++ _integration-tests/main.go 2015-07-21 00:41:17 +0000 |
31 | @@ -47,12 +47,10 @@ |
32 | ) |
33 | |
34 | var ( |
35 | - commonSSHOptions = []string{"---", "ssh"} |
36 | - configFileName = filepath.Join(dataOutputDir, "testconfig.json") |
37 | - controlFile = filepath.Join(dataOutputDir, "control") |
38 | - testPackagesLatest = []string{"latest", "failover"} |
39 | - testPackageUpdate = []string{"update"} |
40 | - testPackages = append(testPackagesLatest, testPackageUpdate...) |
41 | + commonSSHOptions = []string{"---", "ssh"} |
42 | + configFileName = filepath.Join(dataOutputDir, "testconfig.json") |
43 | + controlFile = filepath.Join(dataOutputDir, "control") |
44 | + testPackages = []string{"cmd", "failover"} |
45 | ) |
46 | |
47 | func buildAssets(useSnappyFromBranch bool, arch string) { |
48 | @@ -66,12 +64,18 @@ |
49 | buildTests(arch) |
50 | } |
51 | |
52 | -func writeTestConfig(release, channel string) { |
53 | +func writeTestConfig(release, channel, targetRelease, targetChannel string) { |
54 | fmt.Println("Writing test config...") |
55 | testConfig := map[string]string{ |
56 | "release": release, |
57 | "channel": channel, |
58 | } |
59 | + if targetRelease != "" { |
60 | + testConfig["targetRelease"] = targetRelease |
61 | + } |
62 | + if targetChannel != "" { |
63 | + testConfig["targetChannel"] = targetChannel |
64 | + } |
65 | fmt.Println(testConfig) |
66 | encoded, err := json.Marshal(testConfig) |
67 | if err != nil { |
68 | @@ -86,14 +90,6 @@ |
69 | adtRun(rootPath, testFilter, testPackages, |
70 | kvmSSHOptions(imageName)) |
71 | } |
72 | - |
73 | - // Update from revision -1. |
74 | - img.SetRevision("-1") |
75 | - if imageName, err := img.UdfCreate(); err == nil { |
76 | - adtRun( |
77 | - rootPath, "updateSuite.TestUpdateToSameReleaseAndChannel", |
78 | - testPackageUpdate, kvmSSHOptions(imageName)) |
79 | - } |
80 | } |
81 | |
82 | func setupAndRunRemoteTests(rootPath, testFilter, testbedIP string, testbedPort int) { |
83 | @@ -220,6 +216,10 @@ |
84 | "Channel of the image to be built, defaults to "+defaultChannel) |
85 | imgRevision = flag.String("revision", "", |
86 | "Revision of the image to be built (can be relative to the latest available revision in the given release and channel as in -1), defaults to the empty string") |
87 | + targetRelease = flag.String("target-release", "", |
88 | + "If specified, the image will be updated to this release before running the tests.") |
89 | + targetChannel = flag.String("target-channel", "", |
90 | + "If specified, the image will be updated to this channel before running the tests.") |
91 | ) |
92 | |
93 | flag.Parse() |
94 | @@ -232,7 +232,7 @@ |
95 | |
96 | // TODO: pass the config as arguments to the test binaries. |
97 | // --elopio - 2015-07-15 |
98 | - writeTestConfig(*imgRelease, *imgChannel) |
99 | + writeTestConfig(*imgRelease, *imgChannel, *targetRelease, *targetChannel) |
100 | |
101 | rootPath := getRootPath() |
102 | |
103 | |
104 | === renamed directory '_integration-tests/tests/latest' => '_integration-tests/tests/cmd' |
105 | === modified file '_integration-tests/tests/cmd/apt_test.go' |
106 | --- _integration-tests/tests/latest/apt_test.go 2015-07-17 00:02:32 +0000 |
107 | +++ _integration-tests/tests/cmd/apt_test.go 2015-07-21 00:41:17 +0000 |
108 | @@ -17,7 +17,7 @@ |
109 | * |
110 | */ |
111 | |
112 | -package latest |
113 | +package cmd |
114 | |
115 | import ( |
116 | . "../common" |
117 | |
118 | === modified file '_integration-tests/tests/cmd/base_test.go' |
119 | --- _integration-tests/tests/latest/base_test.go 2015-07-01 14:00:36 +0000 |
120 | +++ _integration-tests/tests/cmd/base_test.go 2015-07-21 00:41:17 +0000 |
121 | @@ -17,7 +17,7 @@ |
122 | * |
123 | */ |
124 | |
125 | -package latest |
126 | +package cmd |
127 | |
128 | import ( |
129 | "testing" |
130 | |
131 | === modified file '_integration-tests/tests/cmd/build_test.go' |
132 | --- _integration-tests/tests/latest/build_test.go 2015-07-08 01:08:26 +0000 |
133 | +++ _integration-tests/tests/cmd/build_test.go 2015-07-21 00:41:17 +0000 |
134 | @@ -17,7 +17,7 @@ |
135 | * |
136 | */ |
137 | |
138 | -package latest |
139 | +package cmd |
140 | |
141 | import ( |
142 | "fmt" |
143 | |
144 | === modified file '_integration-tests/tests/cmd/info_test.go' |
145 | --- _integration-tests/tests/latest/info_test.go 2015-07-15 15:18:22 +0000 |
146 | +++ _integration-tests/tests/cmd/info_test.go 2015-07-21 00:41:17 +0000 |
147 | @@ -17,12 +17,10 @@ |
148 | * |
149 | */ |
150 | |
151 | -package latest |
152 | +package cmd |
153 | |
154 | import ( |
155 | - "encoding/json" |
156 | "fmt" |
157 | - "io/ioutil" |
158 | |
159 | . "../common" |
160 | |
161 | @@ -35,24 +33,11 @@ |
162 | SnappySuite |
163 | } |
164 | |
165 | -func readConfig(c *check.C) map[string]string { |
166 | - b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json") |
167 | - c.Assert( |
168 | - err, check.IsNil, check.Commentf("Failed to read test config: %v", err)) |
169 | - |
170 | - var decoded map[string]string |
171 | - err = json.Unmarshal(b, &decoded) |
172 | - c.Assert( |
173 | - err, check.IsNil, check.Commentf("Failed to decode test config: %v", err)) |
174 | - return decoded |
175 | -} |
176 | - |
177 | func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) { |
178 | infoOutput := ExecCommand(c, "snappy", "info") |
179 | |
180 | - config := readConfig(c) |
181 | expected := "(?ms)" + |
182 | - fmt.Sprintf("^release: ubuntu-core/%s/%s\n", config["release"], config["channel"]) + |
183 | + fmt.Sprintf("^release: ubuntu-core/%s/%s\n", Config["release"], Config["channel"]) + |
184 | ".*" |
185 | |
186 | c.Assert(infoOutput, check.Matches, expected) |
187 | |
188 | === modified file '_integration-tests/tests/cmd/installApp_test.go' |
189 | --- _integration-tests/tests/latest/installApp_test.go 2015-07-15 05:36:24 +0000 |
190 | +++ _integration-tests/tests/cmd/installApp_test.go 2015-07-21 00:41:17 +0000 |
191 | @@ -17,7 +17,7 @@ |
192 | * |
193 | */ |
194 | |
195 | -package latest |
196 | +package cmd |
197 | |
198 | import ( |
199 | "net/http" |
200 | |
201 | === modified file '_integration-tests/tests/cmd/installFramework_test.go' |
202 | --- _integration-tests/tests/latest/installFramework_test.go 2015-07-14 15:54:52 +0000 |
203 | +++ _integration-tests/tests/cmd/installFramework_test.go 2015-07-21 00:41:17 +0000 |
204 | @@ -17,7 +17,7 @@ |
205 | * |
206 | */ |
207 | |
208 | -package latest |
209 | +package cmd |
210 | |
211 | import ( |
212 | "fmt" |
213 | |
214 | === modified file '_integration-tests/tests/cmd/list_test.go' |
215 | --- _integration-tests/tests/latest/list_test.go 2015-07-17 00:28:36 +0000 |
216 | +++ _integration-tests/tests/cmd/list_test.go 2015-07-21 00:41:17 +0000 |
217 | @@ -17,7 +17,7 @@ |
218 | * |
219 | */ |
220 | |
221 | -package latest |
222 | +package cmd |
223 | |
224 | import ( |
225 | "fmt" |
226 | |
227 | === modified file '_integration-tests/tests/cmd/rollback_test.go' |
228 | --- _integration-tests/tests/latest/rollback_test.go 2015-07-17 04:21:07 +0000 |
229 | +++ _integration-tests/tests/cmd/rollback_test.go 2015-07-21 00:41:17 +0000 |
230 | @@ -17,7 +17,7 @@ |
231 | * |
232 | */ |
233 | |
234 | -package latest |
235 | +package cmd |
236 | |
237 | import ( |
238 | "strconv" |
239 | |
240 | === modified file '_integration-tests/tests/cmd/search_test.go' |
241 | --- _integration-tests/tests/latest/search_test.go 2015-07-15 05:54:33 +0000 |
242 | +++ _integration-tests/tests/cmd/search_test.go 2015-07-21 00:41:17 +0000 |
243 | @@ -17,7 +17,7 @@ |
244 | * |
245 | */ |
246 | |
247 | -package latest |
248 | +package cmd |
249 | |
250 | import ( |
251 | . "../common" |
252 | |
253 | === renamed file '_integration-tests/tests/update/update_test.go' => '_integration-tests/tests/cmd/update_test.go' |
254 | --- _integration-tests/tests/update/update_test.go 2015-07-14 15:16:59 +0000 |
255 | +++ _integration-tests/tests/cmd/update_test.go 2015-07-21 00:41:17 +0000 |
256 | @@ -17,19 +17,14 @@ |
257 | * |
258 | */ |
259 | |
260 | -package update |
261 | +package cmd |
262 | |
263 | import ( |
264 | - "testing" |
265 | - |
266 | . "../common" |
267 | - . "gopkg.in/check.v1" |
268 | + check "gopkg.in/check.v1" |
269 | ) |
270 | |
271 | -// Hook up gocheck into the "go test" runner. |
272 | -func Test(t *testing.T) { TestingT(t) } |
273 | - |
274 | -var _ = Suite(&updateSuite{}) |
275 | +var _ = check.Suite(&updateSuite{}) |
276 | |
277 | type updateSuite struct { |
278 | SnappySuite |
279 | @@ -39,12 +34,13 @@ |
280 | // version. If there is no update available, the channel version will be |
281 | // modified to fake an update. If there is a version available, the image will |
282 | // be up-to-date after running this test. |
283 | -func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *C) { |
284 | +func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *check.C) { |
285 | if BeforeReboot() { |
286 | - CallUpdate(c) |
287 | + CallFakeUpdate(c) |
288 | Reboot(c) |
289 | } else if AfterReboot(c) { |
290 | RemoveRebootMark(c) |
291 | - c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c), Equals, true) |
292 | + c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c), |
293 | + check.Equals, true) |
294 | } |
295 | } |
296 | |
297 | === modified file '_integration-tests/tests/cmd/writablePaths_test.go' |
298 | --- _integration-tests/tests/latest/writablePaths_test.go 2015-07-17 16:16:03 +0000 |
299 | +++ _integration-tests/tests/cmd/writablePaths_test.go 2015-07-21 00:41:17 +0000 |
300 | @@ -17,7 +17,7 @@ |
301 | * |
302 | */ |
303 | |
304 | -package latest |
305 | +package cmd |
306 | |
307 | import ( |
308 | "bufio" |
309 | |
310 | === modified file '_integration-tests/tests/common/common.go' |
311 | --- _integration-tests/tests/common/common.go 2015-07-17 04:21:07 +0000 |
312 | +++ _integration-tests/tests/common/common.go 2015-07-21 00:41:17 +0000 |
313 | @@ -20,6 +20,7 @@ |
314 | package common |
315 | |
316 | import ( |
317 | + "encoding/json" |
318 | "fmt" |
319 | "io/ioutil" |
320 | "os" |
321 | @@ -39,6 +40,10 @@ |
322 | channelCfgFile = "/etc/system-image/channel.ini" |
323 | ) |
324 | |
325 | +// Config is a map of strings that contains the configurations values passed |
326 | +// from the host to the testbed. |
327 | +var Config map[string]string |
328 | + |
329 | // SnappySuite is a structure used as a base test suite for all the snappy |
330 | // integration tests. |
331 | type SnappySuite struct { |
332 | @@ -50,6 +55,22 @@ |
333 | func (s *SnappySuite) SetUpSuite(c *check.C) { |
334 | ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
335 | ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") |
336 | + if !isInRebootProcess() { |
337 | + Config = readConfig(c) |
338 | + targetRelease, _ := Config["targetRelease"] |
339 | + targetChannel, _ := Config["targetChannel"] |
340 | + if targetRelease != "" || targetChannel != "" { |
341 | + switchSystemImageConf(c, targetRelease, targetChannel, "0") |
342 | + // Always use the installed snappy because we are updating from an old |
343 | + // image, so we should not use the snappy from the branch. |
344 | + output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update") |
345 | + if output != "" { |
346 | + RebootWithMark(c, "setupsuite-update") |
347 | + } |
348 | + } |
349 | + } else if CheckRebootMark("setupsuite-update") { |
350 | + RemoveRebootMark(c) |
351 | + } |
352 | } |
353 | |
354 | // SetUpTest handles reboots and stores version information. It will run before |
355 | @@ -112,6 +133,47 @@ |
356 | s.cleanupHandlers = append(s.cleanupHandlers, f) |
357 | } |
358 | |
359 | +func readConfig(c *check.C) map[string]string { |
360 | + b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json") |
361 | + c.Assert( |
362 | + err, check.IsNil, check.Commentf("Failed to read test config: %v", err)) |
363 | + |
364 | + var decoded map[string]string |
365 | + err = json.Unmarshal(b, &decoded) |
366 | + c.Assert( |
367 | + err, check.IsNil, check.Commentf("Failed to decode test config: %v", err)) |
368 | + return decoded |
369 | +} |
370 | + |
371 | +func switchSystemImageConf(c *check.C, release, channel, version string) { |
372 | + targets := []string{"/", BaseOtherPath} |
373 | + for _, target := range targets { |
374 | + file := filepath.Join(target, channelCfgFile) |
375 | + if _, err := os.Stat(file); err == nil { |
376 | + MakeWritable(c, target) |
377 | + defer MakeReadonly(c, target) |
378 | + replaceSystemImageValues(c, file, release, channel, version) |
379 | + } |
380 | + } |
381 | +} |
382 | + |
383 | +func replaceSystemImageValues(c *check.C, file, release, channel, version string) { |
384 | + c.Log("Switching the system image conf...") |
385 | + replaceRegex := map[string]string{ |
386 | + release: `s#channel: ubuntu-core/.*/\(.*\)#channel: ubuntu-core/%s/\1#`, |
387 | + channel: `s#channel: ubuntu-core/\(.*\)/.*#channel: ubuntu-core/\1/%s#`, |
388 | + version: `s/build_number: .*/build_number: %s/`, |
389 | + } |
390 | + for value, regex := range replaceRegex { |
391 | + if value != "" { |
392 | + ExecCommand(c, |
393 | + "sudo", "sed", "-i", fmt.Sprintf(regex, value), file) |
394 | + } |
395 | + } |
396 | + // Leave the new file in the test log. |
397 | + ExecCommand(c, "cat", file) |
398 | +} |
399 | + |
400 | func channelCfgBackupFile() string { |
401 | return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini") |
402 | } |
403 | @@ -168,19 +230,6 @@ |
404 | return version |
405 | } |
406 | |
407 | -// CallUpdate executes an snappy update. If there is no update available, the |
408 | -// channel version will be modified to fake an update. |
409 | -func CallUpdate(c *check.C) { |
410 | - c.Log("Calling snappy update...") |
411 | - output := ExecCommand(c, "sudo", "snappy", "update") |
412 | - // XXX Instead of trying the update, we should have a command to tell us |
413 | - // if there is an available update. --elopio - 2015-07-01 |
414 | - if output == "" { |
415 | - c.Log("There is no update available.") |
416 | - CallFakeUpdate(c) |
417 | - } |
418 | -} |
419 | - |
420 | // CallFakeUpdate calls snappy update after faking the current version |
421 | func CallFakeUpdate(c *check.C) { |
422 | c.Log("Preparing fake and calling update.") |
423 | @@ -191,11 +240,11 @@ |
424 | func fakeAvailableUpdate(c *check.C) { |
425 | c.Log("Faking an available update...") |
426 | currentVersion := GetCurrentUbuntuCoreVersion(c) |
427 | - switchChannelVersion(c, currentVersion, currentVersion-1) |
428 | + switchChannelVersionWithBackup(c, currentVersion-1) |
429 | SetSavedVersion(c, currentVersion-1) |
430 | } |
431 | |
432 | -func switchChannelVersion(c *check.C, oldVersion, newVersion int) { |
433 | +func switchChannelVersionWithBackup(c *check.C, newVersion int) { |
434 | m := make(map[string]string) |
435 | m["/"] = channelCfgBackupFile() |
436 | m[BaseOtherPath] = channelCfgOtherBackupFile() |
437 | @@ -206,12 +255,7 @@ |
438 | defer MakeReadonly(c, target) |
439 | // Back up the file. It will be restored during the test tear down. |
440 | ExecCommand(c, "cp", file, backup) |
441 | - ExecCommand(c, |
442 | - "sudo", "sed", "-i", |
443 | - fmt.Sprintf( |
444 | - "s/build_number: %d/build_number: %d/g", |
445 | - oldVersion, newVersion), |
446 | - file) |
447 | + replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion)) |
448 | } |
449 | } |
450 | } |
451 | @@ -263,6 +307,10 @@ |
452 | return os.Getenv("ADT_REBOOT_MARK") == mark |
453 | } |
454 | |
455 | +func isInRebootProcess() bool { |
456 | + return !CheckRebootMark("") || NeedsReboot() |
457 | +} |
458 | + |
459 | // RemoveRebootMark removes the reboot mark to signal that the reboot has been |
460 | // handled. |
461 | func RemoveRebootMark(c *check.C) { |
462 | |
463 | === removed directory '_integration-tests/tests/update' |
464 | === modified file 'run-checks' |
465 | --- run-checks 2015-07-08 15:50:31 +0000 |
466 | +++ run-checks 2015-07-21 00:41:17 +0000 |
467 | @@ -76,7 +76,7 @@ |
468 | |
469 | # integration suite in kvm |
470 | if which adt-run >/dev/null 2>&1; then |
471 | - echo "Running integration tests" |
472 | + echo "Running integration tests on rolling edge" |
473 | go run _integration-tests/main.go --snappy-from-branch |
474 | fi |
475 |
I'm not yet able to test this because of the ssh bug.