Merge lp:~mvo/snappy/selftest-upgrade-rollback into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt
Status: Superseded
Proposed branch: lp:~mvo/snappy/selftest-upgrade-rollback
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 470 lines (+360/-0) (has conflicts)
21 files modified
README (+2/-0)
debian/tests/control (+2/-0)
meta/package.yaml (+8/-0)
meta/readme.md (+3/-0)
meta/snappy-selftest.profile (+34/-0)
meta/snappy-selftest.seccomp (+1/-0)
snappy-selftest (+49/-0)
tests/01_test_info (+4/-0)
tests/02_test_versions (+7/-0)
tests/03_test_apt (+4/-0)
tests/04_test_install_hello (+7/-0)
tests/05_test_install_nonexistant (+5/-0)
tests/06_test_search_framework (+4/-0)
tests/07_test_install_framework (+21/-0)
tests/08_test_versions_has_framework (+4/-0)
tests/10_test_info_has_stuff (+5/-0)
tests/11_test_xkcd_listens (+15/-0)
tests/90_test_upgrade (+67/-0)
tests/91_test_upgrade_from_stable_image (+69/-0)
tests/framework (+46/-0)
tests/settings (+3/-0)
Conflict adding file debian.  Moved existing file to debian.moved.
To merge this branch: bzr merge lp:~mvo/snappy/selftest-upgrade-rollback
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+258605@code.launchpad.net

This proposal has been superseded by a proposal from 2015-05-08.

Description of the change

Always do a basic upgrade/rollback test

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Hey, nice to get this all in adt!

I added a few random comments one can lead to false negatives, the other one is just terminology.

Thanks!

43. By Michael Vogt

add upgrade test for stable->edge

Unmerged revisions

43. By Michael Vogt

add upgrade test for stable->edge

42. By Michael Vogt

update to always include upgrade/rollback test

41. By James Hunt

* snappy-selftest: Don't use after_reboot() as it assumes it's being
  called from within the test loop.
* tests/framework: after_reboot(): Revert to previous logic.

40. By James Hunt

* snappy-selftest:
  - Guard all removals and stop snappy writing to stderr
    (which would trigger a test failure).
* tests/01_test_info: Update for edge channel.
* tests/10_test_info_has_stuff: Update for edge channel.
* tests/framework: after_reboot(): Fix test.

39. By James Hunt

* Only remove the framework before the tests first run - it needs to
  still be there after a reboot.

38. By James Hunt

* tests/01_test_info: selftest is not a snap.
* tests/10_test_info_has_stuff: Correct regex for hello-world (cope if
  other apps are also installed).

37. By James Hunt

* Replaced webdm tests with docker by setting the framework in
  tests/settings.

36. By James Hunt

* tests/05_test_install_nonexistant: Snappy output has changed again.

35. By James Hunt

* snappy-selftest: Drop developer names from packages.
* tests/04_test_install_hello:
  - Drop '.canonical' developer name.
  - Correct name of called script.
* tests/11_test_xkcd_listens: Drop '.canonical' developer name.

34. By James Hunt

* debian/tests/control: Pass '--yes-really' to enable DEP-8 tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README'
2--- README 1970-01-01 00:00:00 +0000
3+++ README 2015-05-08 13:39:06 +0000
4@@ -0,0 +1,2 @@
5+Run with:
6+$ adt-run upgrade-test/ --- ssh -s snappy -- -i /path/to/snappy.img
7
8=== added directory 'debian'
9=== renamed directory 'debian' => 'debian.moved'
10=== added directory 'debian/tests'
11=== added file 'debian/tests/control'
12--- debian/tests/control 1970-01-01 00:00:00 +0000
13+++ debian/tests/control 2015-05-08 13:39:06 +0000
14@@ -0,0 +1,2 @@
15+Test-Command: ./snappy-selftest --yes-really
16+Depends:
17
18=== added directory 'meta'
19=== added file 'meta/package.yaml'
20--- meta/package.yaml 1970-01-01 00:00:00 +0000
21+++ meta/package.yaml 2015-05-08 13:39:06 +0000
22@@ -0,0 +1,8 @@
23+name: snappy-selftest
24+version: 0.1
25+vendor: Michael Vogt <mvo@ubuntu.com>
26+binaries:
27+ - name: snappy-selftest
28+ security-policy:
29+ apparmor: meta/snappy-selftest.profile
30+ seccomp: meta/snappy-selftest.seccomp
31
32=== added file 'meta/readme.md'
33--- meta/readme.md 1970-01-01 00:00:00 +0000
34+++ meta/readme.md 2015-05-08 13:39:06 +0000
35@@ -0,0 +1,3 @@
36+snappy self test
37+
38+run selftest via /apps/snappy-selftest/current/snappy-selftest
39
40=== added file 'meta/snappy-selftest.profile'
41--- meta/snappy-selftest.profile 1970-01-01 00:00:00 +0000
42+++ meta/snappy-selftest.profile 2015-05-08 13:39:06 +0000
43@@ -0,0 +1,34 @@
44+#include <tunables/global>
45+
46+# This profile is copied from the unconfined example profile
47+#
48+# Its even more permissive as it allows loading other profiles
49+# too
50+
51+# Define vars with unconfined since autopilot rules may reference them
52+###VAR###
53+
54+# TODO: when v3 userspace lands, use:
55+# ###PROFILEATTACH### (unconfined) {}
56+
57+# v2 compatible wildly permissive profile
58+###PROFILEATTACH### (attach_disconnected) {
59+ capability,
60+ network,
61+ / rwkl,
62+ /** rwlkm,
63+ /** pix,
64+
65+ mount,
66+ remount,
67+ umount,
68+ dbus,
69+ signal,
70+ ptrace,
71+ unix,
72+
73+ # this is added on top of the unconfined profile and allows
74+ # the snappy selftest to run apps like "hello-world" that will
75+ # switch to a new aa-profile
76+ change_profile -> *,
77+}
78
79=== added file 'meta/snappy-selftest.seccomp'
80--- meta/snappy-selftest.seccomp 1970-01-01 00:00:00 +0000
81+++ meta/snappy-selftest.seccomp 2015-05-08 13:39:06 +0000
82@@ -0,0 +1,1 @@
83+@unrestricted
84
85=== added file 'snappy-selftest'
86--- snappy-selftest 1970-01-01 00:00:00 +0000
87+++ snappy-selftest 2015-05-08 13:39:06 +0000
88@@ -0,0 +1,49 @@
89+#!/bin/bash
90+
91+set -e
92+
93+. tests/framework
94+
95+SNAPPY=snappy
96+
97+MYDIR=$(dirname $0)
98+
99+if [ "$1" != "--yes-really" ]; then
100+ echo "The selftest may be destructive, please run with:"
101+ echo " --yes-really"
102+ echo "if you know what you are doing"
103+ exit 1
104+fi
105+
106+. tests/settings
107+
108+# prepare the environment
109+if [ -z "$ADT_REBOOT_MARK" ]; then
110+ sudo snappy remove "$framework" 2>&1 || true
111+ sudo snappy remove hello-world 2>&1 || true
112+ sudo snappy remove xkcd-webserver 2>&1 || true
113+fi
114+
115+for test in $MYDIR/tests/*_test_*; do
116+ CURRENT_TEST=$(basename $test)
117+
118+ # after a reboot, skip ahead to the test that triggered it
119+ if [ -n "$ADT_REBOOT_MARK" ]; then
120+ if [ "$ADT_REBOOT_MARK" == "$CURRENT_TEST" ]; then
121+ echo "Resuming $test after reboot"
122+ else
123+ continue
124+ fi
125+ else
126+ echo "Running $test"
127+ fi
128+
129+ . "$test"
130+ if ! (test 2>&1); then
131+ echo "FAILED: $test"
132+ exit 1
133+ fi
134+
135+ # clear reboot marker
136+ unset ADT_REBOOT_MARK
137+done
138
139=== added directory 'tests'
140=== added file 'tests/01_test_info'
141--- tests/01_test_info 1970-01-01 00:00:00 +0000
142+++ tests/01_test_info 2015-05-08 13:39:06 +0000
143@@ -0,0 +1,4 @@
144+test() {
145+ test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
146+ test_regexp "^frameworks: ($framework|)*$" $SNAPPY info
147+}
148
149=== added file 'tests/02_test_versions'
150--- tests/02_test_versions 1970-01-01 00:00:00 +0000
151+++ tests/02_test_versions 2015-05-08 13:39:06 +0000
152@@ -0,0 +1,7 @@
153+test() {
154+ T="ubuntu-core.*201?"
155+ test_regexp "$T" $SNAPPY list
156+
157+ T="Name.*Date.*Version.*Developer"
158+ test_regexp "$T" $SNAPPY list
159+}
160
161=== added file 'tests/03_test_apt'
162--- tests/03_test_apt 1970-01-01 00:00:00 +0000
163+++ tests/03_test_apt 2015-05-08 13:39:06 +0000
164@@ -0,0 +1,4 @@
165+test() {
166+ T="Ubuntu Core does not use apt-get, see 'snappy --help'!"
167+ test_equal "$T" apt-get update
168+}
169\ No newline at end of file
170
171=== added file 'tests/04_test_install_hello'
172--- tests/04_test_install_hello 1970-01-01 00:00:00 +0000
173+++ tests/04_test_install_hello 2015-05-08 13:39:06 +0000
174@@ -0,0 +1,7 @@
175+test() {
176+ T="hello-world[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+(\.[0-9]+)+[[:space:]]+canonical"
177+ test_regexp "$T" sudo $SNAPPY install hello-world
178+
179+ T="Hello World!"
180+ test_equal "$T" hello-world.echo
181+}
182
183=== added file 'tests/05_test_install_nonexistant'
184--- tests/05_test_install_nonexistant 1970-01-01 00:00:00 +0000
185+++ tests/05_test_install_nonexistant 2015-05-08 13:39:06 +0000
186@@ -0,0 +1,5 @@
187+test() {
188+ pkg=fizzler
189+ T="^${pkg} failed to install: snappy package not found"
190+ test_regexp "$T" sudo $SNAPPY install $pkg
191+}
192
193=== added file 'tests/06_test_search_framework'
194--- tests/06_test_search_framework 1970-01-01 00:00:00 +0000
195+++ tests/06_test_search_framework 2015-05-08 13:39:06 +0000
196@@ -0,0 +1,4 @@
197+test() {
198+ T="$framework[[:space:]]+[0-9.]+[[:space:]]+.*"
199+ test_regexp "$T" $SNAPPY search "$framework"
200+}
201
202=== added file 'tests/07_test_install_framework'
203--- tests/07_test_install_framework 1970-01-01 00:00:00 +0000
204+++ tests/07_test_install_framework 2015-05-08 13:39:06 +0000
205@@ -0,0 +1,21 @@
206+test() {
207+ if after_reboot; then
208+ # ensure the service comes up after a reboot
209+ services=$(systemctl | grep "${framework}_.*.service")
210+ [ -n "$services" ] || fail "$framework provided no services"
211+ return
212+ fi
213+
214+ # we test that the final line contains the framework command
215+ # FIXME: test progress here too
216+ T="$framework[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+"
217+ test_regexp "$T" sudo $SNAPPY install "$framework_full"
218+
219+ # ensure its there
220+ services=$(systemctl | grep "${framework}_.*.service")
221+ [ -n "$services" ] || fail "$framework provided no services"
222+
223+ if can_reboot; then
224+ reboot
225+ fi
226+}
227
228=== added file 'tests/08_test_versions_has_framework'
229--- tests/08_test_versions_has_framework 1970-01-01 00:00:00 +0000
230+++ tests/08_test_versions_has_framework 2015-05-08 13:39:06 +0000
231@@ -0,0 +1,4 @@
232+test() {
233+ T="$framework[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+"
234+ test_regexp "$T" $SNAPPY list
235+}
236
237=== added file 'tests/10_test_info_has_stuff'
238--- tests/10_test_info_has_stuff 1970-01-01 00:00:00 +0000
239+++ tests/10_test_info_has_stuff 2015-05-08 13:39:06 +0000
240@@ -0,0 +1,5 @@
241+test() {
242+ test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
243+ test_regexp "^frameworks: $framework" $SNAPPY info
244+ test_regexp "^apps:.*\<hello-world\>" $SNAPPY info
245+}
246
247=== added file 'tests/11_test_xkcd_listens'
248--- tests/11_test_xkcd_listens 1970-01-01 00:00:00 +0000
249+++ tests/11_test_xkcd_listens 2015-05-08 13:39:06 +0000
250@@ -0,0 +1,15 @@
251+test() {
252+ # FIXME: add $SNAPPY search webserver
253+
254+ sudo $SNAPPY install xkcd-webserver.canonical
255+
256+ # FIXME: sucks, needed because "systemctl start" does not
257+ # wait until the service is really started
258+ sleep 1
259+
260+ T="HTTP/1.0 200 OK"
261+ TEMPF=$(tempfile)
262+ printf "GET / HTTP/1.0\n\n"|nc localhost 80 > $TEMPF
263+ test_regexp "$T" cat $TEMPF
264+ rm -f $TEMPF
265+}
266
267=== added file 'tests/90_test_upgrade'
268--- tests/90_test_upgrade 1970-01-01 00:00:00 +0000
269+++ tests/90_test_upgrade 2015-05-08 13:39:06 +0000
270@@ -0,0 +1,67 @@
271+# Test that we can upgrade to the latest image version and roll back to the
272+# original version. Test will be skipped the testbed does not offer reboot
273+# (needs autopkgtest with a supporting runner).
274+
275+test() {
276+ can_reboot || { echo "SKIP: cannot reboot testbed"; return; }
277+
278+ versions=$(snappy list)
279+ current=$(echo "$versions" | awk '/ubuntu-core/ {print $3}')
280+ echo "original current snappy version: $current"
281+
282+ # debug
283+ echo "Boot order"
284+ grep root=LABEL /boot/grub/grub.cfg
285+
286+ if after_reboot; then
287+ # second reboot: after rollback
288+ if [ -e $ADT_ARTIFACTS/rolled_back ]; then
289+ orig_current=$(cat $ADT_ARTIFACTS/current)
290+ [ "$orig_current" = "$current" ] || fail "did not roll back to version $orig_current"
291+ return
292+ fi
293+
294+ # first reboot: after upgrade
295+ orig_avail=$(cat $ADT_ARTIFACTS/avail)
296+ [ "$orig_avail" = "$current" ] || fail "did not upgrade to current version"
297+
298+ echo "rolling back..."
299+ sudo snappy rollback ubuntu-core
300+ touch $ADT_ARTIFACTS/rolled_back
301+ reboot
302+ return
303+ fi
304+
305+ # fake new available version by doing a current--
306+ sudo mount -o remount,rw /
307+ sudo sed -i "s/build_number: $current/build_number: $((current-1))/" /etc/system-image/channel.ini
308+ sudo mount -o remount,ro /
309+
310+ if [ -e /writable/cache/system/etc/system-image/channel.ini ]; then
311+ sudo mount -o remount,rw /writable/cache/system/
312+ sudo sed -i 's/build_number: $current/build_number: $((current-1))/' /writable/cache/system/etc/system-image/channel.ini
313+ sudo mount -o remount,ro /writable/cache/system/
314+ fi
315+
316+ # we should have something now :)
317+ versions=$(snappy list)
318+ current=$(echo "$versions" | awk '/ubuntu-core/ {print $3}')
319+ echo "faked current snappy version: $current"
320+
321+ versions=$(snappy list -u)
322+ avail=$(echo "$versions" | awk '/ubuntu-core/ {print $3}')
323+ echo "available snappy version to upgrade: $avail"
324+
325+ # skip if not numeric, e. g. "-"
326+ [ "$avail" != "${avail#[0-9]}" ] || { echo "SKIP: no image to upgrade to"; return; }
327+
328+ [ $avail -gt $current ] || fail "$avail is not newer than $current"
329+
330+ # save version for post-upgrade test
331+ echo "$avail" > $ADT_ARTIFACTS/avail
332+ echo "$current" > $ADT_ARTIFACTS/current
333+
334+ echo "upgrading..."
335+ sudo snappy update
336+ reboot
337+}
338
339=== added file 'tests/91_test_upgrade_from_stable_image'
340--- tests/91_test_upgrade_from_stable_image 1970-01-01 00:00:00 +0000
341+++ tests/91_test_upgrade_from_stable_image 2015-05-08 13:39:06 +0000
342@@ -0,0 +1,69 @@
343+# Test that we can upgrade from the latest *stable* image version to the
344+# current edge image version and rollback original version.
345+#
346+# Make image for this with:
347+#
348+# $ sudo ubuntu-device-flash core --channel=stable 15.04 -o snappy-stable.img --developer-mode --enable-ssh
349+#
350+# Run with:
351+# adt-run upgrade-test/ --- ssh -s snappy -- -i /path/to/snappy-stable.img
352+
353+test() {
354+ can_reboot || { echo "SKIP: cannot reboot testbed"; return; }
355+
356+ versions=$(snappy list)
357+ current=$(echo "$versions" | awk '/ubuntu-core/ {print $3}')
358+ echo "original current snappy version: $current"
359+
360+ # debug
361+ echo "Boot order"
362+ grep root=LABEL /boot/grub/grub.cfg
363+
364+ if after_reboot; then
365+ # second reboot: after rollback
366+ if [ -e $ADT_ARTIFACTS/rolled_back-stable ]; then
367+ orig_current=$(cat $ADT_ARTIFACTS/current)
368+ [ "$orig_current" = "$current" ] || fail "did not roll back to version $orig_current"
369+ return
370+ fi
371+
372+ # first reboot: after upgrade
373+ orig_avail=$(cat $ADT_ARTIFACTS/avail)
374+ [ "$orig_avail" = "$current" ] || fail "did not upgrade to current version"
375+
376+ echo "rolling back..."
377+ sudo snappy rollback ubuntu-core
378+ touch $ADT_ARTIFACTS/rolled_back-stable
379+ reboot
380+ return
381+ fi
382+
383+ # switch channel
384+ sudo mount -o remount,rw /
385+ sudo sed -i 's#channel: ubuntu-core/\(.*\)/stable#channel: ubuntu-core/\1/edge#' /etc/system-image/channel.ini
386+ sudo mount -o remount,ro /
387+
388+ if [ -e /writable/cache/system/etc/system-image/channel.ini ]; then
389+ sudo mount -o remount,rw /writable/cache/system/
390+ sudo sed -i 's#channel: ubuntu-core/\(.*\)/stable#channel: ubuntu-core/\1/edge#' /writable/cache/system/etc/system-image/channel.ini
391+ sudo mount -o remount,ro /writable/cache/system/
392+ fi
393+
394+ # now upgrade to latest edge from stable
395+ versions=$(snappy list -u)
396+ avail=$(echo "$versions" | awk '/ubuntu-core/ {print $3}')
397+ echo "available snappy version to upgrade: $avail"
398+
399+ # skip if not numeric, e. g. "-"
400+ [ "$avail" != "${avail#[0-9]}" ] || { echo "SKIP: no image to upgrade to"; return; }
401+
402+ [ $avail -gt $current ] || fail "$avail is not newer than $current"
403+
404+ # save version for post-upgrade test
405+ echo "$avail" > $ADT_ARTIFACTS/avail
406+ echo "$current" > $ADT_ARTIFACTS/current
407+
408+ echo "upgrading..."
409+ sudo snappy update
410+ reboot
411+}
412
413=== added file 'tests/framework'
414--- tests/framework 1970-01-01 00:00:00 +0000
415+++ tests/framework 2015-05-08 13:39:06 +0000
416@@ -0,0 +1,46 @@
417+fail() {
418+ echo "ERROR" $@
419+ exit 1
420+}
421+
422+test_equal() {
423+ local expected="$1"
424+ shift
425+ "$@" 2>&1 | diff -u <(echo "$expected") -
426+}
427+
428+test_regexp() {
429+ local REGEXP="$1"
430+ shift
431+ local ACTUAL=$("$@" 2>&1)
432+ if ! echo "$ACTUAL" | grep -E -q "$REGEXP"; then
433+ echo "Can not find '$REGEXP' in '$ACTUAL'"
434+ fail
435+ fi
436+}
437+
438+# check if reboot is supported; this needs running with autopkgtest on a
439+# supported testbed (QEMU or ssh with a setup script that announces the
440+# "reboot" capability)
441+can_reboot() {
442+ [ -x /tmp/autopkgtest-reboot ]
443+}
444+
445+# reboot the testbed; the same test will be started again, check after_reboot()
446+# to see in which state you are in
447+reboot() {
448+ if [ -z "$CURRENT_TEST" ]; then
449+ echo 'ERROR: $CURRENT_TEST not defined' >&2
450+ exit 1
451+ fi
452+ echo "Rebooting testbed..."
453+ sudo /tmp/autopkgtest-reboot "$CURRENT_TEST"
454+}
455+
456+# true if the current test reboot()ed and is now restarted after boot; false if
457+# it's the first time the test runs (or reboot is not supported)
458+after_reboot() {
459+ [ "$ADT_REBOOT_MARK" = "$CURRENT_TEST" ]
460+}
461+
462+# vim: filetype=sh shiftwidth=4
463
464=== added file 'tests/settings'
465--- tests/settings 1970-01-01 00:00:00 +0000
466+++ tests/settings 2015-05-08 13:39:06 +0000
467@@ -0,0 +1,3 @@
468+# name of framework that will be installed for testing
469+framework=docker
470+framework_full=docker

Subscribers

People subscribed via source and target branches