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
1=== modified file '_integration-tests/README.md'
2--- _integration-tests/README.md 2015-07-21 00:38:12 +0000
3+++ _integration-tests/README.md 2015-07-22 15:12:38 +0000
4@@ -80,19 +80,32 @@
5
6 ## Testing an update
7
8-You can flash an old image, update to the latest and then run the whole suite
9-on the updated system. The release, the channel and the revision flags specify
10-the image that will be flashed, and the target-release and target-channel flags
11-specify the values to be used in the update.
12+With the --update flag you can flash an old image, update to the latest and
13+then run the whole suite on the updated system. The release, the channel and
14+the revision flags specify the image that will be flashed, and the
15+target-release and target-channel flags specify the values to be used in the
16+update if they are different from the flashed values.
17
18 For example, to update from rolling edge -1 to the latest and then run the
19 integration tests:
20
21 go run _integration-tests/main.go --snappy-from-branch \
22- --revision=-1 --target-release=rolling --target-channel=edge
23+ --revision=-1 --update
24
25-To update from 15.04 edge to rolling edge and then run the integration tests:
26+To update from 15.04 alpha to rolling edge and then run the integration tests:
27
28 go run _integration-tests/main.go --snappy-from-branch \
29- --release=15.04 --channel=edge \
30- --target-release=rolling --target-channel=edge
31+ --release=15.04 --channel=alpha \
32+ --update --target-release=rolling --target-channel=edge
33+
34+## Testing a rollback
35+
36+With the --rollback flag you can flash an old image, update to the latest,
37+rollback again to the old image and then run the whole suite on the rolled
38+back system. You should use the release, channel, revision, target-release and
39+target-channel flags as when testing an update.
40+
41+For example, to test a rollback from latest rolling edge to rolling edge -1:
42+
43+ go run _integration-tests/main.go \
44+ --revision=-1 --rollback
45
46=== added directory '_integration-tests/config'
47=== added file '_integration-tests/config/config.go'
48--- _integration-tests/config/config.go 1970-01-01 00:00:00 +0000
49+++ _integration-tests/config/config.go 2015-07-22 15:12:38 +0000
50@@ -0,0 +1,74 @@
51+// -*- Mode: Go; indent-tabs-mode: t -*-
52+
53+/*
54+ * Copyright (C) 2015 Canonical Ltd
55+ *
56+ * This program is free software: you can redistribute it and/or modify
57+ * it under the terms of the GNU General Public License version 3 as
58+ * published by the Free Software Foundation.
59+ *
60+ * This program is distributed in the hope that it will be useful,
61+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
62+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+ * GNU General Public License for more details.
64+ *
65+ * You should have received a copy of the GNU General Public License
66+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
67+ *
68+ */
69+
70+package config
71+
72+import (
73+ "encoding/json"
74+ "fmt"
75+ "io/ioutil"
76+ "log"
77+ "strconv"
78+)
79+
80+// Config contains the values to pass to the test bed from the host.
81+type Config struct {
82+ fileName string
83+ release string
84+ channel string
85+ targetRelease string
86+ targetChannel string
87+ update bool
88+ rollback bool
89+}
90+
91+// NewConfig is the Config constructor
92+func NewConfig(fileName, release, channel, targetRelease, targetChannel string, update, rollback bool) *Config {
93+ return &Config{
94+ fileName: fileName, release: release, channel: channel,
95+ targetRelease: targetRelease, targetChannel: targetChannel,
96+ update: update, rollback: rollback,
97+ }
98+}
99+
100+// Write writes the config to a file that will be copied to the test bed.
101+func (cfg Config) Write() {
102+ fmt.Println("Writing test config...")
103+ testConfig := map[string]string{
104+ "release": cfg.release,
105+ "channel": cfg.channel,
106+ }
107+ if cfg.targetRelease != "" {
108+ testConfig["targetRelease"] = cfg.targetRelease
109+ }
110+ if cfg.targetChannel != "" {
111+ testConfig["targetChannel"] = cfg.targetChannel
112+ }
113+ testConfig["update"] = strconv.FormatBool(cfg.update)
114+ testConfig["rollback"] = strconv.FormatBool(cfg.rollback)
115+ fmt.Println(testConfig)
116+ encoded, err := json.Marshal(testConfig)
117+ if err != nil {
118+ log.Fatalf("Error encoding the test config: %v", err)
119+ }
120+ err = ioutil.WriteFile(cfg.fileName, encoded, 0644)
121+ if err != nil {
122+ log.Fatalf("Error writing the test config: %v", err)
123+ }
124+}
125
126=== modified file '_integration-tests/image/image.go'
127--- _integration-tests/image/image.go 2015-07-15 14:39:42 +0000
128+++ _integration-tests/image/image.go 2015-07-22 15:12:38 +0000
129@@ -27,7 +27,7 @@
130 utils "../utils"
131 )
132
133-// Image type encapsulate image actions
134+// Image type encapsulates image actions
135 type Image struct {
136 release string
137 channel string
138
139=== modified file '_integration-tests/main.go'
140--- _integration-tests/main.go 2015-07-21 00:40:00 +0000
141+++ _integration-tests/main.go 2015-07-22 15:12:38 +0000
142@@ -20,10 +20,8 @@
143 package main
144
145 import (
146- "encoding/json"
147 "flag"
148 "fmt"
149- "io/ioutil"
150 "log"
151 "os"
152 "path/filepath"
153@@ -31,6 +29,7 @@
154 "strings"
155 "text/template"
156
157+ config "./config"
158 image "./image"
159 utils "./utils"
160 )
161@@ -64,26 +63,6 @@
162 buildTests(arch)
163 }
164
165-func writeTestConfig(release, channel, targetRelease, targetChannel string) {
166- fmt.Println("Writing test config...")
167- testConfig := map[string]string{
168- "release": release,
169- "channel": channel,
170- }
171- if targetRelease != "" {
172- testConfig["targetRelease"] = targetRelease
173- }
174- if targetChannel != "" {
175- testConfig["targetChannel"] = targetChannel
176- }
177- fmt.Println(testConfig)
178- encoded, err := json.Marshal(testConfig)
179- if err != nil {
180- log.Fatalf("Error encoding the test config: %v", testConfig)
181- }
182- ioutil.WriteFile(configFileName, encoded, 0644)
183-}
184-
185 func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {
186 // Run the tests on the latest rolling edge image.
187 if imageName, err := img.UdfCreate(); err == nil {
188@@ -216,10 +195,14 @@
189 "Channel of the image to be built, defaults to "+defaultChannel)
190 imgRevision = flag.String("revision", "",
191 "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")
192+ update = flag.Bool("update", false,
193+ "If this flag is used, the image will be updated before running the tests.")
194 targetRelease = flag.String("target-release", "",
195- "If specified, the image will be updated to this release before running the tests.")
196+ "If the update flag is used, the image will be updated to this release before running the tests.")
197 targetChannel = flag.String("target-channel", "",
198- "If specified, the image will be updated to this channel before running the tests.")
199+ "If the update flag is used, the image will be updated to this channel before running the tests.")
200+ rollback = flag.Bool("rollback", false,
201+ "If this flag is used, the image will be updated and then rolled back before running the tests.")
202 )
203
204 flag.Parse()
205@@ -232,7 +215,10 @@
206
207 // TODO: pass the config as arguments to the test binaries.
208 // --elopio - 2015-07-15
209- writeTestConfig(*imgRelease, *imgChannel, *targetRelease, *targetChannel)
210+ cfg := config.NewConfig(
211+ configFileName, *imgRelease, *imgChannel, *targetRelease, *targetChannel,
212+ *update, *rollback)
213+ cfg.Write()
214
215 rootPath := getRootPath()
216
217
218=== modified file '_integration-tests/tests/common/common.go'
219--- _integration-tests/tests/common/common.go 2015-07-21 00:40:00 +0000
220+++ _integration-tests/tests/common/common.go 2015-07-22 15:12:38 +0000
221@@ -57,10 +57,8 @@
222 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
223 if !isInRebootProcess() {
224 Config = readConfig(c)
225- targetRelease, _ := Config["targetRelease"]
226- targetChannel, _ := Config["targetChannel"]
227- if targetRelease != "" || targetChannel != "" {
228- switchSystemImageConf(c, targetRelease, targetChannel, "0")
229+ if Config["update"] == "true" || Config["rollback"] == "true" {
230+ switchSystemImageConf(c, Config["targetRelease"], Config["targetChannel"], "0")
231 // Always use the installed snappy because we are updating from an old
232 // image, so we should not use the snappy from the branch.
233 output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update")
234@@ -70,6 +68,12 @@
235 }
236 } else if CheckRebootMark("setupsuite-update") {
237 RemoveRebootMark(c)
238+ if Config["rollback"] == "true" {
239+ ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core")
240+ RebootWithMark(c, "setupsuite-rollback")
241+ }
242+ } else if CheckRebootMark("setupsuite-rollback") {
243+ RemoveRebootMark(c)
244 }
245 }
246

Subscribers

People subscribed via source and target branches