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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 603
Merged at revision: 596
Proposed branch: lp:~elopio/snappy/real_rollback
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/15.04_to_rolling-3
Diff against target: 245 lines (+115/-38)
5 files modified
_integration-tests/README.md (+21/-8)
_integration-tests/config/config.go (+74/-0)
_integration-tests/image/image.go (+1/-1)
_integration-tests/main.go (+11/-25)
_integration-tests/tests/common/common.go (+8/-4)
To merge this branch: bzr merge lp:~elopio/snappy/real_rollback
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+265083@code.launchpad.net

Commit message

Added support for real rollbacks before running the integration tests.

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

LGTM, two inline comments, thanks!

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

thanks for the review. Working on it.

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

Please check again Federico.

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

Great Leo :) thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '_integration-tests/README.md'
--- _integration-tests/README.md 2015-07-21 00:38:12 +0000
+++ _integration-tests/README.md 2015-07-22 15:12:38 +0000
@@ -80,19 +80,32 @@
8080
81## Testing an update81## Testing an update
8282
83You can flash an old image, update to the latest and then run the whole suite83With the --update flag you can flash an old image, update to the latest and
84on the updated system. The release, the channel and the revision flags specify84then run the whole suite on the updated system. The release, the channel and
85the image that will be flashed, and the target-release and target-channel flags85the revision flags specify the image that will be flashed, and the
86specify the values to be used in the update.86target-release and target-channel flags specify the values to be used in the
87update if they are different from the flashed values.
8788
88For example, to update from rolling edge -1 to the latest and then run the89For example, to update from rolling edge -1 to the latest and then run the
89integration tests:90integration tests:
9091
91 go run _integration-tests/main.go --snappy-from-branch \92 go run _integration-tests/main.go --snappy-from-branch \
92 --revision=-1 --target-release=rolling --target-channel=edge93 --revision=-1 --update
9394
94To update from 15.04 edge to rolling edge and then run the integration tests:95To update from 15.04 alpha to rolling edge and then run the integration tests:
9596
96 go run _integration-tests/main.go --snappy-from-branch \97 go run _integration-tests/main.go --snappy-from-branch \
97 --release=15.04 --channel=edge \98 --release=15.04 --channel=alpha \
98 --target-release=rolling --target-channel=edge99 --update --target-release=rolling --target-channel=edge
100
101## Testing a rollback
102
103With the --rollback flag you can flash an old image, update to the latest,
104rollback again to the old image and then run the whole suite on the rolled
105back system. You should use the release, channel, revision, target-release and
106target-channel flags as when testing an update.
107
108For example, to test a rollback from latest rolling edge to rolling edge -1:
109
110 go run _integration-tests/main.go \
111 --revision=-1 --rollback
99112
=== added directory '_integration-tests/config'
=== added file '_integration-tests/config/config.go'
--- _integration-tests/config/config.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/config/config.go 2015-07-22 15:12:38 +0000
@@ -0,0 +1,74 @@
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 config
21
22import (
23 "encoding/json"
24 "fmt"
25 "io/ioutil"
26 "log"
27 "strconv"
28)
29
30// Config contains the values to pass to the test bed from the host.
31type Config struct {
32 fileName string
33 release string
34 channel string
35 targetRelease string
36 targetChannel string
37 update bool
38 rollback bool
39}
40
41// NewConfig is the Config constructor
42func NewConfig(fileName, release, channel, targetRelease, targetChannel string, update, rollback bool) *Config {
43 return &Config{
44 fileName: fileName, release: release, channel: channel,
45 targetRelease: targetRelease, targetChannel: targetChannel,
46 update: update, rollback: rollback,
47 }
48}
49
50// Write writes the config to a file that will be copied to the test bed.
51func (cfg Config) Write() {
52 fmt.Println("Writing test config...")
53 testConfig := map[string]string{
54 "release": cfg.release,
55 "channel": cfg.channel,
56 }
57 if cfg.targetRelease != "" {
58 testConfig["targetRelease"] = cfg.targetRelease
59 }
60 if cfg.targetChannel != "" {
61 testConfig["targetChannel"] = cfg.targetChannel
62 }
63 testConfig["update"] = strconv.FormatBool(cfg.update)
64 testConfig["rollback"] = strconv.FormatBool(cfg.rollback)
65 fmt.Println(testConfig)
66 encoded, err := json.Marshal(testConfig)
67 if err != nil {
68 log.Fatalf("Error encoding the test config: %v", err)
69 }
70 err = ioutil.WriteFile(cfg.fileName, encoded, 0644)
71 if err != nil {
72 log.Fatalf("Error writing the test config: %v", err)
73 }
74}
075
=== modified file '_integration-tests/image/image.go'
--- _integration-tests/image/image.go 2015-07-15 14:39:42 +0000
+++ _integration-tests/image/image.go 2015-07-22 15:12:38 +0000
@@ -27,7 +27,7 @@
27 utils "../utils"27 utils "../utils"
28)28)
2929
30// Image type encapsulate image actions30// Image type encapsulates image actions
31type Image struct {31type Image struct {
32 release string32 release string
33 channel string33 channel string
3434
=== modified file '_integration-tests/main.go'
--- _integration-tests/main.go 2015-07-21 00:40:00 +0000
+++ _integration-tests/main.go 2015-07-22 15:12:38 +0000
@@ -20,10 +20,8 @@
20package main20package main
2121
22import (22import (
23 "encoding/json"
24 "flag"23 "flag"
25 "fmt"24 "fmt"
26 "io/ioutil"
27 "log"25 "log"
28 "os"26 "os"
29 "path/filepath"27 "path/filepath"
@@ -31,6 +29,7 @@
31 "strings"29 "strings"
32 "text/template"30 "text/template"
3331
32 config "./config"
34 image "./image"33 image "./image"
35 utils "./utils"34 utils "./utils"
36)35)
@@ -64,26 +63,6 @@
64 buildTests(arch)63 buildTests(arch)
65}64}
6665
67func writeTestConfig(release, channel, targetRelease, targetChannel string) {
68 fmt.Println("Writing test config...")
69 testConfig := map[string]string{
70 "release": release,
71 "channel": channel,
72 }
73 if targetRelease != "" {
74 testConfig["targetRelease"] = targetRelease
75 }
76 if targetChannel != "" {
77 testConfig["targetChannel"] = targetChannel
78 }
79 fmt.Println(testConfig)
80 encoded, err := json.Marshal(testConfig)
81 if err != nil {
82 log.Fatalf("Error encoding the test config: %v", testConfig)
83 }
84 ioutil.WriteFile(configFileName, encoded, 0644)
85}
86
87func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {66func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {
88 // Run the tests on the latest rolling edge image.67 // Run the tests on the latest rolling edge image.
89 if imageName, err := img.UdfCreate(); err == nil {68 if imageName, err := img.UdfCreate(); err == nil {
@@ -216,10 +195,14 @@
216 "Channel of the image to be built, defaults to "+defaultChannel)195 "Channel of the image to be built, defaults to "+defaultChannel)
217 imgRevision = flag.String("revision", "",196 imgRevision = flag.String("revision", "",
218 "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")197 "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")
198 update = flag.Bool("update", false,
199 "If this flag is used, the image will be updated before running the tests.")
219 targetRelease = flag.String("target-release", "",200 targetRelease = flag.String("target-release", "",
220 "If specified, the image will be updated to this release before running the tests.")201 "If the update flag is used, the image will be updated to this release before running the tests.")
221 targetChannel = flag.String("target-channel", "",202 targetChannel = flag.String("target-channel", "",
222 "If specified, the image will be updated to this channel before running the tests.")203 "If the update flag is used, the image will be updated to this channel before running the tests.")
204 rollback = flag.Bool("rollback", false,
205 "If this flag is used, the image will be updated and then rolled back before running the tests.")
223 )206 )
224207
225 flag.Parse()208 flag.Parse()
@@ -232,7 +215,10 @@
232215
233 // TODO: pass the config as arguments to the test binaries.216 // TODO: pass the config as arguments to the test binaries.
234 // --elopio - 2015-07-15217 // --elopio - 2015-07-15
235 writeTestConfig(*imgRelease, *imgChannel, *targetRelease, *targetChannel)218 cfg := config.NewConfig(
219 configFileName, *imgRelease, *imgChannel, *targetRelease, *targetChannel,
220 *update, *rollback)
221 cfg.Write()
236222
237 rootPath := getRootPath()223 rootPath := getRootPath()
238224
239225
=== modified file '_integration-tests/tests/common/common.go'
--- _integration-tests/tests/common/common.go 2015-07-21 00:40:00 +0000
+++ _integration-tests/tests/common/common.go 2015-07-22 15:12:38 +0000
@@ -57,10 +57,8 @@
57 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")57 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
58 if !isInRebootProcess() {58 if !isInRebootProcess() {
59 Config = readConfig(c)59 Config = readConfig(c)
60 targetRelease, _ := Config["targetRelease"]60 if Config["update"] == "true" || Config["rollback"] == "true" {
61 targetChannel, _ := Config["targetChannel"]61 switchSystemImageConf(c, Config["targetRelease"], Config["targetChannel"], "0")
62 if targetRelease != "" || targetChannel != "" {
63 switchSystemImageConf(c, targetRelease, targetChannel, "0")
64 // Always use the installed snappy because we are updating from an old62 // Always use the installed snappy because we are updating from an old
65 // image, so we should not use the snappy from the branch.63 // image, so we should not use the snappy from the branch.
66 output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update")64 output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update")
@@ -70,6 +68,12 @@
70 }68 }
71 } else if CheckRebootMark("setupsuite-update") {69 } else if CheckRebootMark("setupsuite-update") {
72 RemoveRebootMark(c)70 RemoveRebootMark(c)
71 if Config["rollback"] == "true" {
72 ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core")
73 RebootWithMark(c, "setupsuite-rollback")
74 }
75 } else if CheckRebootMark("setupsuite-rollback") {
76 RemoveRebootMark(c)
73 }77 }
74}78}
7579

Subscribers

People subscribed via source and target branches