Merge ~rodsmith/plainbox-provider-checkbox:add-iso-boot-test into plainbox-provider-checkbox:master

Proposed by Rod Smith
Status: Needs review
Proposed branch: ~rodsmith/plainbox-provider-checkbox:add-iso-boot-test
Merge into: plainbox-provider-checkbox:master
Diff against target: 252 lines (+148/-76)
3 files modified
bin/install-method-check.sh (+139/-0)
dev/null (+0/-75)
units/miscellanea/jobs.pxu (+9/-1)
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+419470@code.launchpad.net

Commit message

Add: Test that system was installed from Subiquity ISO image

Description of the change

Renames maas-version-check.sh to install-method-check.sh and expands that script to test either of two cases:

* That the server was installed via MAAS and the MAAS version is known
* That the server was installed via Subiquity/an ISO image

The same conditions can be used to test either case; it's just their outcomes that must differ.

For the first case, the results should be identical to the old maas-version-check.sh script. Here's a submission that demonstrates this:

* https://certification.canonical.com/hardware/201006-5798/submission/259147/
  * https://certification.canonical.com/hardware/201006-5798/submission/259147/test/58324/result/25018913/

For the second case, a new launcher is required (MR to be submitted shortly). Passing (installed via ISO image on USB flash drive) and failing (installed via MAAS) submissions are:

* https://certification.canonical.com/hardware/201508-19150/submission/259144/
  * https://certification.canonical.com/hardware/201508-19150/submission/259144/test/157430/result/25018664/

* https://certification.canonical.com/hardware/201006-5798/submission/259146/
  * https://certification.canonical.com/hardware/201006-5798/submission/259146/test/157430/result/25018901/

This MR should be merged BEFORE the companion MR to plainbox-provider-certification-server.

To post a comment you must log in.
Revision history for this message
Rod Smith (rodsmith) wrote :
Revision history for this message
Jeff Lane  (bladernr) wrote :

Just some nitpics and one slightly more important suggestion inline (that's still a nitpick about final output).

Revision history for this message
Rod Smith (rodsmith) wrote :

I'm afraid that git blew up in my face and the documentation I found online failed to help, so I've resubmitted this MR, with the changes noted inline below:

https://code.launchpad.net/~rodsmith/plainbox-provider-checkbox/+git/plainbox-provider-checkbox/+merge/419489

(I had several failures of various types along the way. I suspect that Launchpad is overloaded in the week leading up to 22.04's release.)

Unmerged commits

cb873e6... by Rod Smith

Add: Test that system was installed from Subiquity ISO image

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/install-method-check.sh b/bin/install-method-check.sh
2new file mode 100755
3index 0000000..cffe8a7
4--- /dev/null
5+++ b/bin/install-method-check.sh
6@@ -0,0 +1,139 @@
7+#!/bin/bash
8+
9+# Copyright (C) 2012-2022 Canonical Ltd.
10+
11+# Authors
12+# Jeff Lane <jeff@ubuntu.com>
13+# Rod Smith <rod.smith@canonical.com>
14+
15+# This program is free software: you can redistribute it and/or modify
16+# it under the terms of the GNU General Public License version 3,
17+# as published by the Free Software Foundation.
18+
19+# This program is distributed in the hope that it will be useful,
20+# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+# GNU General Public License for more details.
23+
24+# You should have received a copy of the GNU General Public License
25+# along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
27+MAAS_FILE="/etc/installed-by-maas"
28+DATASOURCE_FILE="/var/lib/cloud/instance/datasource"
29+INSTALL_DATASOURCE=""
30+SUBIQUITY_LOG_FILE1="/var/log/installer/subiquity-info.log" # Observed on 20.04
31+SUBIQUITY_LOG_FILE2="/var/log/installer/subiquity-server-info.log" # Observed on 22.04
32+CONFIRM_INSTALL_TYPE="maas" # or "subiquity", maybe others in future
33+RETVAL="0"
34+
35+get_params() {
36+ # Default to equivalent of --verify-maas-install; the option is
37+ # provided for clarity in calling script.
38+ while [[ $# -gt 0 ]]; do
39+ case $1 in
40+ --verify-maas-install|-m)
41+ CONFIRM_INSTALL_TYPE="maas" # should already be set
42+ ;;
43+ --verify-iso-install|-i)
44+ CONFIRM_INSTALL_TYPE="subiquity"
45+ ;;
46+ *) echo "Usage: $0 [ -m, --verify-maas-install ] | [ -i, --verify-iso-install ]"
47+ ;;
48+ esac
49+ shift
50+ done
51+ INSTALL_DATASOURCE_FOUND=0 # Should be found for both MAAS & subiquity
52+ MAAS_IP_FOUND=0 # Should be found for MAAS but not subiquity
53+ MAAS_VERSION_FOUND=0 # Should be found for MAAS but not subiquity
54+ SUBIQUITY_LOG_FOUND=0 # Should be found for subiquity but not MAAS
55+}
56+
57+# Context-sensitive echo() function; prints the message only if the program
58+# is launched to confirm a MAAS installation
59+conditional_print() {
60+ if [[ "$CONFIRM_INSTALL_TYPE" == "$2" ]] ; then
61+ echo "$1"
62+ fi
63+}
64+
65+# Find the installation data source, as recorded in cloud installer files.
66+# This should be present for both MAAS and subiquity installs.
67+get_install_datasource() {
68+ # Is the file there?
69+ if [ -s $DATASOURCE_FILE ]; then
70+ INSTALL_DATASOURCE=$(cut -d "[" -f 2 $DATASOURCE_FILE | cut -d "]" -f 1)
71+ echo "Installation data source is $INSTALL_DATASOURCE"
72+ INSTALL_DATASOURCE_FOUND=1
73+ else
74+ echo "ERROR: The installation data source file ($DATASOURCE_FILE)"
75+ echo "cannot be found."
76+ fi
77+}
78+
79+# Verify that the $INSTALL_DATASOURCE points to a valid IP address.
80+# Note: Function assumes that $INSTALL_DATASOURCE is already set, as is
81+# done by the get_install_datasource() function.
82+verify_maas_ip() {
83+ if [[ $INSTALL_DATASOURCE_FOUND == 1 ]]; then
84+ MAAS_HOSTNAME=$(echo "$INSTALL_DATASOURCE" | cut -d "/" -f 3 | cut -d ":" -f 1)
85+ HOST_OUTPUT=$(host "$MAAS_HOSTNAME" | grep "has address")
86+ status=$?
87+ if [[ $status -eq 0 ]]; then
88+ MAAS_IP=$(echo "$HOST_OUTPUT" | cut -d " " -f 4)
89+ conditional_print "MAAS server's IP address is $MAAS_IP" "maas"
90+ conditional_print "ERROR: MAAS server's IP address is $MAAS_IP" "subiquity"
91+ MAAS_IP_FOUND=1
92+ else
93+ conditional_print "ERROR: Unable to determine MAAS server's IP address" "maas"
94+ fi
95+ fi
96+}
97+
98+# Pull the MAAS version information from a file left here by the
99+# Server Certification pre-seed file
100+get_maas_version() {
101+ # Is the file there?
102+ if [ -s $MAAS_FILE ]; then
103+ maas_version=$(cat $MAAS_FILE)
104+ conditional_print "MAAS version is $maas_version" "maas"
105+ conditional_print "ERROR: Server Certification MAAS version file found; MAAS version is $maas_version" "subiquity"
106+ MAAS_VERSION_FOUND=1
107+ else
108+ conditional_print "ERROR: The MAAS version cannot be determined" "maas"
109+ fi
110+}
111+
112+find_subiquity_log() {
113+ if [[ -f "$SUBIQUITY_LOG_FILE1" || -f "$SUBIQUITY_LOG_FILE2" ]]; then
114+ conditional_print "ERROR: Subiquity log file found" "maas"
115+ conditional_print "subiquity log file found" "subiquity"
116+ SUBIQUITY_LOG_FOUND=1
117+ else
118+ conditional_print "ERROR: Subiquity log file not found" "subiquity"
119+ fi
120+}
121+
122+#######################
123+#
124+# Main program begins here....
125+#
126+#######################
127+
128+get_params "$@"
129+
130+# Check for various installation signatures....
131+get_install_datasource
132+verify_maas_ip
133+get_maas_version
134+find_subiquity_log
135+
136+MAAS_FOUND=$((INSTALL_DATASOURCE_FOUND && MAAS_IP_FOUND && MAAS_VERSION_FOUND))
137+SUBIQUITY_FOUND=$((INSTALL_DATASOURCE_FOUND && SUBIQUITY_LOG_FOUND))
138+
139+if [[ $CONFIRM_INSTALL_TYPE == "maas" ]] ; then
140+ RETVAL=$((! MAAS_FOUND)) || SUBIQUITY_FOUND
141+elif [[ $CONFIRM_INSTALL_TYPE == "subiquity" ]] ; then
142+ RETVAL=$((! SUBIQUITY_FOUND)) || MAAS_FOUND
143+fi
144+
145+exit $RETVAL
146diff --git a/bin/maas-version-check.sh b/bin/maas-version-check.sh
147deleted file mode 100755
148index 7d97f0b..0000000
149--- a/bin/maas-version-check.sh
150+++ /dev/null
151@@ -1,75 +0,0 @@
152-#!/bin/bash
153-
154-# Copyright (C) 2012-2022 Canonical Ltd.
155-
156-# Authors
157-# Jeff Lane <jeff@ubuntu.com>
158-# Rod Smith <rod.smith@canonical.com>
159-
160-# This program is free software: you can redistribute it and/or modify
161-# it under the terms of the GNU General Public License version 3,
162-# as published by the Free Software Foundation.
163-
164-# This program is distributed in the hope that it will be useful,
165-# but WITHOUT ANY WARRANTY; without even the implied warranty of
166-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167-# GNU General Public License for more details.
168-
169-# You should have received a copy of the GNU General Public License
170-# along with this program. If not, see <http://www.gnu.org/licenses/>.
171-
172-MAAS_FILE="/etc/installed-by-maas"
173-DATASOURCE_FILE="/var/lib/cloud/instance/datasource"
174-MAAS_DATASOURCE=""
175-RETVAL="0"
176-
177-# Find the MAAS data source, as recorded in cloud installer files
178-get_maas_datasource() {
179- # Is the file there?
180- if [ -s $DATASOURCE_FILE ]; then
181- MAAS_DATASOURCE=$(cut -d "[" -f 2 $DATASOURCE_FILE | cut -d "]" -f 1)
182- echo "MAAS data source is $MAAS_DATASOURCE"
183- else
184- echo "ERROR: This system does not appear to have been installed by MAAS"
185- echo "ERROR: " "$(ls -l $DATASOURCE_FILE 2>&1)"
186- RETVAL="1"
187- fi
188-}
189-
190-# Verify that the $MAAS_DATASOURCE points to a valid IP address.
191-# Note: Function assumes that $MAAS_DATASOURCE is already set, as is
192-# done by the get_maas_datasource() function.
193-verify_maas_ip() {
194- if [[ $RETVAL == 0 ]]; then
195- MAAS_HOSTNAME=$(echo "$MAAS_DATASOURCE" | cut -d "/" -f 3 | cut -d ":" -f 1)
196- HOST_OUTPUT=$(host "$MAAS_HOSTNAME" | grep "has address")
197- status=$?
198- if [[ $status -eq 0 ]]; then
199- MAAS_IP=$(echo "$HOST_OUTPUT" | cut -d " " -f 4)
200- echo "MAAS server's IP address is $MAAS_IP"
201- else
202- echo "ERROR: Unable to determine MAAS server's IP address"
203- RETVAL=1
204- fi
205- fi
206-}
207-
208-# Pull the MAAS version information from a file left here by the
209-# Server Certification pre-seed file
210-get_maas_version() {
211- # Is the file there?
212- if [ -s $MAAS_FILE ]; then
213- maas_version=$(cat $MAAS_FILE)
214- echo "MAAS version is $maas_version"
215- else
216- echo "ERROR: The MAAS version cannot be determined"
217- echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)"
218- RETVAL="1"
219- fi
220-}
221-
222-get_maas_datasource
223-verify_maas_ip
224-get_maas_version
225-
226-exit $RETVAL
227diff --git a/units/miscellanea/jobs.pxu b/units/miscellanea/jobs.pxu
228index 785eebe..1168391 100644
229--- a/units/miscellanea/jobs.pxu
230+++ b/units/miscellanea/jobs.pxu
231@@ -396,12 +396,20 @@ plugin: shell
232 category_id: com.canonical.plainbox::miscellanea
233 estimated_duration: 0.1
234 id: miscellanea/get_maas_version
235-command: maas-version-check.sh
236+command: install-method-check.sh --verify-maas-install
237 _description: If system was installed via MAAS from a cert server, the MAAS version used should be contained in /etc/installed-by-maas
238 _summary: Verify MAAS version used to deploy the SUT
239
240 plugin: shell
241 category_id: com.canonical.plainbox::miscellanea
242+estimated_duration: 0.1
243+id: miscellanea/test_iso_install
244+command: install-method-check.sh --verify-iso-install
245+_description: Test that the system was installed via a Subiquity ISO image
246+_summary: Test that the system was installed via a Subiquity ISO image
247+
248+plugin: shell
249+category_id: com.canonical.plainbox::miscellanea
250 estimated_duration: 30.0
251 id: miscellanea/get_make_and_model
252 user: root

Subscribers

People subscribed via source and target branches