Merge lp:~canonical-platform-qa/ubuntu-ota-tests/remove-si-autopkgtest-workarounds into lp:ubuntu-ota-tests

Proposed by Federico Gimenez
Status: Needs review
Proposed branch: lp:~canonical-platform-qa/ubuntu-ota-tests/remove-si-autopkgtest-workarounds
Merge into: lp:ubuntu-ota-tests
Diff against target: 489 lines (+13/-395)
5 files modified
README.rst (+0/-1)
adb-reboot-to-recovery (+0/-344)
ubuntu_ota_tests/command_line.py (+1/-26)
ubuntu_ota_tests/hooks.py (+5/-23)
ubuntu_ota_tests/upgrade.py (+7/-1)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-ota-tests/remove-si-autopkgtest-workarounds
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
Review via email: mp+260060@code.launchpad.net

Commit message

Removed workarounds for si and autopkgtest

Description of the change

After the release of systemimage 3.0 we can remove the code that installed it from a ppa and the workaround for fixing the problem with the different locations used for reading and writting the si configuration.

With the addition of the /tmp/autopkgtest-reboot-prepare command in autopkgtest we don't need anymore the forked ssh adb script which added a reboot option, nor setting the 'recovery' marker to be used by this option. Now we can just save the status of the test with the new command and reboot to recovery from the test itself.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

\o/ Thanks Frederico!

Revision history for this message
Vincent Ladeuil (vila) wrote :

Nice cleanup \o/

review: Approve

Unmerged revisions

18. By Federico Gimenez

Removed workarounds for si and autopkgtest

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.rst'
2--- README.rst 2015-03-26 16:12:42 +0000
3+++ README.rst 2015-05-25 15:50:14 +0000
4@@ -22,7 +22,6 @@
5 ::
6 $ mkdir /tmp/ota_tests_results
7 $ ./run-ota-tests --wifi-ssid {wifi-ssid} --wifi-password {wifi-password} \
8- --ssh-overwrite-script ./adb-reboot-to-recovery \
9 --output_dir /tmp/ota_tests_results
10
11 To see the full list of options and more information about each one, run::
12
13=== removed file 'adb-reboot-to-recovery'
14--- adb-reboot-to-recovery 2015-03-30 11:52:13 +0000
15+++ adb-reboot-to-recovery 1970-01-01 00:00:00 +0000
16@@ -1,344 +0,0 @@
17-#!/bin/sh
18-
19-# adb.ssh is part of autopkgtest
20-# autopkgtest is a tool for testing Debian binary packages
21-#
22-# This script sets up an ssh connection to an adb host. If that adb host is an
23-# Ubuntu Touch system, it also does some extra configuration like disabling the
24-# screen timeout and allowing Autopilot to introspect running apps.
25-#
26-# Options:
27-# -r/--reset Do a factory reset of the device before running the test
28-# (Available on Ubuntu Phone only; disabled for now as it does not
29-# re-enable developer mode)
30-# -b/--reboot Reboot the device before running the test
31-# -s serial | --serial=serial
32-# Serial ID of the device as returned by adb devices -l when
33-# several devices are connected to the same host.
34-# -p PASSWORD | --password PASSWORD
35-# sudo password; if not given, tries "phablet" and "0000"; if
36-# neither works, tests cannot run as root
37-#
38-# autopkgtest is Copyright (C) 2006-2014 Canonical Ltd.
39-#
40-# Author: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
41-#
42-# This program is free software; you can redistribute it and/or modify
43-# it under the terms of the GNU General Public License as published by
44-# the Free Software Foundation; either version 2 of the License, or
45-# (at your option) any later version.
46-#
47-# This program is distributed in the hope that it will be useful,
48-# but WITHOUT ANY WARRANTY; without even the implied warranty of
49-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50-# GNU General Public License for more details.
51-#
52-# You should have received a copy of the GNU General Public License
53-# along with this program; if not, write to the Free Software
54-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
55-#
56-# See the file CREDITS for a full list of credits information (often
57-# installed as /usr/share/doc/autopkgtest/CREDITS).
58-set -e
59-
60-SSH_USER=phablet
61-SUDO_PASSWORD=
62-CAPABILITIES='isolation-machine reboot'
63-
64-# allow using lp:phablet-tools from a checkout
65-if [ -n "$PHABLET_TOOLS_PATH" ]; then
66- export PATH="$PHABLET_TOOLS_PATH:$PATH"
67-fi
68-
69-# argument parsing
70-ADBOPTS=""
71-RESET=""
72-REBOOT=""
73-IDENTITY=
74-
75-open() {
76- # Setup a connection to an adb device
77- # - Configure ssh connection
78- # - optionally mount device RW
79- wait_booted
80-
81- if [ -n "$REBOOT" ]; then
82- adb $ADBOPTS reboot
83- wait_booted
84- fi
85-
86- # special setup on Ubuntu images
87- if [ -n "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
88- if [ -n "$RESET" ]; then
89- revert
90- else
91- ubuntu_prepare_config
92- ubuntu_prepare_for_testing
93- fi
94- #CAPABILITIES="$CAPABILITIES revert"
95- fi
96-
97-
98- # Configure SSH
99- adb $ADBOPTS shell 'gdbus call -y -d com.canonical.PropertyService -o /com/canonical/PropertyService -m com.canonical.PropertyService.SetProperty ssh true >/dev/null'
100- for port in `seq 2222 2299`; do
101- adb $ADBOPTS forward tcp:$port tcp:22 && break
102- done
103-
104- # Purge the device host key so that SSH doesn't print a scary warning about it
105- # (it changes every time the device is reflashed and this is expected)
106- ssh-keygen -f ~/.ssh/known_hosts -R [localhost]:$PORT 2>/dev/null || true
107-
108- # Copy your ssh id down to the device so you never need a password.
109- IDENTITY=$HOME/.ssh/id_rsa
110- if [ ! -e $IDENTITY ]; then
111- IDENTITY=$HOME/.ssh/id_autopkgtest
112- if [ ! -e $IDENTITY ]; then
113- echo "No default ssh key, generating $IDENTITY" >&2
114- ssh-keygen -q -t ed25519 -f $IDENTITY -N ''
115- fi
116- fi
117- script=$(mktemp /tmp/$(basename $0).XXXXXX)
118- adb $ADBOPTS push ${IDENTITY}.pub /home/$SSH_USER/.ssh/authorized_keys
119- cat>$script <<EOF
120-# Set right permissions
121-chown $SSH_USER:$SSH_USER -R /home/$SSH_USER/.ssh/
122-chmod 700 /home/$SSH_USER/.ssh
123-chmod 600 /home/$SSH_USER/.ssh/authorized_keys
124-EOF
125-
126- adb $ADBOPTS push $script /tmp
127- adb $ADBOPTS shell sh $script
128- adb $ADBOPTS shell rm $script
129- rm $script
130-
131- # verify that we can connect through ssh
132- local ssh_cmd="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $IDENTITY -p $port -l $SSH_USER localhost"
133- for retry in `seq 10`; do
134- if $ssh_cmd true; then
135- can_ssh=1
136- break
137- fi
138- sleep 2
139- done
140- if [ -z "$can_ssh" ]; then
141- echo "ssh setup failed, cannot connect" >&2
142- exit 1
143- fi
144-
145- # try to auto-detect sudo password from common ones used by CI
146- for p in phablet 0000; do
147- if $ssh_cmd "echo $p | sudo -p '' -S true" >/dev/null 2>&1; then
148- SUDO_PASSWORD="$p"
149- break
150- fi
151- done
152-
153- # ensure that adb comes back after reboot
154- if [ -n "$SUDO_PASSWORD" ]; then
155- if ! $ssh_cmd "echo \"$SUDO_PASSWORD\" | sudo -p '' -S touch /userdata/.adb_onlock"; then
156- echo "WARNING: Could not create /userdata/.adb_onlock, reboot will not work properly" >&2
157- fi
158- fi
159-
160- # print info for adt-virt-ssh
161- cat<<EOF
162-login=$SSH_USER
163-hostname=localhost
164-port=$port
165-capabilities=$CAPABILITIES
166-identity=$IDENTITY
167-extraopts=--no-reset --fwd-port=$port
168-EOF
169- if [ -n "$SUDO_PASSWORD" ]; then
170- echo "password=$SUDO_PASSWORD"
171- fi
172-}
173-
174-wait_booted() {
175- echo "Waiting for device ADB to appear..." >&2
176- if ! timeout 300 adb $ADBOPTS wait-for-device >/dev/null; then
177- echo "ERROR: Timed out waiting for adb device" >&2
178- fi
179-}
180-
181-# configure Ubuntu device for testing
182-ubuntu_prepare_config() {
183- if [ -z "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
184- # not an Ubuntu phone
185- return
186- fi
187-
188- if ! type phablet-config >/dev/null 2>&1; then
189- echo "ERROR: phablet-config not found! Install phablet-tools package or" >&2
190- echo "bzr branch lp:phablet-tools and run with PHABLET_TOOLS_PATH=<checkout dir>" >&2
191- exit 1
192- fi
193-
194- echo "Configuring Ubuntu phone for testing..." >&2
195-
196- # disable first-time wizards; these fail due to adb instability from time
197- # to time, so retry
198- for retry in `seq 5`; do
199- if phablet-config $ADBOPTS welcome-wizard --disable >/dev/null; then
200- break
201- else
202- echo "Failed to disable welcome wizard, retrying (attempt $retry)..." >&2
203- sleep 1
204- fi
205- done
206- # this needs accounts-daemon running
207- adb $ADBOPTS shell 'while ! pidof accounts-daemon >/dev/null; do sleep 1; done'
208- for retry in `seq 5`; do
209- if phablet-config $ADBOPTS edges-intro --disable >/dev/null; then
210- break
211- else
212- echo "Failed to disable edges intro, retrying (attempt $retry)..." >&2
213- sleep 1
214- fi
215- done
216-
217- # kill an already running welcome wizard
218- adb $ADBOPTS shell 'kill `pidof system-settings-wizard` 2>/dev/null'
219-}
220-
221-# test run time setup for Ubuntu device
222-ubuntu_prepare_for_testing() {
223- if [ -z "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
224- # not an Ubuntu phone
225- return
226- fi
227-
228- echo "Preparing Ubuntu phone for running tests..." >&2
229-
230- echo "Waiting for desktop to boot" >&2
231- local timeout=$(($(date +%s) + 300))
232- while [ "$(date +%s)" -le $timeout ]; do
233- out=$(adb $ADBOPTS shell 'gdbus call --timeout 5 --session --dest com.canonical.UnityGreeter --object-path / --method org.freedesktop.DBus.Properties.Get com.canonical.UnityGreeter IsActive 2>/dev/null')
234- if [ -n "$out" ]; then
235- timeout=0
236- break
237- fi
238- sleep 5
239- done
240- if [ "$timeout" -gt 0 ]; then
241- echo "ERROR: timed out waiting for Unity greeter" >&2
242- exit 1
243- fi
244-
245- # disable screen dimming; ugly, but pretty much everything else hangs forever
246- adb $ADBOPTS shell "setsid powerd-cli display </dev/null >/dev/null 2>&1 & disown;
247- while ! pidof powerd-cli >/dev/null; do sleep 0.1; done"
248-
249- # unlock the greeter
250- adb $ADBOPTS shell "gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked" >/dev/null
251-}
252-
253-revert() {
254- # revert is only offered on Ubuntu images
255- echo "Performing factory reset, this will take a minute..." >&2
256-
257- # save current network connections
258- NETCONF=$(phablet-config $ADBOPTS network --read) || true:
259-
260- # do factory reset
261- adb $ADBOPTS shell 'gdbus call --system -d com.canonical.SystemImage -o /Service -m com.canonical.SystemImage.FactoryReset'
262- wait_booted
263- adb $ADBOPTS shell 'while ! pidof NetworkManager >/dev/null; do sleep 1; done'
264-
265- # restore network connections
266- if [ -n "$NETCONF" ]; then
267- phablet-config $ADBOPTS network --write "$NETCONF"
268- fi
269-
270- ubuntu_prepare_config
271- ubuntu_prepare_for_testing
272-}
273-
274-reboot() {
275- if [ -z "$FWD_PORT" ]; then
276- echo "ERROR: Must pass --fwd-port" >&2
277- exit 1
278- fi
279- BOOT_TARGET=$(adb pull /run/adt_reboot_target /dev/stdout) || BOOT_TARGET=""
280- adb $ADBOPTS reboot $BOOT_TARGET
281- wait_booted
282- adb $ADBOPTS forward tcp:$FWD_PORT tcp:22
283- adb $ADBOPTS shell "gdbus call -y -d com.canonical.PropertyService -o /com/canonical/PropertyService -m com.canonical.PropertyService.SetProperty ssh true >/dev/null"
284- ubuntu_prepare_for_testing
285-}
286-
287-cleanup() {
288- adb $ADBOPTS shell pkill powerd-cli
289-}
290-
291-
292-#
293-# main
294-#
295-
296-# argument parsing
297-SHORTOPTS="l:,p:,s:,w,r,b"
298-LONGOPTS="login:,password:,serial:,rw,apt-update,reset,reboot,no-reset,fwd-port:"
299-
300-TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
301-eval set -- "$TEMP"
302-
303-while true; do
304- case "$1" in
305- -l|--login)
306- SSH_USER=$2
307- shift 2;;
308- -p|--password)
309- SUDO_PASSWORD="$2"
310- shift 2;;
311- -s|--serial)
312- ADBOPTS="$ADBOPTS -s $2"
313- shift 2;;
314- -b|--reboot)
315- REBOOT="1"
316- shift;;
317- -r|--reset)
318- echo "--reset is currently broken as it does not restore PIN/developer mode. Use -b/--reboot instead." >&2
319- exit 1
320- RESET="1"
321- shift;;
322- # passed in "extraopts" so that --reset is only applied once, not
323- # in between tests that call "revert"
324- --no-reset)
325- RESET=""
326- shift;;
327- --fwd-port)
328- FWD_PORT="$2"
329- shift 2;;
330- --)
331- shift;
332- break;;
333- *)
334- echo "E: $(basename $0): Unsupported option $1" >&2
335- exit 1;;
336- esac
337-done
338-
339-if [ -z "$1" ]; then
340- echo "Needs to be called with command as first argument" >&2
341- exit 1
342-fi
343-
344-cmd=$(echo "$1"|tr [[:upper:]] [[:lower:]])
345-shift
346-
347-case $cmd in
348- open)
349- open;;
350- revert)
351- revert;;
352- reboot)
353- reboot;;
354- cleanup)
355- cleanup;;
356- *)
357- echo "invalid command $cmd" >&2
358- exit 1
359- ;;
360-esac
361
362=== modified file 'ubuntu_ota_tests/command_line.py'
363--- ubuntu_ota_tests/command_line.py 2015-03-26 16:43:28 +0000
364+++ ubuntu_ota_tests/command_line.py 2015-05-25 15:50:14 +0000
365@@ -171,9 +171,7 @@
366
367 virt_cmds = ['ssh', '-s', adt_script, '--', '-p', password]
368
369- si_tmp_commands = get_si_tmp_commands()
370-
371- return adt_run_cmds + si_tmp_commands + ['---'] + virt_cmds
372+ return adt_run_cmds + ['---'] + virt_cmds
373
374
375 def flash_device(revision, channel, password):
376@@ -290,26 +288,3 @@
377 help='Specific ssh virt script to run (i.e. adb-reboot-to-recovery)')
378
379 return main_args
380-
381-
382-def get_si_tmp_commands():
383- """Return adt-run--setup-commands options until si 3.0 is released.
384-
385- Ref. bug: https://bugs.launchpad.net/ubuntu-ota-tests/+bug/1436730
386- """
387- return [
388- '--setup-commands',
389- 'mount -o remount,rw /',
390- '--setup-commands',
391- 'apt-add-repository -y ppa:barry/systemimage',
392- '--setup-commands',
393- 'apt-get --no-list-cleanup update -o Dir::Etc::SourceList=/dev/null',
394- '--setup-commands',
395- 'if [ ! -d /etc/system-image/config.d ];'
396- 'then mkdir -p /etc/system-image/config.d && '
397- 'cd /etc/system-image && '
398- 'ln -sf ../client.ini config.d/00_default.ini && '
399- 'ln -sf ../channel.ini config.d/01_channel.ini; fi',
400- '--setup-commands',
401- 'sync; sleep 2; mount -o remount,ro /'
402- ]
403
404=== modified file 'ubuntu_ota_tests/hooks.py'
405--- ubuntu_ota_tests/hooks.py 2015-03-25 10:50:37 +0000
406+++ ubuntu_ota_tests/hooks.py 2015-05-25 15:50:14 +0000
407@@ -26,8 +26,6 @@
408 # si 2.5
409 from systemimage.reboot import BaseReboot as Base
410
411-from systemimage.config import config
412-
413 log = logging.getLogger('systemimage')
414
415
416@@ -39,35 +37,19 @@
417 def apply(self):
418 """Reboot the testbed to apply the upgrade.
419
420- This method does not execute the reboot, it tells adt-run that the
421- reboot is needed and adt executes it.
422+ This method tells adt-run that the system should enter recovery
423+ after the reboot and launches the reboot
424
425 """
426- self._set_adt_reboot_to_recovery_flag()
427 try:
428- # When running tests with adt-run, we can't just execute a reboot
429- # because it will break the communication with the host. This
430- # script tell adt-run that a reboot is required. The reboot is
431- # executed from the host, saving the state so that the test can
432- # continue when the testbed comes back.
433- autopkgtest_reboot_script = '/tmp/autopkgtest-reboot'
434- # The reboot mark will be set to the $ADT_REBOOT_MARK environment
435- # variable after the machine is rebooted. It can be used in tests
436- # to tell when the reboot happened.
437+ reboot_prepare_script = '/tmp/autopkgtest-reboot-prepare'
438 reboot_mark = 'rebooted'
439- subprocess.check_output([autopkgtest_reboot_script, reboot_mark])
440+ subprocess.check_output([reboot_prepare_script, reboot_mark])
441+ subprocess.check_output(['reboot', '-f', 'recovery'])
442 except subprocess.CalledProcessError as error:
443 log.exception('reboot exit status: {}'.format(error.returncode))
444 log.exception('reboot command output: {}'.format(error.output))
445 raise
446- # This code may or may not run. We're racing against the system
447- # reboot procedure.
448- config.dbus_service.Rebooting(True)
449
450 # si 2.5
451 reboot = apply
452-
453- def _set_adt_reboot_to_recovery_flag(self):
454- """Set a flag to tell adt that the reboot needs to go into recovery."""
455- with open('/run/adt_reboot_target', 'w') as reboot_target:
456- reboot_target.write('recovery')
457
458=== modified file 'ubuntu_ota_tests/upgrade.py'
459--- ubuntu_ota_tests/upgrade.py 2015-03-31 15:27:43 +0000
460+++ ubuntu_ota_tests/upgrade.py 2015-05-25 15:50:14 +0000
461@@ -17,6 +17,7 @@
462 #
463
464 import glob
465+import logging
466 import os
467 import subprocess
468
469@@ -29,6 +30,8 @@
470 services
471 )
472
473+log = logging.getLogger(__name__)
474+
475
476 def upgrade_with_system_image_cli():
477 command = 'system-image-cli -v -g'
478@@ -73,7 +76,10 @@
479 config_path = _get_system_image_config_dir()
480 default_path = '/etc/system-image/config.d'
481 for file in glob.glob('{path}/*.ini'.format(path=default_path)):
482- shutil.copy(file, config_path)
483+ try:
484+ shutil.copy(file, config_path)
485+ except FileNotFoundError:
486+ log.error("{} not found. Broken symlink?".format(file))
487
488
489 def _get_system_image_config_dir():

Subscribers

People subscribed via source and target branches

to all changes: