Merge lp:~mvo/snappy/snappy-merge-integration-tests into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt on 2015-05-20
Status: Merged
Approved by: Leo Arias on 2015-06-09
Approved revision: 468
Merged at revision: 499
Proposed branch: lp:~mvo/snappy/snappy-merge-integration-tests
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 599 lines (+483/-0)
21 files modified
integration-tests/run-in-image/README (+16/-0)
integration-tests/run-in-image/debian/tests/control (+2/-0)
integration-tests/run-in-image/snappy-selftest (+51/-0)
integration-tests/run-in-image/tests/01_test_info (+4/-0)
integration-tests/run-in-image/tests/02_test_versions (+7/-0)
integration-tests/run-in-image/tests/03_test_apt (+4/-0)
integration-tests/run-in-image/tests/04_test_install_hello (+7/-0)
integration-tests/run-in-image/tests/05_test_install_nonexistant (+5/-0)
integration-tests/run-in-image/tests/06_test_search_framework (+4/-0)
integration-tests/run-in-image/tests/07_test_install_framework (+33/-0)
integration-tests/run-in-image/tests/08_test_versions_has_framework (+4/-0)
integration-tests/run-in-image/tests/10_test_info_has_stuff (+5/-0)
integration-tests/run-in-image/tests/11_test_xkcd_listens (+15/-0)
integration-tests/run-in-image/tests/80_test_failover (+48/-0)
integration-tests/run-in-image/tests/90_test_upgrade (+45/-0)
integration-tests/run-in-image/tests/91_test_upgrade_from_stable_image (+51/-0)
integration-tests/run-in-image/tests/common.sh (+59/-0)
integration-tests/run-in-image/tests/framework (+46/-0)
integration-tests/run-in-image/tests/settings (+3/-0)
integration-tests/selftest (+68/-0)
run-checks (+6/-0)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-merge-integration-tests
Reviewer Review Type Date Requested Status
Leo Arias 2015-05-20 Approve on 2015-06-09
Sergio Schvezov Needs Information on 2015-05-21
John Lenton 2015-05-20 Approve on 2015-05-20
Martin Pitt 2015-05-20 Pending
Review via email: mp+259592@code.launchpad.net

Commit Message

Integrate lp:snappy/selftest branch into snappy itself

Description of the Change

This branch integrates the lp:snappy/selftest branch into snappy itself and provides support for running the integration tests as part of the run-checks.sh command.

The way this works is essentially:
- build a deb package from the current tree
- build a fresh ubuntu core test image
- copy/install the ubuntu-snappy deb package into the new image
- run the integration-tests inside this new image via "autopkgtest"

This should allow us to run the full testsuite for each MP via tarmac.

Some open questions:
- can we avoid using sudo for the ubuntu-device-flash generation of the image somehow?
- what does need to change on the CI side so that the new way of running the tests is supported?
- can we add that to our tarmac infrastructure somehow?

To post a comment you must log in.
John Lenton (chipaca) wrote :

drooling at running this in tarmac, here. When can we drop kpartx? (aiui that's where the need for sudo comes from)

review: Approve
Sergio Schvezov (sergiusens) wrote :

hey this is a great initiative!

review: Needs Information
Sergio Schvezov (sergiusens) wrote :

> drooling at running this in tarmac, here. When can we drop kpartx? (aiui
> that's where the need for sudo comes from)

Can you think of anything that doesn't require something similar to kpartx?

I can think of having an option for split image files, but you would still need sudo to install grub, unless more people get on board the idea of using a grub img file (dd'ed ala u-boot) and all the other stuff that goes on.

Sergio Schvezov (sergiusens) wrote :

hmm, we also want to disable the autopilot; one way of doing this is to create an oem package with a config for it to be disabled by default.

Leo Arias (elopio) :
Leo Arias (elopio) wrote :

All good, what could possibly go wrong

\o/

The tests pass. That's an awesome start for me.
I would like to see the tests running from debian/control/tests instead of

16 +++ integration-tests/run-in-image/debian/tests/control

Do you think it is not a good idea to get them running during proposed-migration?

Sergio Schvezov (sergiusens) wrote :

On Thu, May 21, 2015 at 09:30:57PM -0000, Leo Arias wrote:
> All good, what could possibly go wrong
>
> \o/
>
> The tests pass. That's an awesome start for me.
> I would like to see the tests running from debian/control/tests instead of
>
> 16 +++ integration-tests/run-in-image/debian/tests/control

Won't this be tricky since it requires an internet connection?

> Do you think it is not a good idea to get them running during proposed-migration?

That's being worked on by the ci team already.

466. By Michael Vogt on 2015-05-22

sync with lp:snappy/selftest

Leo Arias (elopio) wrote :

> On Thu, May 21, 2015 at 09:30:57PM -0000, Leo Arias wrote:
> > All good, what could possibly go wrong
> >
> > \o/
> >
> > The tests pass. That's an awesome start for me.
> > I would like to see the tests running from debian/control/tests instead of
> >
> > 16 +++ integration-tests/run-in-image/debian/tests/control
>
> Won't this be tricky since it requires an internet connection?

Yes, we would need to deploy a local fake server that replies with the right messages. Then the tests will be able to run with the fake when there's no internet, or with the real server when there is. If CI is going to run the suite against the real server often enough, probably there's no need for the fake.

Federico Gimenez (fgimenez) wrote :

Looks great, some inline comments.

Thanks!

467. By Michael Vogt on 2015-06-09

merged lp:snappy

468. By Michael Vogt on 2015-06-09

do not try to sign the deb

Leo Arias (elopio) wrote :

Successful run: http://paste.ubuntu.com/11676223/

Thanks mvo.

pitti is right, of course. We need to figure out how to generate an image that contains snappy from the code of the branch.

So lets land this and iterate.

review: Approve
Ricardo Salveti (rsalveti) wrote :

From IRC:

<rsalveti> elopio: so, ideally the way to change the image is basically as pitti said, which is creating another clean image with livecd-rootfs
<rsalveti> elopio: the proposed-migration work that the ci team is doing basically that, but using launchpad to build the new image
<rsalveti> we should just have a script or something that can easily do that locally (something like rootstock, ogra_ ^^)
<rsalveti> elopio: we definitely don't want to change the image by installing debs in runtime, as that's not the same path used when we produce the final images
<ogra_> i can look into making rootstock work for core

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'integration-tests'
2=== added directory 'integration-tests/debs'
3=== added directory 'integration-tests/image'
4=== added directory 'integration-tests/run-in-image'
5=== added file 'integration-tests/run-in-image/README'
6--- integration-tests/run-in-image/README 1970-01-01 00:00:00 +0000
7+++ integration-tests/run-in-image/README 2015-06-09 15:41:05 +0000
8@@ -0,0 +1,16 @@
9+# Automatic testing for snappy
10+
11+
12+## qemu based x86 testing
13+
14+Run locally with:
15+$ adt-run $(pwd)/ --- ssh -s snappy -- -i /path/to/snappy.img
16+
17+
18+## BeagleBoneBlack real HW testing
19+
20+With autopkgtest 3.14 it can also drive a BBB directly, this requires
21+that the bbb contains a clean image. Then run:
22+
23+$ adt-run $(pwd)/ --- ssh --reboot -l ubuntu -P ubuntu --reboot -H webdm.local
24+
25
26=== added directory 'integration-tests/run-in-image/debian'
27=== added directory 'integration-tests/run-in-image/debian/tests'
28=== added file 'integration-tests/run-in-image/debian/tests/control'
29--- integration-tests/run-in-image/debian/tests/control 1970-01-01 00:00:00 +0000
30+++ integration-tests/run-in-image/debian/tests/control 2015-06-09 15:41:05 +0000
31@@ -0,0 +1,2 @@
32+Test-Command: ./snappy-selftest --yes-really
33+Depends:
34
35=== added file 'integration-tests/run-in-image/snappy-selftest'
36--- integration-tests/run-in-image/snappy-selftest 1970-01-01 00:00:00 +0000
37+++ integration-tests/run-in-image/snappy-selftest 2015-06-09 15:41:05 +0000
38@@ -0,0 +1,51 @@
39+#!/bin/bash
40+
41+set -e
42+
43+. tests/framework
44+
45+SNAPPY=snappy
46+
47+MYDIR=$(dirname $0)
48+
49+if [ "$1" != "--yes-really" ]; then
50+ echo "The selftest may be destructive, please run with:"
51+ echo " --yes-really"
52+ echo "if you know what you are doing"
53+ exit 1
54+fi
55+
56+. tests/settings
57+
58+. tests/common.sh
59+
60+# prepare the environment
61+if [ -z "$ADT_REBOOT_MARK" ]; then
62+ sudo snappy remove "$framework" 2>&1 || true
63+ sudo snappy remove hello-world 2>&1 || true
64+ sudo snappy remove xkcd-webserver 2>&1 || true
65+fi
66+
67+for test in $MYDIR/tests/*_test_*[!~#]; do
68+ CURRENT_TEST=$(basename $test)
69+
70+ # after a reboot, skip ahead to the test that triggered it
71+ if [ -n "$ADT_REBOOT_MARK" ]; then
72+ if [ "$ADT_REBOOT_MARK" == "$CURRENT_TEST" ]; then
73+ echo "****** Resuming $test after reboot"
74+ else
75+ continue
76+ fi
77+ else
78+ echo "****** Running $test"
79+ fi
80+
81+ . "$test"
82+ if ! (test 2>&1); then
83+ echo "FAILED: $test"
84+ exit 1
85+ fi
86+
87+ # clear reboot marker
88+ unset ADT_REBOOT_MARK
89+done
90
91=== added directory 'integration-tests/run-in-image/tests'
92=== added file 'integration-tests/run-in-image/tests/01_test_info'
93--- integration-tests/run-in-image/tests/01_test_info 1970-01-01 00:00:00 +0000
94+++ integration-tests/run-in-image/tests/01_test_info 2015-06-09 15:41:05 +0000
95@@ -0,0 +1,4 @@
96+test() {
97+ test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
98+ test_regexp "^frameworks: ($framework|)*$" $SNAPPY info
99+}
100
101=== added file 'integration-tests/run-in-image/tests/02_test_versions'
102--- integration-tests/run-in-image/tests/02_test_versions 1970-01-01 00:00:00 +0000
103+++ integration-tests/run-in-image/tests/02_test_versions 2015-06-09 15:41:05 +0000
104@@ -0,0 +1,7 @@
105+test() {
106+ T="ubuntu-core.*201?"
107+ test_regexp "$T" $SNAPPY list
108+
109+ T="Name.*Date.*Version.*Developer"
110+ test_regexp "$T" $SNAPPY list
111+}
112
113=== added file 'integration-tests/run-in-image/tests/03_test_apt'
114--- integration-tests/run-in-image/tests/03_test_apt 1970-01-01 00:00:00 +0000
115+++ integration-tests/run-in-image/tests/03_test_apt 2015-06-09 15:41:05 +0000
116@@ -0,0 +1,4 @@
117+test() {
118+ T="Ubuntu Core does not use apt-get, see 'snappy --help'!"
119+ test_equal "$T" apt-get update
120+}
121\ No newline at end of file
122
123=== added file 'integration-tests/run-in-image/tests/04_test_install_hello'
124--- integration-tests/run-in-image/tests/04_test_install_hello 1970-01-01 00:00:00 +0000
125+++ integration-tests/run-in-image/tests/04_test_install_hello 2015-06-09 15:41:05 +0000
126@@ -0,0 +1,7 @@
127+test() {
128+ T="hello-world[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+(\.[0-9]+)+[[:space:]]+canonical"
129+ test_regexp "$T" sudo $SNAPPY install hello-world
130+
131+ T="Hello World!"
132+ test_equal "$T" hello-world.echo
133+}
134
135=== added file 'integration-tests/run-in-image/tests/05_test_install_nonexistant'
136--- integration-tests/run-in-image/tests/05_test_install_nonexistant 1970-01-01 00:00:00 +0000
137+++ integration-tests/run-in-image/tests/05_test_install_nonexistant 2015-06-09 15:41:05 +0000
138@@ -0,0 +1,5 @@
139+test() {
140+ pkg=fizzler
141+ T="^${pkg} failed to install: snappy package not found"
142+ test_regexp "$T" sudo $SNAPPY install $pkg
143+}
144
145=== added file 'integration-tests/run-in-image/tests/06_test_search_framework'
146--- integration-tests/run-in-image/tests/06_test_search_framework 1970-01-01 00:00:00 +0000
147+++ integration-tests/run-in-image/tests/06_test_search_framework 2015-06-09 15:41:05 +0000
148@@ -0,0 +1,4 @@
149+test() {
150+ T="$framework[[:space:]]+[0-9.]+[[:space:]]+.*"
151+ test_regexp "$T" $SNAPPY search "$framework"
152+}
153
154=== added file 'integration-tests/run-in-image/tests/07_test_install_framework'
155--- integration-tests/run-in-image/tests/07_test_install_framework 1970-01-01 00:00:00 +0000
156+++ integration-tests/run-in-image/tests/07_test_install_framework 2015-06-09 15:41:05 +0000
157@@ -0,0 +1,33 @@
158+test() {
159+ if after_reboot; then
160+ # ensure the service comes up after a reboot, give it time
161+ # to start (i.e. avoid race between framework and ssh)
162+ TIMEOUT=60
163+ for i in $(seq $TIMEOUT); do
164+ services=$(systemctl | grep "${framework}_.*.service")
165+ if [ -n "$services" ]; then
166+ echo "Service $framework ready"
167+ break
168+ fi
169+ echo "Waiting for $framework to come up ($i)"
170+ sleep 1
171+ done
172+ if [ $i = $TIMEOUT ]; then
173+ fail "$framework provided no services"
174+ fi
175+ return
176+ fi
177+
178+ # we test that the final line contains the framework command
179+ # FIXME: test progress here too
180+ T="$framework[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+"
181+ test_regexp "$T" sudo $SNAPPY install "$framework_full"
182+
183+ # ensure its there
184+ services=$(systemctl | grep "${framework}_.*.service")
185+ [ -n "$services" ] || fail "$framework provided no services"
186+
187+ if can_reboot; then
188+ reboot
189+ fi
190+}
191
192=== added file 'integration-tests/run-in-image/tests/08_test_versions_has_framework'
193--- integration-tests/run-in-image/tests/08_test_versions_has_framework 1970-01-01 00:00:00 +0000
194+++ integration-tests/run-in-image/tests/08_test_versions_has_framework 2015-06-09 15:41:05 +0000
195@@ -0,0 +1,4 @@
196+test() {
197+ T="$framework[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+"
198+ test_regexp "$T" $SNAPPY list
199+}
200
201=== added file 'integration-tests/run-in-image/tests/10_test_info_has_stuff'
202--- integration-tests/run-in-image/tests/10_test_info_has_stuff 1970-01-01 00:00:00 +0000
203+++ integration-tests/run-in-image/tests/10_test_info_has_stuff 2015-06-09 15:41:05 +0000
204@@ -0,0 +1,5 @@
205+test() {
206+ test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
207+ test_regexp "^frameworks: $framework" $SNAPPY info
208+ test_regexp "^apps:.*\<hello-world\>" $SNAPPY info
209+}
210
211=== added file 'integration-tests/run-in-image/tests/11_test_xkcd_listens'
212--- integration-tests/run-in-image/tests/11_test_xkcd_listens 1970-01-01 00:00:00 +0000
213+++ integration-tests/run-in-image/tests/11_test_xkcd_listens 2015-06-09 15:41:05 +0000
214@@ -0,0 +1,15 @@
215+test() {
216+ # FIXME: add $SNAPPY search webserver
217+
218+ sudo $SNAPPY install xkcd-webserver.canonical
219+
220+ # FIXME: sucks, needed because "systemctl start" does not
221+ # wait until the service is really started
222+ sleep 1
223+
224+ T="HTTP/1.0 200 OK"
225+ TEMPF=$(tempfile)
226+ printf "GET / HTTP/1.0\n\n"|nc localhost 80 > $TEMPF
227+ test_regexp "$T" cat $TEMPF
228+ rm -f $TEMPF
229+}
230
231=== added file 'integration-tests/run-in-image/tests/80_test_failover'
232--- integration-tests/run-in-image/tests/80_test_failover 1970-01-01 00:00:00 +0000
233+++ integration-tests/run-in-image/tests/80_test_failover 2015-06-09 15:41:05 +0000
234@@ -0,0 +1,48 @@
235+# Test that we rollback on failed upgrades
236+# (needs autopkgtest with a supporting runner).
237+
238+test() {
239+ can_reboot || { echo "SKIP: cannot reboot testbed"; return; }
240+
241+ # debug
242+ version_info
243+ boot_info
244+
245+ if after_reboot; then
246+ # reboot: ensure we booted back into original
247+ orig_current=$(cat "${ADT_ARTIFACTS}/current")
248+ if [ "$orig_current" != "$current" ]; then
249+ fail "did not failover to good version (\"$orig_current\" != \"$current\")"
250+ fi
251+
252+ # FIXME: grep log(other partition) for the crash to ensure it
253+ # really worked
254+ # FIXME2: reboot again as regression test for #1449904
255+
256+ # we booted, cleanup the panic for the next tests to work
257+ sudo mount -o remount,rw /writable/cache/system
258+ sudo rm /writable/cache/system/etc/rc.local
259+ return
260+ fi
261+
262+ # fake new available version by doing a current--
263+ switch_channel "s/build_number: $current/build_number: $((current-1))/" /etc/system-image/channel.ini
264+
265+ # we should have something now :)
266+ version_info
267+
268+ [ $avail -gt $current ] || fail "$avail is not newer than $current"
269+
270+ # save version for post-upgrade test
271+ save_version_info $avail $current
272+
273+ echo "upgrading..."
274+ sudo snappy update
275+
276+ # break the upgrade by inserting a broken rc.local file onto the other
277+ # partition
278+ sudo mount -o remount,rw /writable/cache/system/
279+ printf "#!/bin/sh\nprintf c > /proc/sysrq-trigger" | sudo tee /writable/cache/system/etc/rc.local
280+
281+ reboot
282+}
283
284=== added file 'integration-tests/run-in-image/tests/90_test_upgrade'
285--- integration-tests/run-in-image/tests/90_test_upgrade 1970-01-01 00:00:00 +0000
286+++ integration-tests/run-in-image/tests/90_test_upgrade 2015-06-09 15:41:05 +0000
287@@ -0,0 +1,45 @@
288+# Test that we can upgrade to the latest image version and roll back to the
289+# original version. Test will be skipped the testbed does not offer reboot
290+# (needs autopkgtest with a supporting runner).
291+
292+test() {
293+ can_reboot || { echo "SKIP: cannot reboot testbed"; return; }
294+
295+ # debug
296+ version_info
297+ boot_info
298+
299+ if after_reboot; then
300+ # second reboot: after rollback
301+ if [ -e "${ADT_ARTIFACTS}/rolled_back" ]; then
302+ orig_current=$(cat "${ADT_ARTIFACTS}/current")
303+ [ "$orig_current" = "$current" ] || fail "did not roll back to version $orig_current ($all_versions)"
304+ return
305+ fi
306+
307+ # first reboot: after upgrade
308+ orig_avail=$(cat "${ADT_ARTIFACTS}/avail")
309+ [ "$orig_avail" = "$current" ] || fail "did not upgrade to current version $orig_avail != $current ($all_versions)"
310+
311+ echo "rolling back..."
312+ sudo snappy rollback ubuntu-core
313+ touch "${ADT_ARTIFACTS}/rolled_back"
314+ reboot
315+ return
316+ fi
317+
318+ # fake new available version by doing a current--
319+ switch_channel "s/build_number: $current/build_number: $((current-1))/"
320+
321+ # we should have something now :)
322+ version_info
323+
324+ [ $avail -gt $current ] || fail "$avail is not newer than $current"
325+
326+ # save version for post-upgrade test
327+ save_version_info $avail $current
328+
329+ echo "upgrading..."
330+ sudo snappy update
331+ reboot
332+}
333
334=== added file 'integration-tests/run-in-image/tests/91_test_upgrade_from_stable_image'
335--- integration-tests/run-in-image/tests/91_test_upgrade_from_stable_image 1970-01-01 00:00:00 +0000
336+++ integration-tests/run-in-image/tests/91_test_upgrade_from_stable_image 2015-06-09 15:41:05 +0000
337@@ -0,0 +1,51 @@
338+# Test that we can upgrade from the latest *stable* image version to the
339+# current edge image version and rollback original version.
340+#
341+# Make image for this with:
342+#
343+# $ sudo ubuntu-device-flash core --channel=stable 15.04 -o snappy-stable.img --developer-mode --enable-ssh
344+#
345+# Run with:
346+# adt-run upgrade-test/ --- ssh -s snappy -- -i /path/to/snappy-stable.img
347+
348+test() {
349+ can_reboot || { echo "SKIP: cannot reboot testbed"; return; }
350+
351+ # debug
352+ version_info
353+ boot_info
354+
355+ if after_reboot; then
356+ # second reboot: after rollback
357+ if [ -e "${ADT_ARTIFACTS}/rolled_back-stable" ]; then
358+ orig_current=$(cat "${ADT_ARTIFACTS}/current")
359+ [ "$orig_current" = "$current" ] || fail "did not roll back to version $orig_current ($all_versions)"
360+ return
361+ fi
362+
363+ # first reboot: after upgrade
364+ orig_avail=$(cat "${ADT_ARTIFACTS}/avail")
365+ [ "$orig_avail" = "$current" ] || fail "did not upgrade to current version ($all_versions)"
366+
367+ echo "rolling back..."
368+ sudo snappy rollback ubuntu-core
369+ touch "${ADT_ARTIFACTS}/rolled_back-stable"
370+ reboot
371+ return
372+ fi
373+
374+ # switch channel
375+ switch_channel 's#channel: ubuntu-core/\(.*\)/stable#channel: ubuntu-core/\1/edge#'
376+
377+ # now upgrade to latest edge from stable
378+ version_info
379+
380+ [ $avail -gt $current ] || fail "$avail is not newer than $current"
381+
382+ # save version for post-upgrade test
383+ save_version_info $avail $current
384+
385+ echo "upgrading..."
386+ sudo snappy update
387+ reboot
388+}
389
390=== added file 'integration-tests/run-in-image/tests/common.sh'
391--- integration-tests/run-in-image/tests/common.sh 1970-01-01 00:00:00 +0000
392+++ integration-tests/run-in-image/tests/common.sh 2015-06-09 15:41:05 +0000
393@@ -0,0 +1,59 @@
394+#!/bin/sh
395+#
396+# (not really executable, just to make editors happy)
397+
398+version_info() {
399+ versions=$(snappy list)
400+ current=$(echo "$versions" | awk '/^ubuntu-core/ {print $3}')
401+ echo "current version: $current"
402+ all_version="$(snappy list -v)"
403+
404+ # something went wrong here with the extraction
405+ [ "$current" != "${current#[0-9]}" ] || fail "\"$current\" is not numeric"
406+
407+ versions=$(snappy list -u)
408+ avail=$(echo "$versions" | awk '/^ubuntu-core/ {print $3}')
409+ echo "available version: $avail"
410+ [ "$avail" != "${avail#[0-9]}" ] || fail "\"$avail\" is not numeric"
411+}
412+
413+# debug info really
414+boot_info() {
415+ echo "Boot order"
416+
417+ if [ -e /boot/grub/grub.cfg ]; then
418+ # FIXME: why do we have two places that define what root to boot?
419+
420+ # check grub.cfg config
421+ grep root=LABEL /boot/grub/grub.cfg|head -n1
422+ # show /boot/grub/grubenv
423+ grub-editenv - list
424+ elif [ -e /boot/uboot/snappy-system.txt ]; then
425+ # show uboot config
426+ egrep '(snappy_mode|snappy_ab)' /boot/uboot/snappy-system.txt
427+ else
428+ fail "unknown bootloader"
429+ fi
430+ echo "---"
431+}
432+
433+switch_channel() {
434+ SED_EXPR="$1"
435+ sudo mount -o remount,rw /
436+ sudo sed -i "${SED_EXPR}" /etc/system-image/channel.ini
437+ sudo mount -o remount,ro /
438+
439+ if [ -e /writable/cache/system/etc/system-image/channel.ini ]; then
440+ sudo mount -o remount,rw /writable/cache/system/
441+ sudo sed -i "${SED_EXPR}" /writable/cache/system/etc/system-image/channel.ini
442+ sudo mount -o remount,ro /writable/cache/system/
443+ fi
444+}
445+
446+save_version_info() {
447+ avail=$1
448+ current=$2
449+
450+ echo "$avail" > "${ADT_ARTIFACTS}/avail"
451+ echo "$current" > "${ADT_ARTIFACTS}/current"
452+}
453
454=== added file 'integration-tests/run-in-image/tests/framework'
455--- integration-tests/run-in-image/tests/framework 1970-01-01 00:00:00 +0000
456+++ integration-tests/run-in-image/tests/framework 2015-06-09 15:41:05 +0000
457@@ -0,0 +1,46 @@
458+fail() {
459+ echo "ERROR" $@
460+ exit 1
461+}
462+
463+test_equal() {
464+ local expected="$1"
465+ shift
466+ "$@" 2>&1 | diff -u <(echo "$expected") -
467+}
468+
469+test_regexp() {
470+ local REGEXP="$1"
471+ shift
472+ local ACTUAL=$("$@" 2>&1)
473+ if ! echo "$ACTUAL" | grep -E -q "$REGEXP"; then
474+ echo "Can not find '$REGEXP' in '$ACTUAL'"
475+ fail
476+ fi
477+}
478+
479+# check if reboot is supported; this needs running with autopkgtest on a
480+# supported testbed (QEMU or ssh with a setup script that announces the
481+# "reboot" capability)
482+can_reboot() {
483+ [ -x /tmp/autopkgtest-reboot ]
484+}
485+
486+# reboot the testbed; the same test will be started again, check after_reboot()
487+# to see in which state you are in
488+reboot() {
489+ if [ -z "$CURRENT_TEST" ]; then
490+ echo 'ERROR: $CURRENT_TEST not defined' >&2
491+ exit 1
492+ fi
493+ echo "Rebooting testbed..."
494+ sudo /tmp/autopkgtest-reboot "$CURRENT_TEST"
495+}
496+
497+# true if the current test reboot()ed and is now restarted after boot; false if
498+# it's the first time the test runs (or reboot is not supported)
499+after_reboot() {
500+ [ "$ADT_REBOOT_MARK" = "$CURRENT_TEST" ]
501+}
502+
503+# vim: filetype=sh shiftwidth=4
504
505=== added file 'integration-tests/run-in-image/tests/settings'
506--- integration-tests/run-in-image/tests/settings 1970-01-01 00:00:00 +0000
507+++ integration-tests/run-in-image/tests/settings 2015-06-09 15:41:05 +0000
508@@ -0,0 +1,3 @@
509+# name of framework that will be installed for testing
510+framework=docker
511+framework_full=docker
512
513=== added file 'integration-tests/selftest'
514--- integration-tests/selftest 1970-01-01 00:00:00 +0000
515+++ integration-tests/selftest 2015-06-09 15:41:05 +0000
516@@ -0,0 +1,68 @@
517+#!/bin/sh
518+
519+set -ex
520+
521+HERE="$(dirname $0)"
522+
523+# build the updated deb packages for the image
524+rm -f "$HERE/debs/*"
525+# the "-us -uc " flags tell it not to sign it
526+bzr-buildpackage --result-dir="$HERE/debs" "$HERE/.." -- -us -uc
527+
528+# build a base image
529+IMAGE="$HERE/image/snappy.img"
530+rm -f "$IMAGE/*"
531+# FIXME: hrm, hrm, needs sudo to work on testbed
532+#
533+# FIXME2: use wget here instead and just get the latest image from
534+# cdimage
535+sudo ubuntu-device-flash core -o "$IMAGE" rolling --channel edge --enable-ssh --developer-mode
536+
537+# base cmd
538+QEMU_CMD="qemu-system-$(uname -m) -enable-kvm -m 768 -localtime -nographic -net user -net nic,model=virtio"
539+
540+# fire it up
541+port=11022
542+SERIAL=stdio
543+$QEMU_CMD -drive file="$IMAGE",if=virtio -redir tcp:$port::22 -monitor none -serial $SERIAL &
544+QEMU_PID=$!
545+trap "kill $QEMU_PID" INT QUIT
546+
547+# wait until the image is ready
548+SSH="ssh -oStrictHostKeyChecking=no -o UserKnownHostsFile=\"$HERE/image/known_hosts\" -p $port ubuntu@localhost"
549+SCP="scp -oStrictHostKeyChecking=no -o UserKnownHostsFile=\"$HERE/image/known_hosts\" -P $port"
550+for i in $(seq 100); do
551+ if $SSH true; then
552+ break
553+ fi
554+ sleep 1
555+done
556+if [ $i = 100 ]; then
557+ echo "Failed to setup qemu"
558+ exit 1
559+fi
560+
561+# install debs
562+$SSH rm -rf /tmp/debs
563+$SSH mkdir /tmp/debs
564+$SCP "$HERE"/debs/*.deb ubuntu@localhost:/tmp/debs
565+$SSH sudo mount -o remount,rw /
566+$SSH sudo dpkg -i /tmp/debs/*.deb
567+
568+# shut it down
569+$SSH sudo halt --poweroff || true
570+
571+# wait for qemu pid
572+for i in $(seq 100); do
573+ if [ ! -e /proc/$QEMU_PID/exe ]; then
574+ break
575+ fi
576+ i=$((i+1))
577+ sleep 1
578+done
579+
580+# now run the tests against the image
581+(cd "$HERE";
582+ adt-run run-in-image/ --- ssh -s snappy -- -i image/snappy.img;
583+)
584+
585
586=== modified file 'run-checks'
587--- run-checks 2015-05-19 11:49:41 +0000
588+++ run-checks 2015-06-09 15:41:05 +0000
589@@ -55,4 +55,10 @@
590 exit 1
591 fi
592
593+# integration tests
594+if which adt-run >/dev/null 2>&1; then
595+ echo "Running integration tests"
596+ ./integration-tests/selftest
597+fi
598+
599 echo "All good, what could possibly go wrong"

Subscribers

People subscribed via source and target branches