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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 581
Merged at revision: 581
Proposed branch: lp:~elopio/snappy/test_go_install_framework
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 338 lines (+126/-62)
6 files modified
_integration-tests/tests/07_test_install_framework (+0/-33)
_integration-tests/tests/common/common.go (+23/-14)
_integration-tests/tests/failover/failover_test.go (+1/-1)
_integration-tests/tests/latest/installApp_test.go (+13/-13)
_integration-tests/tests/latest/installFramework_test.go (+88/-0)
_integration-tests/tests/update/update_test.go (+1/-1)
To merge this branch: bzr merge lp:~elopio/snappy/test_go_install_framework
Reviewer Review Type Date Requested Status
Federico Gimenez (community) tested Approve
Review via email: mp+264666@code.launchpad.net

Commit message

Translated the install framework test to go.

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

I have TestFrameworkServiceMustBeStartedAfterReboot and TestInstalledFrameworkServiceMustBeStarted failing, perhaps because of the way I'm running the test (create the image with a patched udf, spin it up with kvm, manually ifup'ing ens3 and executing the tests with -ip and -port) lots of moving parts to determine where the errors might come from :)

Anyway, this is the output, [1] for TestFrameworkServiceMustBeStartedAfterReboot and [2] for TestInstalledFrameworkServiceMustBeStarted

Thanks!

[1] http://paste.ubuntu.com/11877938/
[2] http://paste.ubuntu.com/11877944/

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

Thanks for catching that Federico.
I've pushed a version that doesn't use globbing, and reported this bug:
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1474426

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

Back to work in progress because this will now conflict with the branch that splits main.

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

scratch that. This one is ready, I left the comment on the wrong branch.

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

Working fine now.

review: Approve (tested)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file '_integration-tests/tests/07_test_install_framework'
2--- _integration-tests/tests/07_test_install_framework 2015-06-15 15:36:29 +0000
3+++ _integration-tests/tests/07_test_install_framework 1970-01-01 00:00:00 +0000
4@@ -1,33 +0,0 @@
5-test() {
6- if after_reboot; then
7- # ensure the service comes up after a reboot, give it time
8- # to start (i.e. avoid race between framework and ssh)
9- TIMEOUT=60
10- for i in $(seq $TIMEOUT); do
11- services=$(systemctl | grep "${framework}_.*.service")
12- if [ -n "$services" ]; then
13- echo "Service $framework ready"
14- break
15- fi
16- echo "Waiting for $framework to come up ($i)"
17- sleep 1
18- done
19- if [ $i = $TIMEOUT ]; then
20- fail "$framework provided no services"
21- fi
22- return
23- fi
24-
25- # we test that the final line contains the framework command
26- # FIXME: test progress here too
27- T="$framework[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+"
28- test_regexp "$T" sudo $SNAPPY install "$framework_full"
29-
30- # ensure its there
31- services=$(systemctl | grep "${framework}_.*.service")
32- [ -n "$services" ] || fail "$framework provided no services"
33-
34- if can_reboot; then
35- reboot
36- fi
37-}
38
39=== modified file '_integration-tests/tests/common/common.go'
40--- _integration-tests/tests/common/common.go 2015-07-08 09:10:26 +0000
41+++ _integration-tests/tests/common/common.go 2015-07-14 15:55:04 +0000
42@@ -58,15 +58,15 @@
43 // will skip all the following tests. If the suite is being called after the
44 // test bed was rebooted, it will resume the test that requested the reboot.
45 func (s *SnappySuite) SetUpTest(c *check.C) {
46- if needsReboot() {
47+ if NeedsReboot() {
48 contents, err := ioutil.ReadFile(needsRebootFile)
49 c.Assert(err, check.IsNil, check.Commentf("Error reading needs-reboot file %v", err))
50 c.Skip(fmt.Sprintf("****** Skipped %s during reboot caused by %s",
51 c.TestName(), contents))
52 } else {
53- if checkRebootMark("") {
54+ if CheckRebootMark("") {
55 c.Logf("****** Running %s", c.TestName())
56- SetSavedVersion(c, GetCurrentVersion(c))
57+ SetSavedVersion(c, GetCurrentUbuntuCoreVersion(c))
58 } else {
59 if AfterReboot(c) {
60 c.Logf("****** Resuming %s after reboot", c.TestName())
61@@ -84,7 +84,7 @@
62 // the test.
63 // It also runs the cleanup handlers
64 func (s *SnappySuite) TearDownTest(c *check.C) {
65- if !needsReboot() && checkRebootMark("") {
66+ if !NeedsReboot() && CheckRebootMark("") {
67 // Only restore the channel config files if the reboot has been handled.
68 m := make(map[string]string)
69 m[channelCfgBackupFile()] = "/"
70@@ -146,18 +146,24 @@
71 c.Assert(err, check.IsNil, check.Commentf("Error executing command '%v': %v", cmds, err))
72 }
73
74-// GetCurrentVersion returns the version number of the installed and active
75-// ubuntu-core.
76-func GetCurrentVersion(c *check.C) int {
77+// GetCurrentVersion returns the version of the installed and active package.
78+func GetCurrentVersion(c *check.C, packageName string) string {
79 output := ExecCommand(c, "snappy", "list")
80- pattern := "(?mU)^ubuntu-core (.*)$"
81+ pattern := "(?mU)^" + packageName + " +(.*)$"
82 re := regexp.MustCompile(pattern)
83 match := re.FindStringSubmatch(string(output))
84 c.Assert(match, check.NotNil, check.Commentf("Version not found in %s", output))
85
86 // match is like "ubuntu-core 2015-06-18 93 ubuntu"
87 items := strings.Fields(match[0])
88- version, err := strconv.Atoi(items[2])
89+ return items[2]
90+}
91+
92+// GetCurrentUbuntuCoreVersion returns the version number of the installed and
93+// active ubuntu-core.
94+func GetCurrentUbuntuCoreVersion(c *check.C) int {
95+ versionString := GetCurrentVersion(c, "ubuntu-core")
96+ version, err := strconv.Atoi(versionString)
97 c.Assert(err, check.IsNil, check.Commentf("Error converting version to int %v", version))
98 return version
99 }
100@@ -178,7 +184,7 @@
101
102 func fakeAvailableUpdate(c *check.C) {
103 c.Log("Faking an available update...")
104- currentVersion := GetCurrentVersion(c)
105+ currentVersion := GetCurrentUbuntuCoreVersion(c)
106 switchChannelVersion(c, currentVersion, currentVersion-1)
107 SetSavedVersion(c, currentVersion-1)
108 }
109@@ -226,7 +232,8 @@
110 c.Assert(err, check.IsNil, check.Commentf("Error writing needs-reboot file: %v", err))
111 }
112
113-func needsReboot() bool {
114+// NeedsReboot returns True if a reboot has been requested by a test.
115+func NeedsReboot() bool {
116 _, err := os.Stat(needsRebootFile)
117 return err == nil
118 }
119@@ -234,17 +241,19 @@
120 // BeforeReboot returns True if the test is running before the test bed has
121 // been rebooted, or after the test that requested the reboot handled it.
122 func BeforeReboot() bool {
123- return checkRebootMark("")
124+ return CheckRebootMark("")
125 }
126
127 // AfterReboot returns True if the test is running after the test bed has been
128 // rebooted.
129 func AfterReboot(c *check.C) bool {
130 // $ADT_REBOOT_MARK contains the reboot mark, if we have rebooted it'll be the test name
131- return checkRebootMark(c.TestName())
132+ return CheckRebootMark(c.TestName())
133 }
134
135-func checkRebootMark(mark string) bool {
136+// CheckRebootMark returns True if the reboot mark matches the string passed as
137+// argument.
138+func CheckRebootMark(mark string) bool {
139 return os.Getenv("ADT_REBOOT_MARK") == mark
140 }
141
142
143=== modified file '_integration-tests/tests/failover/failover_test.go'
144--- _integration-tests/tests/failover/failover_test.go 2015-07-07 04:22:56 +0000
145+++ _integration-tests/tests/failover/failover_test.go 2015-07-14 15:55:04 +0000
146@@ -48,7 +48,7 @@
147 // type implementing the failer interface and call this function with an instance
148 // of it
149 func commonFailoverTest(c *check.C, f failer) {
150- currentVersion := GetCurrentVersion(c)
151+ currentVersion := GetCurrentUbuntuCoreVersion(c)
152
153 if AfterReboot(c) {
154 RemoveRebootMark(c)
155
156=== renamed file '_integration-tests/tests/latest/install_test.go' => '_integration-tests/tests/latest/installApp_test.go'
157--- _integration-tests/tests/latest/install_test.go 2015-07-08 16:14:10 +0000
158+++ _integration-tests/tests/latest/installApp_test.go 2015-07-14 15:55:04 +0000
159@@ -24,22 +24,22 @@
160
161 . "../common"
162
163- . "gopkg.in/check.v1"
164+ check "gopkg.in/check.v1"
165 )
166
167-var _ = Suite(&installSuite{})
168+var _ = check.Suite(&installAppSuite{})
169
170-type installSuite struct {
171+type installAppSuite struct {
172 SnappySuite
173 }
174
175-func (s *installSuite) TearDownTest(c *C) {
176+func (s *installAppSuite) TearDownTest(c *check.C) {
177 RemoveSnap(c, "hello-world")
178 // run cleanup last
179 s.SnappySuite.TearDownTest(c)
180 }
181
182-func (s *installSuite) TestInstallSnapMustPrintPackageInformation(c *C) {
183+func (s *installAppSuite) TestInstallAppMustPrintPackageInformation(c *check.C) {
184 installOutput := InstallSnap(c, "hello-world")
185
186 expected := "(?ms)" +
187@@ -49,23 +49,23 @@
188 "^hello-world +.* +.* +canonical \n" +
189 ".*"
190
191- c.Assert(installOutput, Matches, expected)
192+ c.Assert(installOutput, check.Matches, expected)
193 }
194
195-func (s *installSuite) TestCallBinaryFromInstalledSnap(c *C) {
196+func (s *installAppSuite) TestCallBinaryFromInstalledSnap(c *check.C) {
197 InstallSnap(c, "hello-world")
198
199 echoOutput := ExecCommand(c, "hello-world.echo")
200
201- c.Assert(echoOutput, Equals, "Hello World!\n")
202+ c.Assert(echoOutput, check.Equals, "Hello World!\n")
203 }
204
205-func (s *installSuite) TestCallBinaryWithPermissionDeniedMustPrintError(c *C) {
206+func (s *installAppSuite) TestCallBinaryWithPermissionDeniedMustPrintError(c *check.C) {
207 InstallSnap(c, "hello-world")
208
209 cmd := exec.Command("hello-world.evil")
210 echoOutput, err := cmd.CombinedOutput()
211- c.Assert(err, NotNil, Commentf("hello-world.evil did not fail"))
212+ c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))
213
214 expected := "" +
215 "Hello Evil World!\n" +
216@@ -75,14 +75,14 @@
217 "/apps/hello-world.canonical/.*/bin/evil: " +
218 "cannot create /var/tmp/myevil.txt: Permission denied\n"
219
220- c.Assert(string(echoOutput), Matches, expected)
221+ c.Assert(string(echoOutput), check.Matches, expected)
222 }
223
224-func (s *installSuite) TestInfoMustPrintInstalledPackageInformation(c *C) {
225+func (s *installAppSuite) TestInfoMustPrintInstalledPackageInformation(c *check.C) {
226 InstallSnap(c, "hello-world")
227
228 infoOutput := ExecCommand(c, "snappy", "info")
229
230 expected := "(?ms).*^apps: hello-world\n"
231- c.Assert(infoOutput, Matches, expected)
232+ c.Assert(infoOutput, check.Matches, expected)
233 }
234
235=== added file '_integration-tests/tests/latest/installFramework_test.go'
236--- _integration-tests/tests/latest/installFramework_test.go 1970-01-01 00:00:00 +0000
237+++ _integration-tests/tests/latest/installFramework_test.go 2015-07-14 15:55:04 +0000
238@@ -0,0 +1,88 @@
239+// -*- Mode: Go; indent-tabs-mode: t -*-
240+
241+/*
242+ * Copyright (C) 2015 Canonical Ltd
243+ *
244+ * This program is free software: you can redistribute it and/or modify
245+ * it under the terms of the GNU General Public License version 3 as
246+ * published by the Free Software Foundation.
247+ *
248+ * This program is distributed in the hope that it will be useful,
249+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
250+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
251+ * GNU General Public License for more details.
252+ *
253+ * You should have received a copy of the GNU General Public License
254+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
255+ *
256+ */
257+
258+package latest
259+
260+import (
261+ "fmt"
262+ "regexp"
263+
264+ . "../common"
265+
266+ check "gopkg.in/check.v1"
267+)
268+
269+var _ = check.Suite(&installFrameworkSuite{})
270+
271+type installFrameworkSuite struct {
272+ SnappySuite
273+}
274+
275+func (s *installFrameworkSuite) TearDownTest(c *check.C) {
276+ if !NeedsReboot() && CheckRebootMark("") {
277+ RemoveSnap(c, "docker")
278+ }
279+ // run cleanup last
280+ s.SnappySuite.TearDownTest(c)
281+}
282+
283+func isDockerServiceRunning(c *check.C) bool {
284+ dockerVersion := GetCurrentVersion(c, "docker")
285+ statusOutput := ExecCommand(
286+ c, "systemctl", "status",
287+ fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion))
288+
289+ expected := "(?ms)" +
290+ ".* docker_docker-daemon_.*\\.service .*\n" +
291+ ".*Loaded: loaded .*\n" +
292+ ".*Active: active \\(running\\) .*\n" +
293+ ".*"
294+
295+ matched, err := regexp.MatchString(expected, statusOutput)
296+ c.Assert(err, check.IsNil)
297+ return matched
298+}
299+
300+func (s *installFrameworkSuite) TestInstallFrameworkMustPrintPackageInformation(c *check.C) {
301+ installOutput := InstallSnap(c, "docker")
302+
303+ expected := "(?ms)" +
304+ "Installing docker\n" +
305+ "Name +Date +Version +Developer \n" +
306+ ".*" +
307+ "^docker +.* +.* +canonical \n" +
308+ ".*"
309+
310+ c.Assert(installOutput, check.Matches, expected)
311+}
312+
313+func (s *installFrameworkSuite) TestInstalledFrameworkServiceMustBeStarted(c *check.C) {
314+ InstallSnap(c, "docker")
315+ c.Assert(isDockerServiceRunning(c), check.Equals, true)
316+}
317+
318+func (s *installFrameworkSuite) TestFrameworkServiceMustBeStartedAfterReboot(c *check.C) {
319+ if BeforeReboot() {
320+ InstallSnap(c, "docker")
321+ Reboot(c)
322+ } else if AfterReboot(c) {
323+ RemoveRebootMark(c)
324+ c.Assert(isDockerServiceRunning(c), check.Equals, true)
325+ }
326+}
327
328=== modified file '_integration-tests/tests/update/update_test.go'
329--- _integration-tests/tests/update/update_test.go 2015-07-08 01:46:57 +0000
330+++ _integration-tests/tests/update/update_test.go 2015-07-14 15:55:04 +0000
331@@ -45,6 +45,6 @@
332 Reboot(c)
333 } else if AfterReboot(c) {
334 RemoveRebootMark(c)
335- c.Assert(GetCurrentVersion(c) > GetSavedVersion(c), Equals, true)
336+ c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c), Equals, true)
337 }
338 }

Subscribers

People subscribed via source and target branches