Merge ~ssweeny/snappy-hwe-snaps/+git/tpm:aliases into ~snappy-hwe-team/snappy-hwe-snaps/+git/tpm:master

Proposed by Scott Sweeny
Status: Merged
Approved by: Tony Espy
Approved revision: 8895cb3ac6d5449036e54d02a35d1eee26764062
Merged at revision: ae497ed2c7d28c01c117666fcf87fc807ebd7b48
Proposed branch: ~ssweeny/snappy-hwe-snaps/+git/tpm:aliases
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/tpm:master
Diff against target: 438 lines (+316/-1)
9 files modified
run-tests.sh (+79/-0)
snapcraft.yaml (+23/-1)
spread.yaml (+53/-0)
tests/lib/prepare-all.sh (+25/-0)
tests/lib/prepare.sh (+37/-0)
tests/lib/restore-each.sh (+22/-0)
tests/lib/snap-names.sh (+7/-0)
tests/lib/utilities.sh (+39/-0)
tests/main/installation/task.yaml (+31/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Tony Espy Approve
Jim Hodapp (community) Approve
Simon Fels Needs Fixing
Review via email: mp+316647@code.launchpad.net

This proposal supersedes a proposal from 2016-12-19.

Commit message

Add aliases for tpm tools

Description of the change

Add aliases for tpm tools

Also adds a simple spread test and includes an earlier fix for LP: #1637251 that never got merged.

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
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
Jim Hodapp (jhodapp) wrote : Posted in a previous version of this proposal

Obviously the change looks good and you don't need a spread test for this change. But any chance you could add a simple spread test or two to make the CI requirement happy?

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

LGTM

review: Approve
Revision history for this message
Tony Espy (awe) wrote :

Two minor copyright changes needed...

review: Needs Fixing
Revision history for this message
Tony Espy (awe) 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
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) wrote :

Retriggered CI. Failed because of some timing issues with snapd starting up.

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)
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)
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)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/run-tests.sh b/run-tests.sh
2new file mode 100755
3index 0000000..1c0907e
4--- /dev/null
5+++ b/run-tests.sh
6@@ -0,0 +1,79 @@
7+#!/bin/sh
8+#
9+# Copyright (C) 2017 Canonical Ltd
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU General Public License version 3 as
13+# published by the Free Software Foundation.
14+#
15+# This program is distributed in the hope that it will be useful,
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+# GNU General Public License for more details.
19+#
20+# You should have received a copy of the GNU General Public License
21+# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
23+set -e
24+
25+TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras"
26+TESTS_EXTRAS_PATH=".tests-extras"
27+
28+# Display help.
29+# This has to be in sync with the tests-extras/test-runner.sh script
30+# functionalities as the parameters to this one are passed directly there
31+# this function will quit the script because of the 'exec' keyword
32+show_help() {
33+ exec cat <<'EOF'
34+Usage: run-tests.sh [OPTIONS]
35+
36+This is fetch & forget script and what it does is to fetch the
37+tests-extras repository and execute the run-tests.sh script from
38+there passing arguments as-is.
39+
40+optional arguments:
41+ --help Show this help message and exit
42+ --channel Select another channel to build the base image from (default: stable)
43+ --snap Extra snap to install
44+ --debug Enable verbose debugging output
45+ --test-from-channel Pull tpm snap from the specified channel instead of building it from source
46+ --force-new-image Force generating a new image used for testing
47+EOF
48+}
49+
50+# Clone the tests-extras repository
51+clone_tests_extras() {
52+ echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..."
53+ git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1
54+ if [ $? -ne 0 ]; then
55+ echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.."
56+ exit 1
57+ fi
58+}
59+
60+# Make sure the already cloned tests-extras repository is in a known and update
61+# state before it is going to be used.
62+restore_and_update_tests_extras() {
63+ echo "INFO: Restoring and updating $TESTS_EXTRAS_PATH"
64+ cd $TESTS_EXTRAS_PATH && git reset --hard && git clean -dfx && git pull
65+ cd -
66+}
67+
68+# ==============================================================================
69+# This is fetch & forget script and what it does is to fetch the tests-extras
70+# repo and execute the run-tests.sh script from there passing arguments as-is.
71+#
72+# The tests-extras repository ends up checked out in the snap tree but as a
73+# hidden directory which is re-used since then.
74+
75+# Display help w/o fetching anything and exit
76+[ "$1" = "--help" ] && show_help
77+
78+if [ -d "$TESTS_EXTRAS_PATH" ]; then
79+ restore_and_update_tests_extras
80+else
81+ clone_tests_extras
82+fi
83+
84+echo "INFO: Executing tests runner"
85+cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@"
86diff --git a/snapcraft.yaml b/snapcraft.yaml
87index db62c2d..09bf5dd 100644
88--- a/snapcraft.yaml
89+++ b/snapcraft.yaml
90@@ -15,69 +15,91 @@ apps:
91 version:
92 command: sbin/tpm_version
93 plugs: [network]
94+ aliases: [tpm_version]
95 selftest:
96 command: sbin/tpm_selftest
97 plugs: [network]
98+ aliases: [tpm_selftest]
99 takeownership:
100 command: sbin/tpm_takeownership
101 plugs: [network]
102+ aliases: [tpm_takeownership]
103 setenable:
104 command: sbin/tpm_setenable
105 plugs: [network]
106+ aliases: [tpm_setenable]
107 setactive:
108 command: sbin/tpm_setactive
109 plugs: [network]
110+ aliases: [tpm_setactive]
111 getpubek:
112 command: sbin/tpm_getpubek
113 plugs: [network]
114+ aliases: [tpm_getpubek]
115 changeownerauth:
116 command: sbin/tpm_changeownerauth # -o
117 plugs: [network]
118+ aliases: [tpm_changeownerauth]
119 resetdalock:
120 command: sbin/tpm_resetdalock
121 plugs: [network]
122+ aliases: [tpm_resetdalock]
123 clear:
124 command: sbin/tpm_clear
125 plugs: [network]
126+ aliases: [tpm_clear]
127 nvinfo:
128 command: sbin/tpm_nvinfo
129 plugs: [network]
130+ aliases: [tpm_nvinfo]
131 nvrelease:
132 command: sbin/tpm_nvrelease
133 plugs: [network]
134+ aliases: [tpm_nvrelease]
135 restrictsrk:
136 command: sbin/tpm_restrictsrk
137 plugs: [network]
138+ aliases: [tpm_restrictsrk]
139 setclearable:
140 command: sbin/tpm_setclearable
141 plugs: [network]
142+ aliases: [tpm_setclearable]
143 setoperatorauth:
144 command: sbin/tpm_setoperatorauth
145 plugs: [network]
146+ aliases: [tpm_setoperatorauth]
147 setpresence:
148 command: sbin/tpm_setpresence
149 plugs: [network]
150+ aliases: [tpm_setpresence]
151 createek:
152 command: sbin/tpm_createek
153 plugs: [network]
154+ aliases: [tpm_createek]
155 nvdefine:
156 command: sbin/tpm_nvdefine
157 plugs: [network]
158+ aliases: [tpm_nvdefine]
159 nvread:
160 command: sbin/tpm_nvread
161 plugs: [network]
162+ aliases: [tpm_nvread]
163 nvwrite:
164 command: sbin/tpm_nvwrite
165 plugs: [network]
166- restictpubek:
167+ aliases: [tpm_nvwrite]
168+ restrictpubek:
169 command: sbin/tpm_restrictpubek
170 plugs: [network]
171+ aliases: [tpm_restrictpubek]
172 revokeek:
173 command: sbin/tpm_revokeek
174 plugs: [network]
175+ aliases: [tpm_revokeek]
176 setownable:
177 command: sbin/tpm_setownable
178 plugs: [network]
179+ aliases: [tpm_setownable]
180
181 parts:
182 common:
183diff --git a/spread.yaml b/spread.yaml
184new file mode 100644
185index 0000000..a918fc4
186--- /dev/null
187+++ b/spread.yaml
188@@ -0,0 +1,53 @@
189+#
190+# Copyright (C) 2017 Canonical Ltd
191+#
192+# This program is free software: you can redistribute it and/or modify
193+# it under the terms of the GNU General Public License version 3 as
194+# published by the Free Software Foundation.
195+#
196+# This program is distributed in the hope that it will be useful,
197+# but WITHOUT ANY WARRANTY; without even the implied warranty of
198+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
199+# GNU General Public License for more details.
200+#
201+# You should have received a copy of the GNU General Public License
202+# along with this program. If not, see <http://www.gnu.org/licenses/>.
203+
204+
205+project: tpm
206+
207+environment:
208+ PROJECT_PATH: /home/tpm
209+ TESTSLIB: $PROJECT_PATH/tests/lib
210+ SNAP_NAME: tpm
211+ SNAP_ARCH: amd64
212+ # Allow the host to pass the channel to use for the test run
213+ SNAP_CHANNEL: $(HOST:echo $SNAP_CHANNEL)
214+ SNAP_AUTOCONNECT_CORE_PLUGS: network network-bind tpm
215+ SNAP_AUTO_ALIASES: tpm_version tpm_selftest tpm_takeownership tpm_setenable tpm_setactive tpm_getpubek tpm_changeownerauth tpm_resetdalock tpm_clear tpm_nvinfo tpm_nvrelease tpm_restrictsrk tpm_setclearable tpm_setoperatorauth tpm_setpresence tpm_createek tpm_nvdefine tpm_nvread tpm_nvwrite tpm_restrictpubek tpm_revokeek tpm_setownable
216+
217+backends:
218+ qemu:
219+ systems:
220+ - ubuntu-core-16:
221+ username: test
222+ password: test
223+
224+# Put this somewhere where we have read-write access
225+path: /home/tpm
226+
227+exclude:
228+ - .git
229+
230+prepare: |
231+ . $TESTSLIB/prepare-all.sh
232+
233+suites:
234+ tests/main/:
235+ summary: Install tests for tpm
236+ systems:
237+ - ubuntu-core-16
238+ prepare: |
239+ . $TESTSLIB/prepare.sh
240+ restore-each: |
241+ . $TESTSLIB/restore-each.sh
242diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh
243new file mode 100644
244index 0000000..2e77675
245--- /dev/null
246+++ b/tests/lib/prepare-all.sh
247@@ -0,0 +1,25 @@
248+#!/bin/bash
249+
250+# We don't have to build a snap when we should use one from a
251+# channel
252+if [ -n "$SNAP_CHANNEL" ] ; then
253+ exit 0
254+fi
255+
256+# Setup classic snap and build the tpm snap in there
257+snap install --devmode --beta classic
258+cat <<-EOF > /home/test/build-snap.sh
259+#!/bin/sh
260+set -ex
261+apt update
262+apt install -y --force-yes snapcraft
263+cd ${PROJECT_PATH}
264+snapcraft clean
265+snapcraft
266+EOF
267+chmod +x /home/test/build-snap.sh
268+sudo classic /home/test/build-snap.sh
269+snap remove classic
270+
271+# Make sure we have a snap build
272+test -e ${PROJECT_PATH}/${SNAP_NAME}_*_${SNAP_ARCH}.snap
273diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh
274new file mode 100644
275index 0000000..e14a9b2
276--- /dev/null
277+++ b/tests/lib/prepare.sh
278@@ -0,0 +1,37 @@
279+#!/bin/bash
280+
281+. $TESTSLIB/utilities.sh
282+
283+echo "Wait for firstboot change to be ready"
284+while ! snap changes | grep -q "Done"; do
285+ snap changes || true
286+ snap change 1 || true
287+ sleep 1
288+done
289+
290+echo "Ensure fundamental snaps are still present"
291+. $TESTSLIB/snap-names.sh
292+for name in $gadget_name $kernel_name $core_name; do
293+ if ! snap list | grep -q $name ; then
294+ echo "Not all fundamental snaps are available, all-snap image not valid"
295+ echo "Currently installed snaps:"
296+ snap list
297+ exit 1
298+ fi
299+done
300+
301+echo "Kernel has a store revision"
302+snap list | grep ^${kernel_name} | grep -E " [0-9]+\s+canonical"
303+
304+install_snap_under_test
305+
306+# Snapshot of the current snapd state for a later restore
307+if [ ! -f $SPREAD_PATH/snapd-state.tar.gz ] ; then
308+ systemctl stop snapd.service snapd.socket
309+ tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd
310+ systemctl start snapd.socket
311+fi
312+
313+# For debugging dump all snaps and connected slots/plugs
314+snap list
315+snap interfaces
316diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
317new file mode 100644
318index 0000000..f15af2f
319--- /dev/null
320+++ b/tests/lib/restore-each.sh
321@@ -0,0 +1,22 @@
322+#!/bin/bash
323+
324+. $TESTSLIB/snap-names.sh
325+
326+# Remove all snaps not being the core, gadget, kernel or snap we're testing
327+for snap in /snap/*; do
328+ snap="${snap:6}"
329+ case "$snap" in
330+ "bin" | "$gadget_name" | "$kernel_name" | "$core_name" | "$SNAP_NAME" )
331+ ;;
332+ *)
333+ snap remove "$snap"
334+ ;;
335+ esac
336+done
337+
338+# Ensure we have the same state for snapd as we had before
339+systemctl stop snapd.service snapd.socket
340+rm -rf /var/lib/snapd/*
341+$(cd / && tar xzf $SPREAD_PATH/snapd-state.tar.gz)
342+rm -rf /root/.snap
343+systemctl start snapd.service snapd.socket
344diff --git a/tests/lib/snap-names.sh b/tests/lib/snap-names.sh
345new file mode 100644
346index 0000000..f15b09a
347--- /dev/null
348+++ b/tests/lib/snap-names.sh
349@@ -0,0 +1,7 @@
350+#!/bin/bash
351+gadget_name=$(snap list | sed -n 's/^\(pc\|pi[23]\|dragonboard\) .*/\1/p')
352+kernel_name=$gadget_name-kernel
353+core_name=$(snap list | awk '/^(ubuntu-)?core / {print $1; exit}')
354+if [ "$kernel_name" = "pi3-kernel" ] ; then
355+ kernel_name=pi2-kernel
356+fi
357diff --git a/tests/lib/utilities.sh b/tests/lib/utilities.sh
358new file mode 100644
359index 0000000..a9c015a
360--- /dev/null
361+++ b/tests/lib/utilities.sh
362@@ -0,0 +1,39 @@
363+#!/bin/sh
364+
365+wait_for_systemd_service() {
366+ while ! systemctl status $1 ; do
367+ sleep 1
368+ done
369+ sleep 1
370+}
371+
372+wait_for_systemd_service_exit() {
373+ while systemctl status $1 ; do
374+ sleep 1
375+ done
376+ sleep 1
377+}
378+
379+install_snap_under_test() {
380+ # If we don't install the snap here we get a system
381+ # without any network connectivity after reboot.
382+ if [ -n "$SNAP_CHANNEL" ] ; then
383+ # Don't reinstall if we have it installed already
384+ if ! snap list | grep $SNAP_NAME ; then
385+ snap install --$SNAP_CHANNEL $SNAP_NAME
386+ fi
387+ else
388+ # Install prebuilt snap
389+ snap install --dangerous ${PROJECT_PATH}/${SNAP_NAME}_*_${SNAP_ARCH}.snap
390+ # As we have a snap which we build locally it's unasserted and therefore
391+ # we don't have any snap-declarations in place and need to manually
392+ # connect all plugs.
393+ for plug in $SNAP_AUTOCONNECT_CORE_PLUGS ; do
394+ snap connect tpm:$plug core
395+ done
396+ # Setup all necessary aliases
397+ for alias in $SNAP_AUTO_ALIASES ; do
398+ snap alias $SNAP_NAME $alias
399+ done
400+ fi
401+}
402diff --git a/tests/main/installation/task.yaml b/tests/main/installation/task.yaml
403new file mode 100644
404index 0000000..b414ae7
405--- /dev/null
406+++ b/tests/main/installation/task.yaml
407@@ -0,0 +1,31 @@
408+summary: Test tpm snap installation was successful
409+
410+execute: |
411+ # Ensure all necessary plugs/slots are connected
412+ snap interfaces | grep -Pzq ":tpm +tpm"
413+ snap interfaces | grep -Pzq ":network +tpm"
414+ snap interfaces | grep -Pzq ":network-bind +tpm"
415+
416+ # Verify aliases are set up
417+ test -x /snap/bin/tpm_version
418+ test -x /snap/bin/tpm_selftest
419+ test -x /snap/bin/tpm_takeownership
420+ test -x /snap/bin/tpm_setenable
421+ test -x /snap/bin/tpm_setactive
422+ test -x /snap/bin/tpm_getpubek
423+ test -x /snap/bin/tpm_changeownerauth
424+ test -x /snap/bin/tpm_resetdalock
425+ test -x /snap/bin/tpm_clear
426+ test -x /snap/bin/tpm_nvinfo
427+ test -x /snap/bin/tpm_nvrelease
428+ test -x /snap/bin/tpm_restrictsrk
429+ test -x /snap/bin/tpm_setclearable
430+ test -x /snap/bin/tpm_setoperatorauth
431+ test -x /snap/bin/tpm_setpresence
432+ test -x /snap/bin/tpm_createek
433+ test -x /snap/bin/tpm_nvdefine
434+ test -x /snap/bin/tpm_nvread
435+ test -x /snap/bin/tpm_nvwrite
436+ test -x /snap/bin/tpm_restrictpubek
437+ test -x /snap/bin/tpm_revokeek
438+ test -x /snap/bin/tpm_setownable

Subscribers

People subscribed via source and target branches

to all changes: