Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/tests-extras:master into ~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras:master

Proposed by Alfonso Sanchez-Beato
Status: Merged
Merged at revision: 6b205fb6ec10446a6dca0246ef0554725dac6dd1
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/tests-extras:master
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras:master
Diff against target: 336 lines (+84/-73)
4 files modified
create-image-scripts/create-image.sh (+38/-38)
run-tests.sh (+2/-2)
templates/run-tests.sh (+17/-6)
tests-runner.sh (+27/-27)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Needs Fixing
Review via email: mp+368281@code.launchpad.net

Commit message

Improvements to allow spread testing of snaps out for snappy-hwe-team.

Description of the change

Improvements to allow spread testing of snaps out for snappy-hwe-team.

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)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/create-image-scripts/create-image.sh b/create-image-scripts/create-image.sh
2index 19dd0af..d51d523 100755
3--- a/create-image-scripts/create-image.sh
4+++ b/create-image-scripts/create-image.sh
5@@ -16,7 +16,7 @@
6
7 set -e
8
9-if [ $(id -u) -ne 0 ] ; then
10+if [ "$(id -u)" -ne 0 ] ; then
11 echo "ERROR: needs to be executed as root"
12 exit 1
13 fi
14@@ -34,7 +34,7 @@ show_help() {
15 echo
16 echo "optional arguments:"
17 echo " --channel=<channel> Select another channel to build the image from (default: $channel)"
18- echo " --snap=<name> Extra snap to install"
19+ echo " --snap=<name> Snap to copy inside the image to make it available to the tests"
20 echo " --unsigned-core-snap Use an unsigned core snap (so that it might be replaced during a test"
21 echo " --unsigned-gadget-snap Use an unsigned gadget snap"
22 echo " --unsigned-kernel-snap Use an unsigned kernel snap"
23@@ -76,42 +76,37 @@ done
24
25
26 model=pc
27-arch=amd64
28 image_name=ubuntu-core-16.img
29 ubuntu_image_extra_args=
30
31-if [ -n "$snap" ] ; then
32- ubuntu_image_extra_args="--extra-snaps $snap"
33-fi
34-
35 if [ -n "$unsigned_core" ] ; then
36- snap download --$channel core
37+ snap download --"$channel" core
38 ubuntu_image_extra_args="$ubuntu_image_extra_args --extra-snaps core_*.snap"
39 fi
40
41 if [ -n "$unsigned_gadget" ] ; then
42- snap download --$channel pc
43+ snap download --"$channel" pc
44 ubuntu_image_extra_args="$ubuntu_image_extra_args --extra-snaps pc_*.snap"
45 fi
46
47 if [ -n "$unsigned_kernel" ] ; then
48- snap download --$channel pc-kernel
49+ snap download --"$channel" pc-kernel
50 ubuntu_image_extra_args="$ubuntu_image_extra_args --extra-snaps pc-kernel_*.snap"
51 fi
52
53-ubuntu-image \
54- --channel $channel \
55- -O $(pwd) \
56+ubuntu-image snap \
57+ --channel "$channel" \
58+ -O "$(pwd)" \
59 --image-size 4G \
60- $ubuntu_image_extra_args \
61- $model.model
62+ "$ubuntu_image_extra_args" \
63+ "$model".model
64
65-mv $model.img $image_name
66+mv "$model".img "$image_name"
67
68 # kpartx -s: don't return until the partitions are created
69 partitions=$(sudo kpartx -asv ubuntu-core-16.img | grep "add map" | cut -d' ' -f3)
70 for part in $partitions; do
71- loop_path=/dev/mapper/$part
72+ loop_path=/dev/mapper/"$part"
73 if blkid -s LABEL "$loop_path" | grep 'LABEL="writable"'; then
74 break
75 fi
76@@ -125,32 +120,37 @@ tmp_mount=$(mktemp -d)
77
78 mount "$loop_path" "$tmp_mount"
79
80+# Make snap available in the image
81+if [ -n "$snap" ]; then
82+ cp "$snap" "$tmp_mount"/system-data/
83+fi
84+
85 # Migrate all systemd units from core snap into the writable area. This
86 # would be normally done on firstboot by the initramfs but we can't rely
87 # on that because we are adding another file in there and that will
88 # prevent the initramfs from transitioning any files.
89-core_snap=$(find $tmp_mount/system-data/var/lib/snapd/snaps -name "core_*.snap")
90+core_snap=$(find "$tmp_mount"/system-data/var/lib/snapd/snaps -name "core_*.snap")
91 tmp_core=$(mktemp -d)
92-mount $core_snap $tmp_core
93-mkdir -p $tmp_mount/system-data/etc/systemd
94-cp -rav $tmp_core/etc/systemd/* \
95- $tmp_mount/system-data/etc/systemd/
96-umount $tmp_core
97-rm -rf $tmp_core
98+mount "$core_snap" "$tmp_core"
99+mkdir -p "$tmp_mount"/system-data/etc/systemd
100+cp -ra "$tmp_core"/etc/systemd/* \
101+ "$tmp_mount"/system-data/etc/systemd/
102+umount "$tmp_core"
103+rm -rf "$tmp_core"
104
105 # system-user assertion which gives us our test:test user we use to
106 # log into the system
107-mkdir -p $tmp_mount/system-data/var/lib/snapd/seed/assertions
108-cp test-user.assertion $tmp_mount/system-data/var/lib/snapd/seed/assertions
109+mkdir -p "$tmp_mount"/system-data/var/lib/snapd/seed/assertions
110+cp test-user.assertion "$tmp_mount"/system-data/var/lib/snapd/seed/assertions
111
112 # Disable console-conf for the first boot
113-mkdir -p $tmp_mount/system-data/var/lib/console-conf/
114-touch $tmp_mount/system-data/var/lib/console-conf/complete
115+mkdir -p "$tmp_mount"/system-data/var/lib/console-conf/
116+touch "$tmp_mount"/system-data/var/lib/console-conf/complete
117
118 # Create systemd service which is running on firstboot and sets up
119 # various things for us.
120-mkdir -p $tmp_mount/system-data/etc/systemd/system
121-cat << 'EOF' > $tmp_mount/system-data/etc/systemd/system/devmode-firstboot.service
122+mkdir -p "$tmp_mount"/system-data/etc/systemd/system
123+cat << 'EOF' > "$tmp_mount"/system-data/etc/systemd/system/devmode-firstboot.service
124 [Unit]
125 Description=Run devmode firstboot setup
126 After=snapd.service snapd.socket
127@@ -162,12 +162,12 @@ RemainAfterExit=yes
128 TimeoutSec=3min
129 EOF
130
131-mkdir -p $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants
132+mkdir -p "$tmp_mount"/system-data/etc/systemd/system/multi-user.target.wants
133 ln -sf /etc/systemd/system/devmode-firstboot.service \
134- $tmp_mount/system-data/etc/systemd/system/multi-user.target.wants/devmode-firstboot.service
135+ "$tmp_mount"/system-data/etc/systemd/system/multi-user.target.wants/devmode-firstboot.service
136
137-mkdir $tmp_mount/system-data/var/lib/devmode-firstboot
138-cat << EOF > $tmp_mount/system-data/var/lib/devmode-firstboot/00-snapd-config.yaml
139+mkdir "$tmp_mount"/system-data/var/lib/devmode-firstboot
140+cat << EOF > "$tmp_mount"/system-data/var/lib/devmode-firstboot/00-snapd-config.yaml
141 network:
142 version: 2
143 ethernets:
144@@ -175,7 +175,7 @@ network:
145 dhcp4: true
146 EOF
147
148-cat << 'EOF' > $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
149+cat << 'EOF' > "$tmp_mount"/system-data/var/lib/devmode-firstboot/run.sh
150 #!/bin/sh
151
152 set -e
153@@ -220,8 +220,8 @@ touch /writable/system-data/var/lib/devmode-firstboot/complete
154 reboot
155 EOF
156
157-chmod +x $tmp_mount/system-data/var/lib/devmode-firstboot/run.sh
158+chmod +x "$tmp_mount"/system-data/var/lib/devmode-firstboot/run.sh
159
160-umount $tmp_mount
161+umount "$tmp_mount"
162 kpartx -d $image_name
163-rm -rf $tmp_mount
164+rm -rf "$tmp_mount"
165diff --git a/run-tests.sh b/run-tests.sh
166index 1fcfdc0..05cce59 100755
167--- a/run-tests.sh
168+++ b/run-tests.sh
169@@ -14,11 +14,11 @@
170 # You should have received a copy of the GNU General Public License
171 # along with this program. If not, see <http://www.gnu.org/licenses/>.
172
173-if [ ! -x "`which shellcheck`" ]; then
174+if [ ! -x "$(which shellcheck)" ]; then
175 sudo apt install shellcheck
176 fi
177
178 FILES_TO_TEST="tests-runner.sh templates/run-tests.sh"
179 for f in $FILES_TO_TEST ; do
180- shellcheck -e SC2086 $f
181+ shellcheck "$f"
182 done
183diff --git a/templates/run-tests.sh b/templates/run-tests.sh
184index f069bfb..a4ada66 100755
185--- a/templates/run-tests.sh
186+++ b/templates/run-tests.sh
187@@ -1,4 +1,4 @@
188-#!/bin/sh
189+#!/bin/bash
190 #
191 # Copyright (C) 2016 Canonical Ltd
192 #
193@@ -17,7 +17,7 @@
194 set -e
195
196 TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras"
197-TESTS_EXTRAS_PATH=".tests-extras"
198+TESTS_EXTRAS_PATH="tests-extras"
199
200 show_help() {
201 exec cat <<'EOF'
202@@ -36,8 +36,7 @@ EOF
203 # Clone the tests-extras repository
204 clone_tests_extras() {
205 echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..."
206- git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1
207- if [ $? -ne 0 ]; then
208+ if ! git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1; then
209 echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.."
210 exit 1
211 fi
212@@ -58,6 +57,16 @@ restore_and_update_tests_extras() {
213 # The tests-extras repository ends up checked out in the snap tree but as a
214 # hidden directory which is re-used since then.
215
216+# Find snap to use in the tests
217+snaps=$(find . -maxdepth 1 -type f -name '*_*.snap')
218+while read -r snap_file; do
219+ if [ -n "$snap" ]; then
220+ printf "More than one snap revision in the folder\n"
221+ exit 1
222+ fi
223+ snap=$PWD/${snap_file#*/}
224+done < <(printf "%s\n" "$snaps")
225+
226 [ ! -d "$TESTS_EXTRAS_PATH" ] && [ "$1" = "--help" ] && show_help
227
228 if [ -d "$TESTS_EXTRAS_PATH" ]; then
229@@ -68,9 +77,11 @@ fi
230
231 # Any project-specific options for test-runner should be specified in
232 # .tests_config under EXTRA_ARGS
233-if [ -e ".tests_config" ]; then
234+if [ -f ".tests_config" ]; then
235+ # shellcheck disable=SC1091
236 . .tests_config
237 fi
238
239 echo "INFO: Executing tests runner"
240-cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@" "$EXTRA_ARGS"
241+# shellcheck disable=SC2086
242+cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@" --snap="$snap" $EXTRA_ARGS
243diff --git a/tests-runner.sh b/tests-runner.sh
244index 6a33587..f96900d 100755
245--- a/tests-runner.sh
246+++ b/tests-runner.sh
247@@ -24,7 +24,6 @@ snap=
248 spread_filter=
249 spread_opts="-v"
250 spread_system=
251-force_new_image=0
252 test_from_channel=
253 image_unsigned_core=
254 image_unsigned_gadget=
255@@ -44,7 +43,7 @@ there passing arguments as-is.
256 optional arguments:
257 --help Show this help message and exit
258 --channel=<channel> Select another channel to build the base image from (default: $channel)
259- --snap=<name> Extra snap to install
260+ --snap=<name> Snap to copy inside the image to make it available to the tests
261 --debug Enable verbose debugging output
262 --verbose Be extra verbose
263 --test-from-channel=<channel> Pull snap from the specified channel instead of building it from source
264@@ -108,7 +107,7 @@ while [ -n "$1" ]; do
265 shift
266 ;;
267 --force-new-image)
268- force_new_image=1
269+ printf "WARNING: --force-new-image is deprecated\n"
270 shift
271 ;;
272 --image-unsigned-core)
273@@ -162,33 +161,33 @@ if [ "$SPREAD_BACKEND" = "qemu" ] ; then
274 SPREAD_QEMU_PATH="$HOME/snap/spread/$current_version/.spread/qemu/"
275 fi
276
277- if [ ! -e "$SPREAD_QEMU_PATH/$image_name" ] || [ $force_new_image -eq 1 ] ; then
278-
279- CREATE_IMAGE_PATH="./create-image-scripts"
280-
281- create_image_args="--channel=$channel"
282-
283- if [ -n "$snap" ]; then
284- create_image_args+="$create_image_args --snap=$snap"
285- fi
286-
287- if [ -n "$image_unsigned_core" ] ; then
288- create_image_args="$create_image_args --unsigned-core-snap"
289- fi
290-
291- if [ -n "$image_unsigned_gadget" ] ; then
292- create_image_args="$create_image_args --unsigned-gadget-snap"
293- fi
294+ # We always create a new VM - it is quite cheap and we avoid
295+ # contamination from previous test runs.
296+ if [ -e "$SPREAD_QEMU_PATH/$image_name" ]; then
297+ rm -rf "$SPREAD_QEMU_PATH"
298+ fi
299
300- if [ -n "$image_unsigned_kernel" ] ; then
301- create_image_args="$create_image_args --unsigned-kernel-snap"
302- fi
303+ CREATE_IMAGE_PATH="./create-image-scripts"
304+ create_image_args="--channel=$channel"
305
306- echo "INFO: Creating new qemu test image ..."
307- (cd $CREATE_IMAGE_PATH; $SUDO ./create-image.sh $create_image_args)
308- mkdir -p "$SPREAD_QEMU_PATH"
309- mv $CREATE_IMAGE_PATH/ubuntu-core-16.img "$SPREAD_QEMU_PATH/$image_name"
310+ if [ -n "$snap" ]; then
311+ create_image_args="$create_image_args --snap=$snap"
312+ fi
313+ if [ -n "$image_unsigned_core" ] ; then
314+ create_image_args="$create_image_args --unsigned-core-snap"
315+ fi
316+ if [ -n "$image_unsigned_gadget" ] ; then
317+ create_image_args="$create_image_args --unsigned-gadget-snap"
318 fi
319+ if [ -n "$image_unsigned_kernel" ] ; then
320+ create_image_args="$create_image_args --unsigned-kernel-snap"
321+ fi
322+
323+ echo "INFO: Creating qemu test image ..."
324+ # shellcheck disable=SC2086
325+ (cd $CREATE_IMAGE_PATH; $SUDO ./create-image.sh $create_image_args)
326+ mkdir -p "$SPREAD_QEMU_PATH"
327+ mv $CREATE_IMAGE_PATH/ubuntu-core-16.img "$SPREAD_QEMU_PATH/$image_name"
328 fi
329
330 # We currently only run spread tests but we could do other things
331@@ -202,4 +201,5 @@ if [ -n "$spread_system" ]; then
332 else
333 spread_opts="$spread_opts $SPREAD_BACKEND:$spread_filter"
334 fi
335+# shellcheck disable=SC2086
336 spread $spread_opts

Subscribers

People subscribed via source and target branches