Merge ~morphis/snappy-hwe-snaps/+git/wifi-ap:spread-tests into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Simon Fels
Status: Merged
Approved by: Simon Fels
Approved revision: b93a02749693fa8c56677061ba7cf44b698815d7
Merged at revision: ab67bfd7c649dcbcf41f515effaed068c6b08129
Proposed branch: ~morphis/snappy-hwe-snaps/+git/wifi-ap:spread-tests
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 657 lines (+555/-0)
17 files modified
README.md (+48/-0)
run-tests.sh (+75/-0)
spread.yaml (+49/-0)
tests/image/README.md (+7/-0)
tests/image/create-image.sh (+136/-0)
tests/image/pc-model.json (+11/-0)
tests/image/pc.model (+21/-0)
tests/image/test-user-assertion.json (+13/-0)
tests/image/test-user.assertion (+25/-0)
tests/lib/prepare-each.sh (+6/-0)
tests/lib/prepare.sh (+40/-0)
tests/lib/restore-each.sh (+22/-0)
tests/lib/snap-names.sh (+7/-0)
tests/main/configuration-changes/task.yaml (+16/-0)
tests/main/default-conf-brings-up-ap/task.yaml (+44/-0)
tests/main/default-configuration/tasks.yaml (+22/-0)
tests/main/installation/task.yaml (+13/-0)
Reviewer Review Type Date Requested Status
Konrad Zapałowicz (community) code Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+309495@code.launchpad.net

Description of the change

Add initial spread test infrastructure

Same as for network-manager. At some point we need to factor common things out and move them into a common place but lets see how things are going and not make things too complicated from the beginning.

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

LGTM

review: Approve (code)
Revision history for this message
Matteo Croce (teknoraver) :
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Same instructions on how to run the tests as in network-manager would be nice to have.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

sweet

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2new file mode 100644
3index 0000000..3c89bcd
4--- /dev/null
5+++ b/README.md
6@@ -0,0 +1,48 @@
7+# wifi-ap
8+
9+This snap provided WiFi AP functionality out of the box.
10+
11+Documentation is currently available at
12+https://docs.google.com/document/d/1vNu3fBqpOkBkjv_Vs9NZyTv50vOEfugrQqgxD0_f0rE/edit#
13+
14+## Running tests
15+
16+We have a set of spread (https://github.com/snapcore/spread) tests which
17+can be executed on a virtual machine or real hardware.
18+
19+In order to run those tests you need the follow things
20+
21+ * ubuntu-image
22+ * spread
23+
24+ You can install both as a snap
25+
26+ $ snap install --edge --devmode ubuntu-image
27+ $ snap install --devmode spread
28+
29+NOTE: As of today (27/10/2016) the version of spread in the store misses
30+some important bug fixes so you have to build your own one for now:
31+
32+ $ WORKDIR=`mktemp -d`
33+ $ export GOPATH=$WORKDIR
34+ $ go get -d -v github.com/snapcore/spread/...
35+ $ go build github.com/snapcore/spread/cmd/spread
36+ $ sudo cp spread /usr/local/bin
37+
38+Make sure /usr/local/bin is in your path and is used as default:
39+
40+ $ which spread
41+ /usr/local/bin/spread
42+
43+Now you have everything to run the test suite.
44+
45+ $ ./run-tests
46+
47+The script will create an image via ubuntu-image and make it available
48+to spread by copying it to ~/.spread/qemu or ~/snap/spread/<version>/.spread/qemu
49+depending on if you're using a local spread version or the one from the
50+snap.
51+
52+If you want to see more verbose debugging output of spread run
53+
54+ $ ./run-tests --debug
55diff --git a/run-tests.sh b/run-tests.sh
56new file mode 100755
57index 0000000..78ff9e1
58--- /dev/null
59+++ b/run-tests.sh
60@@ -0,0 +1,75 @@
61+#!/bin/bash
62+#
63+# Copyright (C) 2016 Canonical Ltd
64+#
65+# This program is free software: you can redistribute it and/or modify
66+# it under the terms of the GNU General Public License version 3 as
67+# published by the Free Software Foundation.
68+#
69+# This program is distributed in the hope that it will be useful,
70+# but WITHOUT ANY WARRANTY; without even the implied warranty of
71+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72+# GNU General Public License for more details.
73+#
74+# You should have received a copy of the GNU General Public License
75+# along with this program. If not, see <http://www.gnu.org/licenses/>.
76+
77+set -e
78+
79+show_help() {
80+ echo "Usage: run-tests.sh [OPTIONS]"
81+ echo
82+ echo "optional arguments:"
83+ echo " --help Show this help message and exit"
84+ echo " --channel Select another channel to build the base image from"
85+ echo " --debug Enable verbose debugging output"
86+}
87+
88+image_name=ubuntu-core-16.img
89+channel=candidate
90+spread_opts=
91+force_new_image=0
92+
93+while [ -n "$1" ]; do
94+ case "$1" in
95+ --help)
96+ show_help
97+ exit
98+ ;;
99+ --channel=*)
100+ channel="${1#*=}"
101+ shift
102+ ;;
103+ --debug)
104+ spread_opts="$spread_opts -vv -debug"
105+ shift
106+ ;;
107+ --force-new-image)
108+ force_new_image=1
109+ shift
110+ ;;
111+ *)
112+ echo "Unknown command: $1"
113+ exit 1
114+ ;;
115+ esac
116+done
117+
118+SPREAD_QEMU_PATH="$HOME/.spread/qemu"
119+if [ `which spread` = /snap/bin/spread ] ; then
120+ current_version=`readlink /snap/spread/current`
121+ SPREAD_QEMU_PATH="$HOME/snap/spread/$current_version/.spread/qemu/"
122+fi
123+
124+# Make sure we have a base image we use for testing
125+if [ ! -e $SPREAD_QEMU_PATH/$image_name ] || [ $force_new_image -eq 1 ] ; then
126+ echo "INFO: Creating new qemu test image ..."
127+ (cd tests/image ; sudo ./create-image.sh $channel)
128+ mkdir -p $SPREAD_QEMU_PATH
129+ mv tests/image/ubuntu-core-16.img $SPREAD_QEMU_PATH/$image_name
130+fi
131+
132+# We currently only run spread tests but we could do other things
133+# here as well like running our snap-lintian tool etc.
134+export SNAP_CHANNEL=$channel
135+exec spread $spread_opts
136diff --git a/spread.yaml b/spread.yaml
137new file mode 100644
138index 0000000..90791c7
139--- /dev/null
140+++ b/spread.yaml
141@@ -0,0 +1,49 @@
142+#
143+# Copyright (C) 2015, 2016 Canonical Ltd
144+#
145+# This program is free software: you can redistribute it and/or modify
146+# it under the terms of the GNU General Public License version 3 as
147+# published by the Free Software Foundation.
148+#
149+# This program is distributed in the hope that it will be useful,
150+# but WITHOUT ANY WARRANTY; without even the implied warranty of
151+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152+# GNU General Public License for more details.
153+#
154+# You should have received a copy of the GNU General Public License
155+# along with this program. If not, see <http://www.gnu.org/licenses/>.
156+
157+
158+project: wifi-ap
159+
160+environment:
161+ PROJECT_PATH: /home/wifi-ap
162+ TESTSLIB: $PROJECT_PATH/tests/lib
163+ SNAP_NAME: wifi-ap
164+ # Allow the host to pass the channel to use for the test rim
165+ SNAP_CHANNEL: $(HOST:echo $SNAP_CHANNEL)
166+
167+backends:
168+ qemu:
169+ systems:
170+ - ubuntu-core-16:
171+ username: test
172+ password: test
173+
174+# Put this somewhere where we have read-write access
175+path: /home/wifi-ap
176+
177+exclude:
178+ - .git
179+
180+suites:
181+ tests/main/:
182+ summary: Full-system tests for the wifi-ap snap
183+ systems:
184+ - ubuntu-core-16
185+ prepare: |
186+ . $TESTSLIB/prepare.sh
187+ prepare-each: |
188+ . $TESTSLIB/prepare-each.sh
189+ restore-each: |
190+ . $TESTSLIB/restore-each.sh
191diff --git a/tests/image/README.md b/tests/image/README.md
192new file mode 100644
193index 0000000..b75b66e
194--- /dev/null
195+++ b/tests/image/README.md
196@@ -0,0 +1,7 @@
197+# Generate user password
198+
199+You can generate the password for the system user assertion via
200+
201+```
202+ $ python3 -c 'import crypt; print(crypt.crypt("test", crypt.mksalt(crypt.METHOD_SHA512)))'
203+```
204diff --git a/tests/image/create-image.sh b/tests/image/create-image.sh
205new file mode 100755
206index 0000000..468949f
207--- /dev/null
208+++ b/tests/image/create-image.sh
209@@ -0,0 +1,136 @@
210+#!/bin/bash
211+#
212+# Copyright (C) 2016 Canonical Ltd
213+#
214+# This program is free software: you can redistribute it and/or modify
215+# it under the terms of the GNU General Public License version 3 as
216+# published by the Free Software Foundation.
217+#
218+# This program is distributed in the hope that it will be useful,
219+# but WITHOUT ANY WARRANTY; without even the implied warranty of
220+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
221+# GNU General Public License for more details.
222+#
223+# You should have received a copy of the GNU General Public License
224+# along with this program. If not, see <http://www.gnu.org/licenses/>.
225+
226+set -e
227+
228+if [ $(id -u) -ne 0 ] ; then
229+ echo "ERROR: needs to be executed as root"
230+ exit 1
231+fi
232+
233+channel=candidate
234+if [ ! -z "$1" ] ; then
235+ channel=$1
236+fi
237+
238+model=pc
239+arch=amd64
240+image_name=ubuntu-core-16.img
241+
242+ubuntu-image \
243+ --channel $channel \
244+ -o $image_name \
245+ --image-size 2G \
246+ $model.model
247+
248+kpartx -a $image_name
249+sleep 0.5
250+
251+loop_path=`findfs LABEL=writable`
252+tmp_mount=`mktemp -d`
253+
254+mount $loop_path $tmp_mount
255+
256+# Migrate all systemd units from core snap into the writable area. This
257+# would be normally done on firstboot by the initramfs but we can't rely
258+# on that because we are adding another file in there and that will
259+# prevent the initramfs from transitioning any files.
260+core_snap=$(find $tmp_mount/system-data/var/lib/snapd/snaps -name "core_*.snap")
261+tmp_core=`mktemp -d`
262+mount $core_snap $tmp_core
263+mkdir -p $tmp_mount/system-data/etc/systemd
264+cp -rav $tmp_core/etc/systemd/* \
265+ $tmp_mount/system-data/etc/systemd/
266+umount $tmp_core
267+rm -rf $tmp_core
268+
269+# system-user assertion which gives us our test:test user we use to
270+# log into the system
271+mkdir -p $tmp_mount/system-data/var/lib/snapd/seed/assertions
272+cp test-user.assertion $tmp_mount/system-data/var/lib/snapd/seed/assertions
273+
274+# Disable console-conf for the first boot
275+mkdir -p $tmp_mount/system-data/var/lib/console-conf/
276+touch $tmp_mount/system-data/var/lib/console-conf/complete
277+
278+# Create systemd service which is running on firstboot and sets up
279+# various things for us.
280+mkdir -p $tmp_mount/system-data/etc/systemd/system
281+cat << 'EOF' > $tmp_mount/system-data/etc/systemd/system/devmode-firstboot.service
282+[Unit]
283+Description=Run devmode firstboot setup
284+After=snapd.service snapd.socket
285+
286+[Service]
287+Type=oneshot
288+ExecStart=/writable/system-data/var/lib/devmode-firstboot/run.sh
289+RemainAfterExit=yes
290+TimeoutSec=3min
291+EOF
292+
293+mkdir -p $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants
294+ln -sf /etc/systemd/system/devmode-firstboot.service \
295+ $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants/devmode-firstboot.service
296+
297+mkdir $tmp_mount/system-data/var/lib/devmode-firstboot
298+cat << 'EOF' > $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
299+#!/bin/bash
300+
301+set -e
302+
303+# Don't start again if we're already done
304+if [ -e /writable/system-data/var/lib/devmode-firstboot/complete ] ; then
305+ exit 0
306+fi
307+
308+echo "Start devmode-firstboot $(date -Iseconds --utc)"
309+
310+if [ "$(snap managed)" = "true" ]; then
311+ echo "System already managed, exiting"
312+ exit 0
313+fi
314+
315+# no changes at all
316+while ! snap changes ; do
317+ echo "No changes yet, waiting"
318+ sleep 1
319+done
320+
321+while snap changes | grep -qE '(Do|Doing) .*Initialize system state' ; do
322+ echo "Initialize system state is in progress, waiting"
323+ sleep 1
324+done
325+
326+if [ -n "$(snap known system-user)" ]; then
327+ echo "Trying to create known user"
328+ snap create-user --known --sudoer
329+fi
330+
331+# Enable console-conf again
332+rm /writable/system-data/var/lib/console-conf/complete
333+
334+# Mark us done
335+touch /writable/system-data/var/lib/devmode-firstboot/complete
336+
337+# Reboot the system as its now prepared for the user
338+reboot
339+EOF
340+
341+chmod +x $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
342+
343+umount $tmp_mount
344+kpartx -d $image_name
345+rm -rf $tmp_mount
346diff --git a/tests/image/pc-model.json b/tests/image/pc-model.json
347new file mode 100644
348index 0000000..2eb1411
349--- /dev/null
350+++ b/tests/image/pc-model.json
351@@ -0,0 +1,11 @@
352+{
353+ "type": "model",
354+ "authority-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
355+ "brand-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
356+ "series": "16",
357+ "model": "pc",
358+ "architecture": "amd64",
359+ "gadget": "pc",
360+ "kernel": "pc-kernel",
361+ "timestamp": "2016-09-09T08:27:36+00:00"
362+}
363diff --git a/tests/image/pc.model b/tests/image/pc.model
364new file mode 100644
365index 0000000..345b7e4
366--- /dev/null
367+++ b/tests/image/pc.model
368@@ -0,0 +1,21 @@
369+type: model
370+authority-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
371+series: 16
372+brand-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
373+model: pc
374+architecture: amd64
375+gadget: pc
376+kernel: pc-kernel
377+timestamp: 2016-09-09T08:27:36+00:00
378+sign-key-sha3-384: a4qX7md6GQGNcZc_cmWPBStTq4RNCnGTzF-4usF5wFylQ-xZQej-SD6prx8Yl89O
379+
380+AcLBXAQAAQoABgUCWBBNTwAKCRAVoE002xqmOPH/EACWLf1UeZgICjNbzLI5bO/84LExS8iUjarG
381+S7DRn8Ln5zu44pxz7UXJNjULgnU8yuKVPVWg0ij7DRvaj8tGxOMMAls1fjSRtEYR8oJFsI3jXDGw
382+cLjvJG/crUxV8DgdZFlF02Kb5VtmNDXs1OE3zpPeniG19JYHaf2hDz4SRmWZe4c2MFrAt2UwI/VC
383+o/209Fl3qA8p8x5EYOBycgHooHm3924NTF9mXbKSfLRgGS7YzmN4FXFyiGOTY6CRsp37XnkxGcA1
384++lyZz1X97qT/fOGVUFqHDqUZmuCs5sC3+DNonytTgKt5+7S+V+Ai45HEayD5f4gS9uscnTMTwEEJ
385+VgSZRU0My+iJwFlXHaGWQe9eC37YCZ3ahBxc2SpkFffXjYhEMtTtr1vDIYCAhbc2k8aa3hPE2GUg
386+3pv8zs1AuZzSVX+Rp4ysMBqU23UUVP6Bmvr7ZD3E8aEUxE6O/BEA10Km5oZPqpmBfcEVO8a0yZjn
387+YQxn4XzY1Nwq1d0sJIV7FEDsq9dXH9QCa4qsCH3KG3jHv32GapvLf8mpr6HSH+JmPM5kNeVugLVy
388+/RUAFNu+Y4hqhpRNC8fc+UDkVBXsLDqHb5gfXnhbFIH8LvpVFR20SSkg9/Km5xC+7wcey0h8SD6/
389+Eh70OPLxDkzitEn/1L/0V987dlJnhS4WpqrYfbHYwQ==
390diff --git a/tests/image/test-user-assertion.json b/tests/image/test-user-assertion.json
391new file mode 100644
392index 0000000..81f6beb
393--- /dev/null
394+++ b/tests/image/test-user-assertion.json
395@@ -0,0 +1,13 @@
396+{
397+ "type": "system-user",
398+ "authority-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
399+ "brand-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
400+ "series": ["16"],
401+ "models": ["pc"],
402+ "name": "Default Test User",
403+ "username": "test",
404+ "email": "test@localhost",
405+ "password": "$6$OCvKy4w/Ppxp7IvC$WPzWiIW.4y18h9htjbOuxLZ.sjQ5M2hoSiEu3FpMU0PMdHQuQdBOqvk8p6DMdS/R/nU/rXidClD23CbSkSgp30",
406+ "since": "2016-10-24T07:12:10+00:00",
407+ "until": "2017-10-24T07:12:10+00:00"
408+}
409diff --git a/tests/image/test-user.assertion b/tests/image/test-user.assertion
410new file mode 100644
411index 0000000..7ebb667
412--- /dev/null
413+++ b/tests/image/test-user.assertion
414@@ -0,0 +1,25 @@
415+type: system-user
416+authority-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
417+brand-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
418+email: test@localhost
419+models:
420+ - pc
421+name: Default Test User
422+password: $6$OCvKy4w/Ppxp7IvC$WPzWiIW.4y18h9htjbOuxLZ.sjQ5M2hoSiEu3FpMU0PMdHQuQdBOqvk8p6DMdS/R/nU/rXidClD23CbSkSgp30
423+series:
424+ - 16
425+since: 2016-10-24T07:12:10+00:00
426+until: 2017-10-24T07:12:10+00:00
427+username: test
428+sign-key-sha3-384: a4qX7md6GQGNcZc_cmWPBStTq4RNCnGTzF-4usF5wFylQ-xZQej-SD6prx8Yl89O
429+
430+AcLBXAQAAQoABgUCWBBOJAAKCRAVoE002xqmOKaRD/0cEKWb2nbwhk+BTgOrYZHrwzjbIWTZznDh
431+xCD6JWF/yr9br1vEmRz2zCNPPWZgFH9HaJ+mT/lktWIs7VVMIdwMDWYOR8P9rdWM/Jx6iyB3z0OI
432+YO31zaU4XLyolv/YSj/nFXMMD+jIeE4l8j4AtCSJwd7ZS9Jz8F/RfrD8EpG0JU1F55lq8MC0mjZ4
433+ul5ws8k9UiP8nA5IAG30NvvReiUGYqtdkO43eQmy88WABL95MbFsbfEk4/VduG0Gt3y/T8vDDcF6
434+NJEm8L+O9IXnPBAje0Ve0NX3YtOE3CDTkYRKR7xFFJq2cJVCSvf9CsorREg4KyfagIdMKDSa5Tiq
435+FzoAJTfI0ltq5cAnLImtxFKulJ+AnGUNMLrKFr1H0FGtqTZBfs/PcIxy0qY0YDXSF4/9F2PUBdQS
436+tSmN6pT9t1FCGy2Rf5n3QV4e0R2JzS6Kx+vdbPMYqhssQosLU5GwlWj8UbevtphAGf8u8nLBDYWs
437+MNIPi0IrPmzIewZBD05A6a8T+oHZ9dIg5SAnJ4gmz0sCzNDKarvYqLpcU1rZzu78/UypbHXDvBAt
438+gnxYpD6WHR2aHSeyx3WvOp130jFco2/55M0RTEm50isO1uv2DqTn9ULkBdCrG/zOqEmZgY18ds3P
439+yTaAbaIAqUe7scpAHY0a31tfnXq8cRyEX03e9g2Mrg==
440diff --git a/tests/lib/prepare-each.sh b/tests/lib/prepare-each.sh
441new file mode 100644
442index 0000000..de6816d
443--- /dev/null
444+++ b/tests/lib/prepare-each.sh
445@@ -0,0 +1,6 @@
446+SNAP_INSTALL_OPTS=
447+if [ -n "$SNAP_CHANNEL" ] ; then
448+ SNAP_INSTALL_OPTS="--$SNAP_CHANNEL"
449+fi
450+
451+snap install $SNAP_INSTALL_OPTS $SNAP_NAME
452diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh
453new file mode 100644
454index 0000000..9815ef4
455--- /dev/null
456+++ b/tests/lib/prepare.sh
457@@ -0,0 +1,40 @@
458+#!/bin/bash
459+
460+if [ $SPREAD_REBOOT -ge 1 ] ; then
461+ # Give system a moment to settle
462+ sleep 2
463+
464+ # For debugging dump all snaps and connected slots/plugs
465+ snap list
466+ snap interfaces
467+
468+ exit 0
469+fi
470+
471+echo "Wait for firstboot change to be ready"
472+while ! snap changes | grep -q "Done"; do
473+ snap changes || true
474+ snap change 1 || true
475+ sleep 1
476+done
477+
478+echo "Ensure fundamental snaps are still present"
479+. $TESTSLIB/snap-names.sh
480+for name in $gadget_name $kernel_name $core_name; do
481+ if ! snap list | grep -q $name ; then
482+ echo "Not all fundamental snaps are available, all-snap image not valid"
483+ echo "Currently installed snaps:"
484+ snap list
485+ exit 1
486+ fi
487+done
488+
489+echo "Kernel has a store revision"
490+snap list | grep ^${kernel_name} | grep -E " [0-9]+\s+canonical"
491+
492+# Snapshot of the current snapd state for a later restore
493+if [ ! -f $SPREAD_PATH/snapd-state.tar.gz ] ; then
494+ systemctl stop snapd.service snapd.socket
495+ tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd
496+ systemctl start snapd.socket
497+fi
498diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
499new file mode 100644
500index 0000000..36fb2d7
501--- /dev/null
502+++ b/tests/lib/restore-each.sh
503@@ -0,0 +1,22 @@
504+#!/bin/bash
505+
506+. $TESTSLIB/snap-names.sh
507+
508+# Remove all snaps not being the core, gadget, kernel or snap we're testing
509+for snap in /snap/*; do
510+ snap="${snap:6}"
511+ case "$snap" in
512+ "bin" | "$gadget_name" | "$kernel_name" | "$core_name")
513+ ;;
514+ *)
515+ snap remove "$snap"
516+ ;;
517+ esac
518+done
519+
520+# Ensure we have the same state for snapd as we had before
521+systemctl stop snapd.service snapd.socket
522+rm -rf /var/lib/snapd/*
523+tar xzf $SPREAD_PATH/snapd-state.tar.gz -C /
524+rm -rf /root/.snap
525+systemctl start snapd.service snapd.socket
526diff --git a/tests/lib/snap-names.sh b/tests/lib/snap-names.sh
527new file mode 100644
528index 0000000..f15b09a
529--- /dev/null
530+++ b/tests/lib/snap-names.sh
531@@ -0,0 +1,7 @@
532+#!/bin/bash
533+gadget_name=$(snap list | sed -n 's/^\(pc\|pi[23]\|dragonboard\) .*/\1/p')
534+kernel_name=$gadget_name-kernel
535+core_name=$(snap list | awk '/^(ubuntu-)?core / {print $1; exit}')
536+if [ "$kernel_name" = "pi3-kernel" ] ; then
537+ kernel_name=pi2-kernel
538+fi
539diff --git a/tests/main/configuration-changes/task.yaml b/tests/main/configuration-changes/task.yaml
540new file mode 100644
541index 0000000..acf96d2
542--- /dev/null
543+++ b/tests/main/configuration-changes/task.yaml
544@@ -0,0 +1,16 @@
545+summary: Test that we can change the configuration
546+
547+execute: |
548+ test "`wifi-ap.config get wifi.interface`" = "wlan0"
549+ wifi-ap.config set wifi.interface wlan1
550+ test "`wifi-ap.config get wifi.interface`" = "wlan1"
551+
552+ test `wifi-ap.config get disabled` -eq 1
553+ wifi-ap.config set disabled 0
554+ # Verify 'disabled' was safed and change to 'wifi.interface' is still there
555+ test `wifi-ap.config get disabled` -eq 0
556+ test "`wifi-ap.config get wifi.interface`" = "wlan1"
557+
558+ # FIXME: once we deny invalid configuration items we need to check
559+ # for them here as well
560+
561diff --git a/tests/main/default-conf-brings-up-ap/task.yaml b/tests/main/default-conf-brings-up-ap/task.yaml
562new file mode 100644
563index 0000000..349e7f4
564--- /dev/null
565+++ b/tests/main/default-conf-brings-up-ap/task.yaml
566@@ -0,0 +1,44 @@
567+summary: Verify that the default configuration is able to spawn up an AP
568+
569+prepare: |
570+ # Simulate two WiFi radio network interfaces
571+ modprobe mac80211_hwsim radios=2
572+
573+restore: |
574+ rmmod mac80211_hwsim
575+
576+execute: |
577+ # Default configuration will use wlan0 which we just created
578+ wifi-ap.config set disabled 0
579+
580+ systemctl restart snap.wifi-ap.backend
581+ while ! systemctl status snap.wifi-ap.backend ; do
582+ sleep 1
583+ done
584+
585+ snap install wireless-tools
586+ # FIXME: Can be dropped once we have a snap-declaration for this in place
587+ snap connect wireless-tools:network-control core:network-control
588+
589+ # Scan for existing WiFi networks and ensure our 'Ubuntu' one is part
590+ # of the result
591+ ifconfig wlan1 up
592+ wireless-tools.iw dev wlan1 scan | grep 'SSID: Ubuntu'
593+ wireless-tools.iw dev wlan1 scan | grep 'primary channel: 6'
594+ # There should be only a single network
595+ network_count=`wireless-tools.iw dev wlan1 scan | grep 'SSID: Ubuntu' | wc -l`
596+ test $network_count -eq 1
597+ # The AP should not be secured by default
598+ test ! `wireless-tools.iw dev wlan1 scan | grep 'WPA:'`
599+ test ! `wireless-tools.iw dev wlan1 scan | grep 'RSN:'`
600+
601+ # Verify we can associate with the AP
602+ wireless-tools.iw wlan1 connect Ubuntu
603+ wireless-tools.iw dev wlan1 link | grep 'SSID: Ubuntu'
604+
605+ # And we should get an IP address assigned over DHCP
606+ dhclient wlan1
607+ # IP Address and routing needs to be correct
608+ ifconfig wlan1 | grep 'inet addr:10.0.60'
609+ ip route | grep '10.0.60.0/24 dev wlan1'
610+ ip route | grep 'default via 10.0.60.1 dev wlan1'
611diff --git a/tests/main/default-configuration/tasks.yaml b/tests/main/default-configuration/tasks.yaml
612new file mode 100644
613index 0000000..0d9da9a
614--- /dev/null
615+++ b/tests/main/default-configuration/tasks.yaml
616@@ -0,0 +1,22 @@
617+summary: Verify snap has correct default configuration
618+
619+execute: |
620+ test `wifi-ap.config get debug` -eq 0
621+ test `wifi-ap.config get disabled` -eq 1
622+ test "`wifi-ap.config get dhcp.lease-time`" = "12h"
623+ test "`wifi-ap.config get dhcp.range-start`" = "10.0.60.3"
624+ test "`wifi-ap.config get dhcp.range-stop`" = "10.0.60.20"
625+ test `wifi-ap.config get share.disabled` = 0
626+ test "`wifi-ap.config get share.network-interface`" = "eth0"
627+ test "`wifi-ap.config get wifi.address`" = "10.0.60.1"
628+ test `wifi-ap.config get wifi.channel` -eq 6
629+ test "`wifi-ap.config get wifi.hostapd-driver`" = "nl80211"
630+ test "`wifi-ap.config get wifi.interface`" = "wlan0"
631+ test "`wifi-ap.config get wifi.interface-mode`" = "direct"
632+ test "`wifi-ap.config get wifi.netmask`" = "255.255.255.0"
633+ test "`wifi-ap.config get wifi.operation-mode`" = "g"
634+ test "`wifi-ap.config get wifi.security`" = "open"
635+ test "`wifi-ap.config get wifi.ssid`" = "Ubuntu"
636+ # FIXME: Once wifi-ap.config get returns correct error codes when an
637+ # item does not exist we can drop the grep check here.
638+ wifi-ap.config get wifi.security-passphrase | grep 'does not exist'
639diff --git a/tests/main/installation/task.yaml b/tests/main/installation/task.yaml
640new file mode 100644
641index 0000000..90cb364
642--- /dev/null
643+++ b/tests/main/installation/task.yaml
644@@ -0,0 +1,13 @@
645+summary: Test wifi-ap snap installation was successful
646+
647+execute: |
648+ # Service should be up an running
649+ systemctl status snap.wifi-ap.management-service
650+
651+ # Ensure all necessary plugs/slots are connected
652+ snap interfaces | grep -Pzq ":network-control +wifi-ap"
653+ snap interfaces | grep -Pzq ":firewall-control +wifi-ap"
654+ snap interfaces | grep -Pzq ":network-bind +wifi-ap"
655+ # As we don't have network-manager installed this one must
656+ # be disconnected.
657+ snap interfaces | grep -Pzq "(?s).*?\n- +wifi-ap:network-manager"

Subscribers

People subscribed via source and target branches

to all changes: