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: | Superseded |
---|---|
Proposed branch: | lp:~elopio/snappy/15.04_to_rolling-3 |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
358 lines (+190/-26) 7 files modified
_integration-tests/main.go (+37/-3) _integration-tests/tests/01_test_info (+0/-4) _integration-tests/tests/10_test_info_has_stuff (+0/-4) _integration-tests/tests/common/common.go (+73/-13) _integration-tests/tests/latest/info_test.go (+74/-0) _integration-tests/tests/update/update_test.go (+1/-1) run-checks (+5/-1) |
To merge this branch: | bzr merge lp:~elopio/snappy/15.04_to_rolling-3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Snappy Developers | Pending | ||
Review via email:
|
This proposal has been superseded by a proposal from 2015-07-15.
Commit message
Description of the change
To post a comment you must log in.
- 588. By Leo Arias
-
Fixed the regexps.
- 589. By Leo Arias
-
Various fixes.
- 590. By Leo Arias
-
Updated comments and logs.
- 591. By Leo Arias
-
Merge
- 592. By Leo Arias
-
Better not replace the version yet.
- 593. By Leo Arias
-
Reverted the last change.
- 594. By Leo Arias
-
Only execute the setup if there is no reboot in progress.
- 595. By Leo Arias
-
Added a comment to Config.
- 596. By Leo Arias
-
Use the installed snappy for the update.
- 597. By Leo Arias
-
Moved the update tests to the latest package.
- 598. By Leo Arias
-
Renamed the latest package to cmd.
- 599. By Leo Arias
-
Added the isInRebootProcess method.
- 600. By Leo Arias
-
Use a map for the regex.
- 601. By Leo Arias
-
Moved the examples from run-checks to the README.
- 602. By Leo Arias
-
Merged with trunk.
- 603. By Leo Arias
-
Renamed the packages.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '_integration-tests/main.go' |
2 | --- _integration-tests/main.go 2015-07-15 14:22:11 +0000 |
3 | +++ _integration-tests/main.go 2015-07-15 23:45:01 +0000 |
4 | @@ -20,8 +20,10 @@ |
5 | package main |
6 | |
7 | import ( |
8 | + "encoding/json" |
9 | "flag" |
10 | "fmt" |
11 | + "io/ioutil" |
12 | "log" |
13 | "os" |
14 | "path/filepath" |
15 | @@ -40,13 +42,14 @@ |
16 | defaultChannel = "edge" |
17 | defaultSSHPort = 22 |
18 | defaultGoArm = "7" |
19 | - tplOutputDir = "_integration-tests/data/output/" |
20 | + dataOutputDir = "_integration-tests/data/output/" |
21 | controlTpl = "_integration-tests/data/tpl/control" |
22 | ) |
23 | |
24 | var ( |
25 | commonSSHOptions = []string{"---", "ssh"} |
26 | - controlFile = filepath.Join(tplOutputDir, "control") |
27 | + configFileName = filepath.Join(dataOutputDir, "testconfig.json") |
28 | + controlFile = filepath.Join(dataOutputDir, "control") |
29 | testPackagesLatest = []string{"latest", "failover"} |
30 | testPackageUpdate = []string{"update"} |
31 | testPackages = append(testPackagesLatest, testPackageUpdate...) |
32 | @@ -63,6 +66,26 @@ |
33 | buildTests(arch) |
34 | } |
35 | |
36 | +func writeTestConfig(release, channel, targetRelease, targetChannel string) { |
37 | + fmt.Println("Writing test config...") |
38 | + testConfig := map[string]string{ |
39 | + "release": release, |
40 | + "channel": channel, |
41 | + } |
42 | + if targetRelease != "" { |
43 | + testConfig["targetRelease"] = targetRelease |
44 | + } |
45 | + if targetChannel != "" { |
46 | + testConfig["targetChannel"] = targetChannel |
47 | + } |
48 | + fmt.Println(testConfig) |
49 | + encoded, err := json.Marshal(testConfig) |
50 | + if err != nil { |
51 | + log.Fatalf("Error encoding the test config: %v", testConfig) |
52 | + } |
53 | + ioutil.WriteFile(configFileName, encoded, 0644) |
54 | +} |
55 | + |
56 | func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) { |
57 | var includeShell bool |
58 | if testFilter == "" { |
59 | @@ -161,7 +184,6 @@ |
60 | log.Fatalf("Error reading adt-run control template %s", controlTpl) |
61 | } |
62 | |
63 | - utils.PrepareTargetDir(tplOutputDir) |
64 | outputFile, err := os.Create(controlFile) |
65 | if err != nil { |
66 | log.Fatalf("Error creating control file %s", controlFile) |
67 | @@ -218,12 +240,24 @@ |
68 | "Channel of the image to be built, defaults to "+defaultChannel) |
69 | imgRevision = flag.String("revision", "", |
70 | "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") |
71 | + targetRelease = flag.String("target-release", "", |
72 | + "If specified, the image will be updated to this release before running the tests.") |
73 | + targetChannel = flag.String("target-channel", "", |
74 | + "If specified, the image will be updated to this channel before running the tests.") |
75 | ) |
76 | |
77 | flag.Parse() |
78 | |
79 | buildAssets(*useSnappyFromBranch, *arch) |
80 | |
81 | + // TODO: generate the files out of the source tree. --elopio - 2015-07-15 |
82 | + utils.PrepareTargetDir(dataOutputDir) |
83 | + defer os.RemoveAll(dataOutputDir) |
84 | + |
85 | + // TODO: pass the config as arguments to the test binaries. |
86 | + // --elopio - 2015-07-15 |
87 | + writeTestConfig(*imgRelease, *imgChannel, *targetRelease, *targetChannel) |
88 | + |
89 | rootPath := getRootPath() |
90 | |
91 | if *testbedIP == "" { |
92 | |
93 | === removed file '_integration-tests/tests/01_test_info' |
94 | --- _integration-tests/tests/01_test_info 2015-06-15 15:36:29 +0000 |
95 | +++ _integration-tests/tests/01_test_info 1970-01-01 00:00:00 +0000 |
96 | @@ -1,4 +0,0 @@ |
97 | -test() { |
98 | - test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info |
99 | - test_regexp "^frameworks: ($framework|)*$" $SNAPPY info |
100 | -} |
101 | |
102 | === removed file '_integration-tests/tests/10_test_info_has_stuff' |
103 | --- _integration-tests/tests/10_test_info_has_stuff 2015-06-16 06:05:14 +0000 |
104 | +++ _integration-tests/tests/10_test_info_has_stuff 1970-01-01 00:00:00 +0000 |
105 | @@ -1,4 +0,0 @@ |
106 | -test() { |
107 | - test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info |
108 | - test_regexp "^frameworks: $framework" $SNAPPY info |
109 | -} |
110 | |
111 | === modified file '_integration-tests/tests/common/common.go' |
112 | --- _integration-tests/tests/common/common.go 2015-07-15 16:12:25 +0000 |
113 | +++ _integration-tests/tests/common/common.go 2015-07-15 23:45:01 +0000 |
114 | @@ -39,6 +39,8 @@ |
115 | channelCfgFile = "/etc/system-image/channel.ini" |
116 | ) |
117 | |
118 | +var Config map[string]string |
119 | + |
120 | // SnappySuite is a structure used as a base test suite for all the snappy |
121 | // integration tests. |
122 | type SnappySuite struct { |
123 | @@ -50,6 +52,19 @@ |
124 | func (s *SnappySuite) SetUpSuite(c *check.C) { |
125 | ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
126 | ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") |
127 | + if CheckRebootMark("") { |
128 | + Config = readConfig(c) |
129 | + targetRelease, _ := Config["targetRelease"] |
130 | + targetChannel, _ := Config["targetChannel"] |
131 | + if targetRelease != "" || targetChannel != "" { |
132 | + switchSystemImageConf(c, targetRelease, targetChannel, 0) |
133 | + if CallUpdate(c) { |
134 | + RebootWithMark(c, c.TestName()+"-setupsuite-update") |
135 | + } |
136 | + } |
137 | + } else if CheckRebootMark(c.TestName() + "-setupsuite-update") { |
138 | + RemoveRebootMark() |
139 | + } |
140 | } |
141 | |
142 | // SetUpTest handles reboots and stores version information. It will run before |
143 | @@ -112,6 +127,59 @@ |
144 | s.cleanupHandlers = append(s.cleanupHandlers, f) |
145 | } |
146 | |
147 | +func (s *SnappySuite) readConfig(c *check.C) map[string]string { |
148 | + b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json") |
149 | + c.Assert( |
150 | + err, check.IsNil, check.Commentf("Failed to read test config: %v", err)) |
151 | + |
152 | + var decoded map[string]string |
153 | + err = json.Unmarshal(b, &decoded) |
154 | + c.Assert( |
155 | + err, check.IsNil, check.Commentf("Failed to decode test config: %v", err)) |
156 | + return decoded |
157 | +} |
158 | + |
159 | +func switchSsytemImageConf(c *check.C, release, channel, version string) { |
160 | + targets := []string{"/", BaseOtherPath} |
161 | + for _, target := range targets { |
162 | + file := filepath.Join(target, channelCfgFile) |
163 | + if _, err := os.Stat(file); err == nil { |
164 | + MakeWritable(c, target) |
165 | + defer MakeReadonly(c, target) |
166 | + replaceSystemImageValues(c, file, release, channel, version) |
167 | + } |
168 | + } |
169 | +} |
170 | + |
171 | +func replaceSystemImageValues(c *check.C, file, release, channel, version string) { |
172 | + c.Log("Switching the system image conf...") |
173 | + regex := []string{} |
174 | + if release != "" { |
175 | + regex = append(regex, |
176 | + fmt.Sprintf( |
177 | + `s#^channel: ubuntu-core/.*/(.*)$#channel: ubuntu-core/%s/\1#`, |
178 | + release)) |
179 | + } |
180 | + if channel != "" { |
181 | + regex = append(regex, |
182 | + fmt.Sprintf( |
183 | + `s#^channel: ubuntu-core/(.*)/.*$#channel: ubuntu-core/\1/%s#`, |
184 | + channel)) |
185 | + } |
186 | + if version != "" { |
187 | + regex = append(regex, |
188 | + fmt.Sprintf( |
189 | + `s/^build_number: .*$/build_number: %s/`, |
190 | + version)) |
191 | + } |
192 | + for i := range regex { |
193 | + ExecCommand(c, |
194 | + "sudo", "sed", "-i", regex[i], file) |
195 | + } |
196 | + // Leave the new file in the test log. |
197 | + ExecCommand(c, "cat", file) |
198 | +} |
199 | + |
200 | func channelCfgBackupFile() string { |
201 | return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini") |
202 | } |
203 | @@ -170,15 +238,12 @@ |
204 | |
205 | // CallUpdate executes an snappy update. If there is no update available, the |
206 | // channel version will be modified to fake an update. |
207 | -func CallUpdate(c *check.C) { |
208 | +func CallUpdate(c *check.C) bool { |
209 | c.Log("Calling snappy update...") |
210 | output := ExecCommand(c, "sudo", "snappy", "update") |
211 | // XXX Instead of trying the update, we should have a command to tell us |
212 | // if there is an available update. --elopio - 2015-07-01 |
213 | - if output == "" { |
214 | - c.Log("There is no update available.") |
215 | - CallFakeUpdate(c) |
216 | - } |
217 | + return output != "" |
218 | } |
219 | |
220 | // CallFakeUpdate calls snappy update after faking the current version |
221 | @@ -191,11 +256,11 @@ |
222 | func fakeAvailableUpdate(c *check.C) { |
223 | c.Log("Faking an available update...") |
224 | currentVersion := GetCurrentUbuntuCoreVersion(c) |
225 | - switchChannelVersion(c, currentVersion, currentVersion-1) |
226 | + switchChanelVersionWithBackup(c, currentVersion, currentVersion-1) |
227 | SetSavedVersion(c, currentVersion-1) |
228 | } |
229 | |
230 | -func switchChannelVersion(c *check.C, oldVersion, newVersion int) { |
231 | +func switchChannelVersionWithBackup(c *check.C, newVersion int) { |
232 | m := make(map[string]string) |
233 | m["/"] = channelCfgBackupFile() |
234 | m[BaseOtherPath] = channelCfgOtherBackupFile() |
235 | @@ -206,12 +271,7 @@ |
236 | defer MakeReadonly(c, target) |
237 | // Back up the file. It will be restored during the test tear down. |
238 | ExecCommand(c, "cp", file, backup) |
239 | - ExecCommand(c, |
240 | - "sudo", "sed", "-i", |
241 | - fmt.Sprintf( |
242 | - "s/build_number: %d/build_number: %d/g", |
243 | - oldVersion, newVersion), |
244 | - file) |
245 | + replaceSystemImageValues(c, file, "", "", newVersion) |
246 | } |
247 | } |
248 | } |
249 | |
250 | === added file '_integration-tests/tests/latest/info_test.go' |
251 | --- _integration-tests/tests/latest/info_test.go 1970-01-01 00:00:00 +0000 |
252 | +++ _integration-tests/tests/latest/info_test.go 2015-07-15 23:45:01 +0000 |
253 | @@ -0,0 +1,74 @@ |
254 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
255 | + |
256 | +/* |
257 | + * Copyright (C) 2015 Canonical Ltd |
258 | + * |
259 | + * This program is free software: you can redistribute it and/or modify |
260 | + * it under the terms of the GNU General Public License version 3 as |
261 | + * published by the Free Software Foundation. |
262 | + * |
263 | + * This program is distributed in the hope that it will be useful, |
264 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
265 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
266 | + * GNU General Public License for more details. |
267 | + * |
268 | + * You should have received a copy of the GNU General Public License |
269 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
270 | + * |
271 | + */ |
272 | + |
273 | +package latest |
274 | + |
275 | +import ( |
276 | + "encoding/json" |
277 | + "fmt" |
278 | + "io/ioutil" |
279 | + |
280 | + . "../common" |
281 | + |
282 | + check "gopkg.in/check.v1" |
283 | +) |
284 | + |
285 | +var _ = check.Suite(&infoSuite{}) |
286 | + |
287 | +type infoSuite struct { |
288 | + SnappySuite |
289 | +} |
290 | + |
291 | +func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) { |
292 | + infoOutput := ExecCommand(c, "snappy", "info") |
293 | + |
294 | + config := readConfig(c) |
295 | + expected := "(?ms)" + |
296 | + fmt.Sprintf("^release: ubuntu-core/%s/%s\n", config["release"], config["channel"]) + |
297 | + ".*" |
298 | + |
299 | + c.Assert(infoOutput, check.Matches, expected) |
300 | +} |
301 | + |
302 | +func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) { |
303 | + InstallSnap(c, "hello-world") |
304 | + s.AddCleanup(func() { |
305 | + RemoveSnap(c, "hello-world") |
306 | + }) |
307 | + infoOutput := ExecCommand(c, "snappy", "info") |
308 | + |
309 | + expected := "(?ms)" + |
310 | + ".*" + |
311 | + "^apps: .*hello-world.*\n" |
312 | + c.Assert(infoOutput, check.Matches, expected) |
313 | +} |
314 | + |
315 | +func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) { |
316 | + InstallSnap(c, "hello-dbus-fwk.canonical") |
317 | + s.AddCleanup(func() { |
318 | + RemoveSnap(c, "hello-dbus-fwk.canonical") |
319 | + }) |
320 | + infoOutput := ExecCommand(c, "snappy", "info") |
321 | + |
322 | + expected := "(?ms)" + |
323 | + ".*" + |
324 | + "^frameworks: .*hello-dbus-fwk.*\n" + |
325 | + ".*" |
326 | + c.Assert(infoOutput, check.Matches, expected) |
327 | +} |
328 | |
329 | === modified file '_integration-tests/tests/update/update_test.go' |
330 | --- _integration-tests/tests/update/update_test.go 2015-07-14 15:16:59 +0000 |
331 | +++ _integration-tests/tests/update/update_test.go 2015-07-15 23:45:01 +0000 |
332 | @@ -41,7 +41,7 @@ |
333 | // be up-to-date after running this test. |
334 | func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *C) { |
335 | if BeforeReboot() { |
336 | - CallUpdate(c) |
337 | + CallFakeUpdate(c) |
338 | Reboot(c) |
339 | } else if AfterReboot(c) { |
340 | RemoveRebootMark(c) |
341 | |
342 | === modified file 'run-checks' |
343 | --- run-checks 2015-07-08 15:50:31 +0000 |
344 | +++ run-checks 2015-07-15 23:45:01 +0000 |
345 | @@ -76,8 +76,12 @@ |
346 | |
347 | # integration suite in kvm |
348 | if which adt-run >/dev/null 2>&1; then |
349 | - echo "Running integration tests" |
350 | + echo "Running integration tests on rolling edge" |
351 | go run _integration-tests/main.go --snappy-from-branch |
352 | + echo "Update from rolling edge -1 and run the integration tests" |
353 | + go run _integration-tests/main.go --snappy-from-branch --revision=-1 --target-release=rolling --target-channel=edge |
354 | + echo "Update from 15.04 edge to rolling edge and run the integration tests" |
355 | + go run _integration-tests/main.go --snappy-from-branch --release=15.04 --channel=edge --target-release=rolling --target-channel=edge |
356 | fi |
357 | |
358 | echo "All good, what could possibly go wrong" |