Merge lp:~elopio/snappy/15.04_to_rolling-3 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: 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
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.

To post a comment you must log in.
lp:~elopio/snappy/15.04_to_rolling-3 updated
597. By Leo Arias

Moved the update tests to the latest package.

598. By Leo Arias

Renamed the latest package to cmd.

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

I'm not yet able to test this because of the ssh bug.

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,

lp:~elopio/snappy/15.04_to_rolling-3 updated
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.

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?

lp:~elopio/snappy/15.04_to_rolling-3 updated
602. By Leo Arias

Merged with trunk.

603. By Leo Arias

Renamed the packages.

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
=== modified file '_integration-tests/README.md'
--- _integration-tests/README.md 2015-07-15 07:37:35 +0000
+++ _integration-tests/README.md 2015-07-21 00:41:17 +0000
@@ -77,3 +77,22 @@
77Run the tests with:77Run the tests with:
7878
79 go run _integration-tests/main.go --ip {beaglebone-ip} --arch arm79 go run _integration-tests/main.go --ip {beaglebone-ip} --arch arm
80
81## Testing an update
82
83You can flash an old image, update to the latest and then run the whole suite
84on the updated system. The release, the channel and the revision flags specify
85the image that will be flashed, and the target-release and target-channel flags
86specify the values to be used in the update.
87
88For example, to update from rolling edge -1 to the latest and then run the
89integration tests:
90
91 go run _integration-tests/main.go --snappy-from-branch \
92 --revision=-1 --target-release=rolling --target-channel=edge
93
94To update from 15.04 edge to rolling edge and then run the integration tests:
95
96 go run _integration-tests/main.go --snappy-from-branch \
97 --release=15.04 --channel=edge \
98 --target-release=rolling --target-channel=edge
8099
=== modified file '_integration-tests/main.go'
--- _integration-tests/main.go 2015-07-17 15:43:11 +0000
+++ _integration-tests/main.go 2015-07-21 00:41:17 +0000
@@ -47,12 +47,10 @@
47)47)
4848
49var (49var (
50 commonSSHOptions = []string{"---", "ssh"}50 commonSSHOptions = []string{"---", "ssh"}
51 configFileName = filepath.Join(dataOutputDir, "testconfig.json")51 configFileName = filepath.Join(dataOutputDir, "testconfig.json")
52 controlFile = filepath.Join(dataOutputDir, "control")52 controlFile = filepath.Join(dataOutputDir, "control")
53 testPackagesLatest = []string{"latest", "failover"}53 testPackages = []string{"cmd", "failover"}
54 testPackageUpdate = []string{"update"}
55 testPackages = append(testPackagesLatest, testPackageUpdate...)
56)54)
5755
58func buildAssets(useSnappyFromBranch bool, arch string) {56func buildAssets(useSnappyFromBranch bool, arch string) {
@@ -66,12 +64,18 @@
66 buildTests(arch)64 buildTests(arch)
67}65}
6866
69func writeTestConfig(release, channel string) {67func writeTestConfig(release, channel, targetRelease, targetChannel string) {
70 fmt.Println("Writing test config...")68 fmt.Println("Writing test config...")
71 testConfig := map[string]string{69 testConfig := map[string]string{
72 "release": release,70 "release": release,
73 "channel": channel,71 "channel": channel,
74 }72 }
73 if targetRelease != "" {
74 testConfig["targetRelease"] = targetRelease
75 }
76 if targetChannel != "" {
77 testConfig["targetChannel"] = targetChannel
78 }
75 fmt.Println(testConfig)79 fmt.Println(testConfig)
76 encoded, err := json.Marshal(testConfig)80 encoded, err := json.Marshal(testConfig)
77 if err != nil {81 if err != nil {
@@ -86,14 +90,6 @@
86 adtRun(rootPath, testFilter, testPackages,90 adtRun(rootPath, testFilter, testPackages,
87 kvmSSHOptions(imageName))91 kvmSSHOptions(imageName))
88 }92 }
89
90 // Update from revision -1.
91 img.SetRevision("-1")
92 if imageName, err := img.UdfCreate(); err == nil {
93 adtRun(
94 rootPath, "updateSuite.TestUpdateToSameReleaseAndChannel",
95 testPackageUpdate, kvmSSHOptions(imageName))
96 }
97}93}
9894
99func setupAndRunRemoteTests(rootPath, testFilter, testbedIP string, testbedPort int) {95func setupAndRunRemoteTests(rootPath, testFilter, testbedIP string, testbedPort int) {
@@ -220,6 +216,10 @@
220 "Channel of the image to be built, defaults to "+defaultChannel)216 "Channel of the image to be built, defaults to "+defaultChannel)
221 imgRevision = flag.String("revision", "",217 imgRevision = flag.String("revision", "",
222 "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")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")
219 targetRelease = flag.String("target-release", "",
220 "If specified, the image will be updated to this release before running the tests.")
221 targetChannel = flag.String("target-channel", "",
222 "If specified, the image will be updated to this channel before running the tests.")
223 )223 )
224224
225 flag.Parse()225 flag.Parse()
@@ -232,7 +232,7 @@
232232
233 // TODO: pass the config as arguments to the test binaries.233 // TODO: pass the config as arguments to the test binaries.
234 // --elopio - 2015-07-15234 // --elopio - 2015-07-15
235 writeTestConfig(*imgRelease, *imgChannel)235 writeTestConfig(*imgRelease, *imgChannel, *targetRelease, *targetChannel)
236236
237 rootPath := getRootPath()237 rootPath := getRootPath()
238238
239239
=== renamed directory '_integration-tests/tests/latest' => '_integration-tests/tests/cmd'
=== modified file '_integration-tests/tests/cmd/apt_test.go'
--- _integration-tests/tests/latest/apt_test.go 2015-07-17 00:02:32 +0000
+++ _integration-tests/tests/cmd/apt_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 . "../common"23 . "../common"
2424
=== modified file '_integration-tests/tests/cmd/base_test.go'
--- _integration-tests/tests/latest/base_test.go 2015-07-01 14:00:36 +0000
+++ _integration-tests/tests/cmd/base_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "testing"23 "testing"
2424
=== modified file '_integration-tests/tests/cmd/build_test.go'
--- _integration-tests/tests/latest/build_test.go 2015-07-08 01:08:26 +0000
+++ _integration-tests/tests/cmd/build_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "fmt"23 "fmt"
2424
=== modified file '_integration-tests/tests/cmd/info_test.go'
--- _integration-tests/tests/latest/info_test.go 2015-07-15 15:18:22 +0000
+++ _integration-tests/tests/cmd/info_test.go 2015-07-21 00:41:17 +0000
@@ -17,12 +17,10 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "encoding/json"
24 "fmt"23 "fmt"
25 "io/ioutil"
2624
27 . "../common"25 . "../common"
2826
@@ -35,24 +33,11 @@
35 SnappySuite33 SnappySuite
36}34}
3735
38func readConfig(c *check.C) map[string]string {
39 b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json")
40 c.Assert(
41 err, check.IsNil, check.Commentf("Failed to read test config: %v", err))
42
43 var decoded map[string]string
44 err = json.Unmarshal(b, &decoded)
45 c.Assert(
46 err, check.IsNil, check.Commentf("Failed to decode test config: %v", err))
47 return decoded
48}
49
50func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) {36func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) {
51 infoOutput := ExecCommand(c, "snappy", "info")37 infoOutput := ExecCommand(c, "snappy", "info")
5238
53 config := readConfig(c)
54 expected := "(?ms)" +39 expected := "(?ms)" +
55 fmt.Sprintf("^release: ubuntu-core/%s/%s\n", config["release"], config["channel"]) +40 fmt.Sprintf("^release: ubuntu-core/%s/%s\n", Config["release"], Config["channel"]) +
56 ".*"41 ".*"
5742
58 c.Assert(infoOutput, check.Matches, expected)43 c.Assert(infoOutput, check.Matches, expected)
5944
=== modified file '_integration-tests/tests/cmd/installApp_test.go'
--- _integration-tests/tests/latest/installApp_test.go 2015-07-15 05:36:24 +0000
+++ _integration-tests/tests/cmd/installApp_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "net/http"23 "net/http"
2424
=== modified file '_integration-tests/tests/cmd/installFramework_test.go'
--- _integration-tests/tests/latest/installFramework_test.go 2015-07-14 15:54:52 +0000
+++ _integration-tests/tests/cmd/installFramework_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "fmt"23 "fmt"
2424
=== modified file '_integration-tests/tests/cmd/list_test.go'
--- _integration-tests/tests/latest/list_test.go 2015-07-17 00:28:36 +0000
+++ _integration-tests/tests/cmd/list_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "fmt"23 "fmt"
2424
=== modified file '_integration-tests/tests/cmd/rollback_test.go'
--- _integration-tests/tests/latest/rollback_test.go 2015-07-17 04:21:07 +0000
+++ _integration-tests/tests/cmd/rollback_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "strconv"23 "strconv"
2424
=== modified file '_integration-tests/tests/cmd/search_test.go'
--- _integration-tests/tests/latest/search_test.go 2015-07-15 05:54:33 +0000
+++ _integration-tests/tests/cmd/search_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 . "../common"23 . "../common"
2424
=== renamed file '_integration-tests/tests/update/update_test.go' => '_integration-tests/tests/cmd/update_test.go'
--- _integration-tests/tests/update/update_test.go 2015-07-14 15:16:59 +0000
+++ _integration-tests/tests/cmd/update_test.go 2015-07-21 00:41:17 +0000
@@ -17,19 +17,14 @@
17 *17 *
18 */18 */
1919
20package update20package cmd
2121
22import (22import (
23 "testing"
24
25 . "../common"23 . "../common"
26 . "gopkg.in/check.v1"24 check "gopkg.in/check.v1"
27)25)
2826
29// Hook up gocheck into the "go test" runner.27var _ = check.Suite(&updateSuite{})
30func Test(t *testing.T) { TestingT(t) }
31
32var _ = Suite(&updateSuite{})
3328
34type updateSuite struct {29type updateSuite struct {
35 SnappySuite30 SnappySuite
@@ -39,12 +34,13 @@
39// version. If there is no update available, the channel version will be34// version. If there is no update available, the channel version will be
40// modified to fake an update. If there is a version available, the image will35// modified to fake an update. If there is a version available, the image will
41// be up-to-date after running this test.36// be up-to-date after running this test.
42func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *C) {37func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *check.C) {
43 if BeforeReboot() {38 if BeforeReboot() {
44 CallUpdate(c)39 CallFakeUpdate(c)
45 Reboot(c)40 Reboot(c)
46 } else if AfterReboot(c) {41 } else if AfterReboot(c) {
47 RemoveRebootMark(c)42 RemoveRebootMark(c)
48 c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c), Equals, true)43 c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c),
44 check.Equals, true)
49 }45 }
50}46}
5147
=== modified file '_integration-tests/tests/cmd/writablePaths_test.go'
--- _integration-tests/tests/latest/writablePaths_test.go 2015-07-17 16:16:03 +0000
+++ _integration-tests/tests/cmd/writablePaths_test.go 2015-07-21 00:41:17 +0000
@@ -17,7 +17,7 @@
17 *17 *
18 */18 */
1919
20package latest20package cmd
2121
22import (22import (
23 "bufio"23 "bufio"
2424
=== modified file '_integration-tests/tests/common/common.go'
--- _integration-tests/tests/common/common.go 2015-07-17 04:21:07 +0000
+++ _integration-tests/tests/common/common.go 2015-07-21 00:41:17 +0000
@@ -20,6 +20,7 @@
20package common20package common
2121
22import (22import (
23 "encoding/json"
23 "fmt"24 "fmt"
24 "io/ioutil"25 "io/ioutil"
25 "os"26 "os"
@@ -39,6 +40,10 @@
39 channelCfgFile = "/etc/system-image/channel.ini"40 channelCfgFile = "/etc/system-image/channel.ini"
40)41)
4142
43// Config is a map of strings that contains the configurations values passed
44// from the host to the testbed.
45var Config map[string]string
46
42// SnappySuite is a structure used as a base test suite for all the snappy47// SnappySuite is a structure used as a base test suite for all the snappy
43// integration tests.48// integration tests.
44type SnappySuite struct {49type SnappySuite struct {
@@ -50,6 +55,22 @@
50func (s *SnappySuite) SetUpSuite(c *check.C) {55func (s *SnappySuite) SetUpSuite(c *check.C) {
51 ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")56 ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
52 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")57 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
58 if !isInRebootProcess() {
59 Config = readConfig(c)
60 targetRelease, _ := Config["targetRelease"]
61 targetChannel, _ := Config["targetChannel"]
62 if targetRelease != "" || targetChannel != "" {
63 switchSystemImageConf(c, targetRelease, targetChannel, "0")
64 // Always use the installed snappy because we are updating from an old
65 // image, so we should not use the snappy from the branch.
66 output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update")
67 if output != "" {
68 RebootWithMark(c, "setupsuite-update")
69 }
70 }
71 } else if CheckRebootMark("setupsuite-update") {
72 RemoveRebootMark(c)
73 }
53}74}
5475
55// SetUpTest handles reboots and stores version information. It will run before76// SetUpTest handles reboots and stores version information. It will run before
@@ -112,6 +133,47 @@
112 s.cleanupHandlers = append(s.cleanupHandlers, f)133 s.cleanupHandlers = append(s.cleanupHandlers, f)
113}134}
114135
136func readConfig(c *check.C) map[string]string {
137 b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json")
138 c.Assert(
139 err, check.IsNil, check.Commentf("Failed to read test config: %v", err))
140
141 var decoded map[string]string
142 err = json.Unmarshal(b, &decoded)
143 c.Assert(
144 err, check.IsNil, check.Commentf("Failed to decode test config: %v", err))
145 return decoded
146}
147
148func switchSystemImageConf(c *check.C, release, channel, version string) {
149 targets := []string{"/", BaseOtherPath}
150 for _, target := range targets {
151 file := filepath.Join(target, channelCfgFile)
152 if _, err := os.Stat(file); err == nil {
153 MakeWritable(c, target)
154 defer MakeReadonly(c, target)
155 replaceSystemImageValues(c, file, release, channel, version)
156 }
157 }
158}
159
160func replaceSystemImageValues(c *check.C, file, release, channel, version string) {
161 c.Log("Switching the system image conf...")
162 replaceRegex := map[string]string{
163 release: `s#channel: ubuntu-core/.*/\(.*\)#channel: ubuntu-core/%s/\1#`,
164 channel: `s#channel: ubuntu-core/\(.*\)/.*#channel: ubuntu-core/\1/%s#`,
165 version: `s/build_number: .*/build_number: %s/`,
166 }
167 for value, regex := range replaceRegex {
168 if value != "" {
169 ExecCommand(c,
170 "sudo", "sed", "-i", fmt.Sprintf(regex, value), file)
171 }
172 }
173 // Leave the new file in the test log.
174 ExecCommand(c, "cat", file)
175}
176
115func channelCfgBackupFile() string {177func channelCfgBackupFile() string {
116 return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini")178 return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini")
117}179}
@@ -168,19 +230,6 @@
168 return version230 return version
169}231}
170232
171// CallUpdate executes an snappy update. If there is no update available, the
172// channel version will be modified to fake an update.
173func CallUpdate(c *check.C) {
174 c.Log("Calling snappy update...")
175 output := ExecCommand(c, "sudo", "snappy", "update")
176 // XXX Instead of trying the update, we should have a command to tell us
177 // if there is an available update. --elopio - 2015-07-01
178 if output == "" {
179 c.Log("There is no update available.")
180 CallFakeUpdate(c)
181 }
182}
183
184// CallFakeUpdate calls snappy update after faking the current version233// CallFakeUpdate calls snappy update after faking the current version
185func CallFakeUpdate(c *check.C) {234func CallFakeUpdate(c *check.C) {
186 c.Log("Preparing fake and calling update.")235 c.Log("Preparing fake and calling update.")
@@ -191,11 +240,11 @@
191func fakeAvailableUpdate(c *check.C) {240func fakeAvailableUpdate(c *check.C) {
192 c.Log("Faking an available update...")241 c.Log("Faking an available update...")
193 currentVersion := GetCurrentUbuntuCoreVersion(c)242 currentVersion := GetCurrentUbuntuCoreVersion(c)
194 switchChannelVersion(c, currentVersion, currentVersion-1)243 switchChannelVersionWithBackup(c, currentVersion-1)
195 SetSavedVersion(c, currentVersion-1)244 SetSavedVersion(c, currentVersion-1)
196}245}
197246
198func switchChannelVersion(c *check.C, oldVersion, newVersion int) {247func switchChannelVersionWithBackup(c *check.C, newVersion int) {
199 m := make(map[string]string)248 m := make(map[string]string)
200 m["/"] = channelCfgBackupFile()249 m["/"] = channelCfgBackupFile()
201 m[BaseOtherPath] = channelCfgOtherBackupFile()250 m[BaseOtherPath] = channelCfgOtherBackupFile()
@@ -206,12 +255,7 @@
206 defer MakeReadonly(c, target)255 defer MakeReadonly(c, target)
207 // Back up the file. It will be restored during the test tear down.256 // Back up the file. It will be restored during the test tear down.
208 ExecCommand(c, "cp", file, backup)257 ExecCommand(c, "cp", file, backup)
209 ExecCommand(c,258 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))
210 "sudo", "sed", "-i",
211 fmt.Sprintf(
212 "s/build_number: %d/build_number: %d/g",
213 oldVersion, newVersion),
214 file)
215 }259 }
216 }260 }
217}261}
@@ -263,6 +307,10 @@
263 return os.Getenv("ADT_REBOOT_MARK") == mark307 return os.Getenv("ADT_REBOOT_MARK") == mark
264}308}
265309
310func isInRebootProcess() bool {
311 return !CheckRebootMark("") || NeedsReboot()
312}
313
266// RemoveRebootMark removes the reboot mark to signal that the reboot has been314// RemoveRebootMark removes the reboot mark to signal that the reboot has been
267// handled.315// handled.
268func RemoveRebootMark(c *check.C) {316func RemoveRebootMark(c *check.C) {
269317
=== removed directory '_integration-tests/tests/update'
=== modified file 'run-checks'
--- run-checks 2015-07-08 15:50:31 +0000
+++ run-checks 2015-07-21 00:41:17 +0000
@@ -76,7 +76,7 @@
7676
77# integration suite in kvm77# integration suite in kvm
78if which adt-run >/dev/null 2>&1; then78if which adt-run >/dev/null 2>&1; then
79 echo "Running integration tests"79 echo "Running integration tests on rolling edge"
80 go run _integration-tests/main.go --snappy-from-branch80 go run _integration-tests/main.go --snappy-from-branch
81fi81fi
8282

Subscribers

People subscribed via source and target branches