Merge ~kzapalowicz/snappy-hwe-snaps/+git/network-manager:feature/use-create-image-scripts-repo into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master

Proposed by Konrad Zapałowicz
Status: Merged
Approved by: Simon Fels
Approved revision: b59d07627c64f0b2769444ae35f79065ada8640c
Merge reported by: Konrad Zapałowicz
Merged at revision: not available
Proposed branch: ~kzapalowicz/snappy-hwe-snaps/+git/network-manager:feature/use-create-image-scripts-repo
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master
Diff against target: 416 lines (+54/-76)
4 files modified
.gitignore (+1/-0)
README.md (+8/-1)
dev/null (+0/-25)
run-tests.sh (+45/-50)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Simon Fels Approve
Jim Hodapp (community) Approve
Review via email: mp+315455@code.launchpad.net

This proposal supersedes a proposal from 2017-01-24.

Description of the change

tests: use the tests-extras repository

The tests-extras repository contains the tests-runner as well
as image creating scripts. This commit changes the run-tests.sh
script in a way that it fetches the tests-extras and uses it for
test execution.

See: https://code.launchpad.net/~kzapalowicz/snappy-hwe-snaps/+git/tests-extras/+merge/315453

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
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: Needs Fixing (continuous-integration)
Revision history for this message
Matteo Croce (teknoraver) : Posted in a previous version of this proposal
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

Explanations

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good, just setting this to needs information until the other guy's issues are addressed.

review: Needs Information
Revision history for this message
Jim Hodapp (jhodapp) wrote :

One other thing, the tests don't seem to work with the CI infrastructure that runs the spread tests. So this new script solution should not be approved until it passes CI.

review: Needs Fixing
fd7756d... by =?utf-8?q?Konrad_Zapa=C5=82owicz?= <email address hidden>

refactor run-tests.sh to match review comments

The run-tests.sh script does not remove the tests-extras repository
when the tests are finished. Instead it reuse it but first make sure
that it is in a know state by hard reset and pulling.

Moreover the tests-extras is now a hidden directory and the git is
told not to track the .tests-extras. The .gitignore is commited but
only when it is not locally modfied prior to running this script.

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: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
b59d076... by =?utf-8?q?Konrad_Zapa=C5=82owicz?= <email address hidden>

add .gitignore to the repository

This commit adds the .gitignore file and thus makes the part of
script where this is done unnecessary.

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: Needs Fixing (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

I'd top approve this, but I'm not a maintainer. Tony or Simon should be able to top approve.

Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

Sure, but before this happens I would like to get things straight with the System Enablement Bot.

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Absolutely :)

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2new file mode 100644
3index 0000000..082484d
4--- /dev/null
5+++ b/.gitignore
6@@ -0,0 +1 @@
7+.tests-extras
8diff --git a/README.md b/README.md
9index 5eac800..c54a4d8 100644
10--- a/README.md
11+++ b/README.md
12@@ -47,7 +47,14 @@ Now you have everything to run the test suite.
13 $ ./run-tests
14 ```
15
16-The script will create an image via ubuntu-image and make it available
17+The script will reach out to tests-extras repository and download the helper
18+scripts: image creator and test runner. Next it will execute the test runner
19+passing the arguments as-is.
20+
21+The helper scripts are tracked here:
22+https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras
23+
24+The test runner script will create an image via ubuntu-image and make it available
25 to spread by copying it to ~/.spread/qemu or ~/snap/spread/<version>/.spread/qemu
26 depending on if you're using a local spread version or the one from the
27 snap.
28diff --git a/run-tests.sh b/run-tests.sh
29index 0c8a1fc..fdba1d8 100755
30--- a/run-tests.sh
31+++ b/run-tests.sh
32@@ -16,69 +16,64 @@
33
34 set -e
35
36-image_name=ubuntu-core-16.img
37-channel=stable
38-spread_opts=
39-force_new_image=0
40-test_from_channel=0
41+TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras"
42+TESTS_EXTRAS_PATH=".tests-extras"
43
44+# Display help.
45+# This has to be in sync with the tests-extras/test-runner.sh script
46+# functionalities as the parameters to this one are passed directly there
47 show_help() {
48 echo "Usage: run-tests.sh [OPTIONS]"
49 echo
50+ echo "This is fetch & forget script and what it does is to fetch the"
51+ echo "tests-extras repository and execute the run-tests.sh script from"
52+ echo "there passing arguments as-is."
53+ echo
54 echo "optional arguments:"
55 echo " --help Show this help message and exit"
56- echo " --channel Select another channel to build the base image from (default: $channel)"
57+ echo " --channel Select another channel to build the base image from (default: stable)"
58+ echo " --snap Extra snap to install"
59 echo " --debug Enable verbose debugging output"
60 echo " --test-from-channel Pull network-manager snap from the specified channel instead of building it from source"
61 echo " --force-new-image Force generating a new image used for testing"
62 }
63
64-while [ -n "$1" ]; do
65- case "$1" in
66- --help)
67- show_help
68- exit
69- ;;
70- --channel=*)
71- channel=${1#*=}
72- shift
73- ;;
74- --test-from-channel)
75- test_from_channel=1
76- shift
77- ;;
78- --debug)
79- spread_opts="$spread_opts -vv -debug"
80- shift
81- ;;
82- --force-new-image)
83- force_new_image=1
84- shift
85- ;;
86- *)
87- echo "Unknown command: $1"
88- exit 1
89- ;;
90- esac
91-done
92+# Clone the tests-extras repository
93+clone_tests_extras() {
94+ echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..."
95+ (git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1)
96+ if [ $? -ne 0 ]; then
97+ echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.."
98+ exit 1
99+ fi
100+}
101
102-SPREAD_QEMU_PATH="$HOME/.spread/qemu"
103-if [ `which spread` = /snap/bin/spread ] ; then
104- current_version=`readlink /snap/spread/current`
105- SPREAD_QEMU_PATH="$HOME/snap/spread/$current_version/.spread/qemu/"
106-fi
107+# Make sure the already cloned tests-extras repository is in a known and update
108+# state before it is going to be used.
109+restore_and_update_tests_extras() {
110+ echo "INFO: Restoring and updating $TESTS_EXTRAS_PATH"
111+ (cd $TESTS_EXTRAS_PATH && git reset --hard && git clean -dfx && git pull)
112+ (cd ..)
113+}
114
115-# Make sure we have a base image we use for testing
116-if [ ! -e $SPREAD_QEMU_PATH/$image_name ] || [ $force_new_image -eq 1 ] ; then
117- echo "INFO: Creating new qemu test image ..."
118- (cd tests/image ; sudo ./create-image.sh $channel)
119- mkdir -p $SPREAD_QEMU_PATH
120- mv tests/image/ubuntu-core-16.img $SPREAD_QEMU_PATH/$image_name
121+# ==============================================================================
122+# This is fetch & forget script and what it does is to fetch the tests-extras
123+# repo and execute the run-tests.sh script from there passing arguments as-is.
124+#
125+# The tests-extras repository ends up checked out in the snap tree but as a
126+# hidden directory which is re-used since then.
127+
128+# Display help w/o fetching anything
129+if [ "$1" == "--help" ]; then
130+ show_help
131+ exit 0
132 fi
133
134-# We currently only run spread tests but we could do other things
135-# here as well like running our snap-lintian tool etc.
136-if [ $test_from_channel -eq 1 ] ; then
137- export SNAP_CHANNEL=$channel
138+if [ -d "$TESTS_EXTRAS_PATH" ]; then
139+ restore_and_update_tests_extras
140+else
141+ clone_tests_extras
142 fi
143-spread $spread_opts
144+
145+echo "INFO: Executing tests runner"
146+cd $TESTS_EXTRAS_PATH && ./tests-runner.sh $@
147diff --git a/tests/image/README.md b/tests/image/README.md
148deleted file mode 100644
149index b75b66e..0000000
150--- a/tests/image/README.md
151+++ /dev/null
152@@ -1,7 +0,0 @@
153-# Generate user password
154-
155-You can generate the password for the system user assertion via
156-
157-```
158- $ python3 -c 'import crypt; print(crypt.crypt("test", crypt.mksalt(crypt.METHOD_SHA512)))'
159-```
160diff --git a/tests/image/create-image.sh b/tests/image/create-image.sh
161deleted file mode 100755
162index e3c36e0..0000000
163--- a/tests/image/create-image.sh
164+++ /dev/null
165@@ -1,157 +0,0 @@
166-#!/bin/bash
167-#
168-# Copyright (C) 2016 Canonical Ltd
169-#
170-# This program is free software: you can redistribute it and/or modify
171-# it under the terms of the GNU General Public License version 3 as
172-# published by the Free Software Foundation.
173-#
174-# This program is distributed in the hope that it will be useful,
175-# but WITHOUT ANY WARRANTY; without even the implied warranty of
176-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177-# GNU General Public License for more details.
178-#
179-# You should have received a copy of the GNU General Public License
180-# along with this program. If not, see <http://www.gnu.org/licenses/>.
181-
182-set -e
183-
184-if [ $(id -u) -ne 0 ] ; then
185- echo "ERROR: needs to be executed as root"
186- exit 1
187-fi
188-
189-channel=candidate
190-if [ ! -z "$1" ] ; then
191- channel=$1
192-fi
193-
194-snap=
195-if [ ! -z "$2" ] ; then
196- snap=$2
197-fi
198-
199-model=pc
200-arch=amd64
201-image_name=ubuntu-core-16.img
202-ubuntu_image_extra_args=
203-
204-if [ ! -z "$snap" ] ; then
205- ubuntu_image_extra_args="--extra-snaps $snap"
206-fi
207-
208-ubuntu-image \
209- --channel $channel \
210- -o $image_name \
211- --image-size 4G \
212- $ubuntu_image_extra_args \
213- $model.model
214-
215-kpartx -a $image_name
216-sleep 0.5
217-
218-loop_path=`findfs LABEL=writable`
219-tmp_mount=`mktemp -d`
220-
221-mount $loop_path $tmp_mount
222-
223-# Migrate all systemd units from core snap into the writable area. This
224-# would be normally done on firstboot by the initramfs but we can't rely
225-# on that because we are adding another file in there and that will
226-# prevent the initramfs from transitioning any files.
227-core_snap=$(find $tmp_mount/system-data/var/lib/snapd/snaps -name "core_*.snap")
228-tmp_core=`mktemp -d`
229-mount $core_snap $tmp_core
230-mkdir -p $tmp_mount/system-data/etc/systemd
231-cp -rav $tmp_core/etc/systemd/* \
232- $tmp_mount/system-data/etc/systemd/
233-umount $tmp_core
234-rm -rf $tmp_core
235-
236-# system-user assertion which gives us our test:test user we use to
237-# log into the system
238-mkdir -p $tmp_mount/system-data/var/lib/snapd/seed/assertions
239-cp test-user.assertion $tmp_mount/system-data/var/lib/snapd/seed/assertions
240-
241-# Disable console-conf for the first boot
242-mkdir -p $tmp_mount/system-data/var/lib/console-conf/
243-touch $tmp_mount/system-data/var/lib/console-conf/complete
244-
245-# Create systemd service which is running on firstboot and sets up
246-# various things for us.
247-mkdir -p $tmp_mount/system-data/etc/systemd/system
248-cat << 'EOF' > $tmp_mount/system-data/etc/systemd/system/devmode-firstboot.service
249-[Unit]
250-Description=Run devmode firstboot setup
251-After=snapd.service snapd.socket
252-
253-[Service]
254-Type=oneshot
255-ExecStart=/writable/system-data/var/lib/devmode-firstboot/run.sh
256-RemainAfterExit=yes
257-TimeoutSec=3min
258-EOF
259-
260-mkdir -p $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants
261-ln -sf /etc/systemd/system/devmode-firstboot.service \
262- $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants/devmode-firstboot.service
263-
264-mkdir $tmp_mount/system-data/var/lib/devmode-firstboot
265-cat << EOF > $tmp_mount/system-data/var/lib/devmode-firstboot/00-snapd-config.yaml
266-network:
267- version: 2
268- ethernets:
269- eth0:
270- dhcp4: true
271-EOF
272-
273-cat << 'EOF' > $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
274-#!/bin/bash
275-
276-set -e
277-
278-# Don't start again if we're already done
279-if [ -e /writable/system-data/var/lib/devmode-firstboot/complete ] ; then
280- exit 0
281-fi
282-
283-echo "Start devmode-firstboot $(date -Iseconds --utc)"
284-
285-if [ "$(snap managed)" = "true" ]; then
286- echo "System already managed, exiting"
287- exit 0
288-fi
289-
290-# no changes at all
291-while ! snap changes ; do
292- echo "No changes yet, waiting"
293- sleep 1
294-done
295-
296-while snap changes | grep -qE '(Do|Doing) .*Initialize system state' ; do
297- echo "Initialize system state is in progress, waiting"
298- sleep 1
299-done
300-
301-if [ -n "$(snap known system-user)" ]; then
302- echo "Trying to create known user"
303- snap create-user --known --sudoer
304-fi
305-
306-cp /writable/system-data/var/lib/devmode-firstboot/00-snapd-config.yaml /writable/system-data/etc/netplan
307-
308-# Enable console-conf again
309-rm /writable/system-data/var/lib/console-conf/complete
310-
311-# Mark us done
312-touch /writable/system-data/var/lib/devmode-firstboot/complete
313-
314-# Reboot the system as its now prepared for the user
315-reboot
316-EOF
317-
318-chmod +x $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
319-
320-umount $tmp_mount
321-kpartx -d $image_name
322-rm -rf $tmp_mount
323diff --git a/tests/image/pc-model.json b/tests/image/pc-model.json
324deleted file mode 100644
325index 2eb1411..0000000
326--- a/tests/image/pc-model.json
327+++ /dev/null
328@@ -1,11 +0,0 @@
329-{
330- "type": "model",
331- "authority-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
332- "brand-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
333- "series": "16",
334- "model": "pc",
335- "architecture": "amd64",
336- "gadget": "pc",
337- "kernel": "pc-kernel",
338- "timestamp": "2016-09-09T08:27:36+00:00"
339-}
340diff --git a/tests/image/pc.model b/tests/image/pc.model
341deleted file mode 100644
342index 345b7e4..0000000
343--- a/tests/image/pc.model
344+++ /dev/null
345@@ -1,21 +0,0 @@
346-type: model
347-authority-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
348-series: 16
349-brand-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
350-model: pc
351-architecture: amd64
352-gadget: pc
353-kernel: pc-kernel
354-timestamp: 2016-09-09T08:27:36+00:00
355-sign-key-sha3-384: a4qX7md6GQGNcZc_cmWPBStTq4RNCnGTzF-4usF5wFylQ-xZQej-SD6prx8Yl89O
356-
357-AcLBXAQAAQoABgUCWBBNTwAKCRAVoE002xqmOPH/EACWLf1UeZgICjNbzLI5bO/84LExS8iUjarG
358-S7DRn8Ln5zu44pxz7UXJNjULgnU8yuKVPVWg0ij7DRvaj8tGxOMMAls1fjSRtEYR8oJFsI3jXDGw
359-cLjvJG/crUxV8DgdZFlF02Kb5VtmNDXs1OE3zpPeniG19JYHaf2hDz4SRmWZe4c2MFrAt2UwI/VC
360-o/209Fl3qA8p8x5EYOBycgHooHm3924NTF9mXbKSfLRgGS7YzmN4FXFyiGOTY6CRsp37XnkxGcA1
361-+lyZz1X97qT/fOGVUFqHDqUZmuCs5sC3+DNonytTgKt5+7S+V+Ai45HEayD5f4gS9uscnTMTwEEJ
362-VgSZRU0My+iJwFlXHaGWQe9eC37YCZ3ahBxc2SpkFffXjYhEMtTtr1vDIYCAhbc2k8aa3hPE2GUg
363-3pv8zs1AuZzSVX+Rp4ysMBqU23UUVP6Bmvr7ZD3E8aEUxE6O/BEA10Km5oZPqpmBfcEVO8a0yZjn
364-YQxn4XzY1Nwq1d0sJIV7FEDsq9dXH9QCa4qsCH3KG3jHv32GapvLf8mpr6HSH+JmPM5kNeVugLVy
365-/RUAFNu+Y4hqhpRNC8fc+UDkVBXsLDqHb5gfXnhbFIH8LvpVFR20SSkg9/Km5xC+7wcey0h8SD6/
366-Eh70OPLxDkzitEn/1L/0V987dlJnhS4WpqrYfbHYwQ==
367diff --git a/tests/image/test-user-assertion.json b/tests/image/test-user-assertion.json
368deleted file mode 100644
369index 81f6beb..0000000
370--- a/tests/image/test-user-assertion.json
371+++ /dev/null
372@@ -1,13 +0,0 @@
373-{
374- "type": "system-user",
375- "authority-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
376- "brand-id": "4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf",
377- "series": ["16"],
378- "models": ["pc"],
379- "name": "Default Test User",
380- "username": "test",
381- "email": "test@localhost",
382- "password": "$6$OCvKy4w/Ppxp7IvC$WPzWiIW.4y18h9htjbOuxLZ.sjQ5M2hoSiEu3FpMU0PMdHQuQdBOqvk8p6DMdS/R/nU/rXidClD23CbSkSgp30",
383- "since": "2016-10-24T07:12:10+00:00",
384- "until": "2017-10-24T07:12:10+00:00"
385-}
386diff --git a/tests/image/test-user.assertion b/tests/image/test-user.assertion
387deleted file mode 100644
388index 7ebb667..0000000
389--- a/tests/image/test-user.assertion
390+++ /dev/null
391@@ -1,25 +0,0 @@
392-type: system-user
393-authority-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
394-brand-id: 4BKZlf4WMNBKgQfij0rftmp5BzDdVhlf
395-email: test@localhost
396-models:
397- - pc
398-name: Default Test User
399-password: $6$OCvKy4w/Ppxp7IvC$WPzWiIW.4y18h9htjbOuxLZ.sjQ5M2hoSiEu3FpMU0PMdHQuQdBOqvk8p6DMdS/R/nU/rXidClD23CbSkSgp30
400-series:
401- - 16
402-since: 2016-10-24T07:12:10+00:00
403-until: 2017-10-24T07:12:10+00:00
404-username: test
405-sign-key-sha3-384: a4qX7md6GQGNcZc_cmWPBStTq4RNCnGTzF-4usF5wFylQ-xZQej-SD6prx8Yl89O
406-
407-AcLBXAQAAQoABgUCWBBOJAAKCRAVoE002xqmOKaRD/0cEKWb2nbwhk+BTgOrYZHrwzjbIWTZznDh
408-xCD6JWF/yr9br1vEmRz2zCNPPWZgFH9HaJ+mT/lktWIs7VVMIdwMDWYOR8P9rdWM/Jx6iyB3z0OI
409-YO31zaU4XLyolv/YSj/nFXMMD+jIeE4l8j4AtCSJwd7ZS9Jz8F/RfrD8EpG0JU1F55lq8MC0mjZ4
410-ul5ws8k9UiP8nA5IAG30NvvReiUGYqtdkO43eQmy88WABL95MbFsbfEk4/VduG0Gt3y/T8vDDcF6
411-NJEm8L+O9IXnPBAje0Ve0NX3YtOE3CDTkYRKR7xFFJq2cJVCSvf9CsorREg4KyfagIdMKDSa5Tiq
412-FzoAJTfI0ltq5cAnLImtxFKulJ+AnGUNMLrKFr1H0FGtqTZBfs/PcIxy0qY0YDXSF4/9F2PUBdQS
413-tSmN6pT9t1FCGy2Rf5n3QV4e0R2JzS6Kx+vdbPMYqhssQosLU5GwlWj8UbevtphAGf8u8nLBDYWs
414-MNIPi0IrPmzIewZBD05A6a8T+oHZ9dIg5SAnJ4gmz0sCzNDKarvYqLpcU1rZzu78/UypbHXDvBAt
415-gnxYpD6WHR2aHSeyx3WvOp130jFco2/55M0RTEm50isO1uv2DqTn9ULkBdCrG/zOqEmZgY18ds3P
416-yTaAbaIAqUe7scpAHY0a31tfnXq8cRyEX03e9g2Mrg==

Subscribers

People subscribed via source and target branches