Merge lp:~canonical-platform-qa/ubuntu-ota-tests/upgrade into lp:ubuntu-ota-tests

Proposed by Leo Arias on 2015-03-03
Status: Superseded
Proposed branch: lp:~canonical-platform-qa/ubuntu-ota-tests/upgrade
Merge into: lp:ubuntu-ota-tests
Prerequisite: lp:~canonical-platform-qa/ubuntu-ota-tests/adding-initial-autopkgtesting
Diff against target: 600 lines (+546/-11)
7 files modified
adb-reboot-to-recovery (+337/-0)
debian/tests/control (+4/-1)
debian/tests/ota_basic (+29/-10)
debian/tests/ubuntu_ota_tests/__init__.py (+27/-0)
debian/tests/ubuntu_ota_tests/hooks.py (+42/-0)
debian/tests/ubuntu_ota_tests/services.py (+74/-0)
debian/tests/ubuntu_ota_tests/system.py (+33/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-ota-tests/upgrade
Reviewer Review Type Date Requested Status
Brendan Donegan (community) 2015-03-03 Needs Information on 2015-03-04
Review via email: mp+251646@code.launchpad.net

This proposal supersedes a proposal from 2015-03-03.

Description of the Change

Flash with:
ubuntu-device-flash --revision=-1 touch --developer-mode --password 0000 --channel="ubuntu-touch/devel-proposed" --wipe

The adb-reboot-to-recovery script is copied from /usr/share/autopkgtest/ssh-setup/adb, which only one line changed:

261 + adb $ADBOPTS reboot recovery

To post a comment you must log in.
Leo Arias (elopio) wrote : Posted in a previous version of this proposal

To give it a try, use something like:

elopio@tangamandapio76-desktop:~/workspace/canonical/ubuntu-ota-tests/experimeal/upgrade$ phablet-network
elopio@tangamandapio76-desktop:~/workspace/canonical/ubuntu-ota-tests/experimental/upgrade$ adt-run -d -B --unbuilt-tree=/home/elopio/workspace/canonical/ubuntu-ota-tests/experimental/upgrade --output-dir /tmp/output --- ssh -s /home/elopio/workspace/canonical/ubuntu-ota-tests/experimental/upgrade/adb-reboot-to-recovery

Leo Arias (elopio) wrote : Posted in a previous version of this proposal

After the reboot, I got:
adt-virt-ssh: WARNING: ssh connection failed. Retrying in 3 seconds...

If I phablet-shell in a different terminal, the test continues.
So we are missing a way to reset the ssh connection.

Leo Arias (elopio) wrote :

This makes it work, but I'm not quite sure if it is right.

=== modified file 'adb-reboot-to-recovery'
--- adb-reboot-to-recovery 2015-03-03 19:28:44 +0000
+++ adb-reboot-to-recovery 2015-03-03 20:10:08 +0000
@@ -256,7 +256,7 @@
     adb $ADBOPTS reboot recovery
     wait_booted
     adb $ADBOPTS forward tcp:$FWD_PORT tcp:22
- ubuntu_prepare_for_testing
+ open
 }

Brendan Donegan (brendan-donegan) wrote :

Do we definitely want to merge this? It doesn't implement what we want since we decided to use dbus to trigger the update, which we still need the scripts for, but I suppose it would be a good building block to start from. Any other opinions?

review: Needs Information
Federico Gimenez (fgimenez) wrote :

I'm getting this [1] at the end of the execution, otherwise seems to work fine

[1] http://paste.ubuntu.com/10526508/

Leo Arias (elopio) wrote :

No, please don't merge it. The system-image-cli it's easy to replace, but the adb-reboot-to-recovery is ugly. We need a better solution for that.

Brendan Donegan (brendan-donegan) wrote :

Ok, set to WIP to avoid confusion

5. By Leo Arias on 2015-03-03

Do the reboot only if the download workded.

6. By Leo Arias on 2015-03-05

Added a dbus call to enable ssh.

Leo Arias (elopio) wrote :

There was no need to call open again.
We just need to renable ssh with a dbus call. I pushed this version.

263 + adb $ADBOPTS shell 'gdbus call -y -d com.canonical.PropertyService -o /com/canonical/PropertyService -m com.canonical.PropertyService.SetProperty ssh true >/dev/null'

7. By Leo Arias on 2015-03-05

Merged with trunk.

8. By Leo Arias on 2015-03-09

Change cli to dbus.

Leo Arias (elopio) wrote :

In order to get the latest system-image-dbus version, run with:

adt-run -d -B --unbuilt-tree=. --output-dir /tmp/output --setup-commands "mount -o remount,rw /; apt-add-repository -y ppa:barry/systemimage; apt-get --no-list-cleanup update -o Dir::Etc::SourceList=/dev/null; sync; sleep 2; mount -o remount,ro /"--- ssh -s ./adb-reboot-to-recovery

9. By Leo Arias on 2015-03-09

Quickly fixed the apply script.

10. By Leo Arias on 2015-03-09

Merged with prerequisite.

11. By Leo Arias on 2015-03-09

Merged with prerequisite. Changed the script to python.

12. By Leo Arias on 2015-03-09

Reduced the try.

13. By Leo Arias on 2015-03-09

fixtures not needed yet.

14. By Leo Arias on 2015-03-10

Merged with prerequisite.

15. By Leo Arias on 2015-03-10

Move the test to the ota module.

16. By Leo Arias on 2015-03-10

Merged with parent.

17. By Leo Arias on 2015-03-10

Use the command.

18. By Leo Arias on 2015-03-10

Added the missing file.

19. By Leo Arias on 2015-03-10

Fixed the import order.

20. By Leo Arias on 2015-03-10

Fixed the reboot call.

21. By Leo Arias on 2015-03-10

Use cli and the current version for now.

22. By Leo Arias on 2015-03-10

Removed the dbus upgrade, not yet working.

23. By Leo Arias on 2015-03-10

Downgrade to the released version.

24. By Leo Arias on 2015-03-11

Removed the rebooting.

25. By Leo Arias on 2015-03-12

Cleaned the code.

26. By Leo Arias on 2015-03-12

Merged with trunk.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'adb-reboot-to-recovery'
2--- adb-reboot-to-recovery 1970-01-01 00:00:00 +0000
3+++ adb-reboot-to-recovery 2015-03-09 21:35:41 +0000
4@@ -0,0 +1,337 @@
5+#!/bin/sh
6+
7+# adb.ssh is part of autopkgtest
8+# autopkgtest is a tool for testing Debian binary packages
9+#
10+# This script sets up an ssh connection to an adb host. If that adb host is an
11+# Ubuntu Touch system, it also does some extra configuration like disabling the
12+# screen timeout and allowing Autopilot to introspect running apps.
13+#
14+# Options:
15+# -r/--reset Do a factory reset of the device before running the test
16+# (Available on Ubuntu Phone only; disabled for now as it does not
17+# re-enable developer mode)
18+# -b/--reboot Reboot the device before running the test
19+# -s serial | --serial=serial
20+# Serial ID of the device as returned by adb devices -l when
21+# several devices are connected to the same host.
22+# -p PASSWORD | --password PASSWORD
23+# sudo password; if not given, tries "phablet" and "0000"; if
24+# neither works, tests cannot run as root
25+#
26+# autopkgtest is Copyright (C) 2006-2014 Canonical Ltd.
27+#
28+# Author: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
29+#
30+# This program is free software; you can redistribute it and/or modify
31+# it under the terms of the GNU General Public License as published by
32+# the Free Software Foundation; either version 2 of the License, or
33+# (at your option) any later version.
34+#
35+# This program is distributed in the hope that it will be useful,
36+# but WITHOUT ANY WARRANTY; without even the implied warranty of
37+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+# GNU General Public License for more details.
39+#
40+# You should have received a copy of the GNU General Public License
41+# along with this program; if not, write to the Free Software
42+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
43+#
44+# See the file CREDITS for a full list of credits information (often
45+# installed as /usr/share/doc/autopkgtest/CREDITS).
46+set -e
47+
48+SSH_USER=phablet
49+SUDO_PASSWORD=
50+CAPABILITIES='isolation-machine reboot'
51+
52+# allow using lp:phablet-tools from a checkout
53+if [ -n "$PHABLET_TOOLS_PATH" ]; then
54+ export PATH="$PHABLET_TOOLS_PATH:$PATH"
55+fi
56+
57+# argument parsing
58+ADBOPTS=""
59+RESET=""
60+REBOOT=""
61+IDENTITY=
62+
63+open() {
64+ # Setup a connection to an adb device
65+ # - Configure ssh connection
66+ # - optionally mount device RW
67+ wait_booted
68+
69+ if [ -n "$REBOOT" ]; then
70+ adb $ADBOPTS reboot
71+ wait_booted
72+ fi
73+
74+ # special setup on Ubuntu images
75+ if [ -n "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
76+ if [ -n "$RESET" ]; then
77+ revert
78+ else
79+ ubuntu_prepare_config
80+ ubuntu_prepare_for_testing
81+ fi
82+ #CAPABILITIES="$CAPABILITIES revert"
83+ fi
84+
85+
86+ # Configure SSH
87+ adb $ADBOPTS shell 'gdbus call -y -d com.canonical.PropertyService -o /com/canonical/PropertyService -m com.canonical.PropertyService.SetProperty ssh true >/dev/null'
88+ for port in `seq 2222 2299`; do
89+ adb $ADBOPTS forward tcp:$port tcp:22 && break
90+ done
91+
92+ # Purge the device host key so that SSH doesn't print a scary warning about it
93+ # (it changes every time the device is reflashed and this is expected)
94+ ssh-keygen -f ~/.ssh/known_hosts -R [localhost]:$PORT 2>/dev/null || true
95+
96+ # Copy your ssh id down to the device so you never need a password.
97+ IDENTITY=$HOME/.ssh/id_rsa
98+ if [ ! -e $IDENTITY ]; then
99+ IDENTITY=$HOME/.ssh/id_autopkgtest
100+ if [ ! -e $IDENTITY ]; then
101+ echo "No default ssh key, generating $IDENTITY" >&2
102+ ssh-keygen -q -t ed25519 -f $IDENTITY -N ''
103+ fi
104+ fi
105+ script=$(mktemp /tmp/$(basename $0).XXXXXX)
106+ adb $ADBOPTS push ${IDENTITY}.pub /home/$SSH_USER/.ssh/authorized_keys
107+ cat>$script <<EOF
108+# Set right permissions
109+chown $SSH_USER:$SSH_USER -R /home/$SSH_USER/.ssh/
110+chmod 700 /home/$SSH_USER/.ssh
111+chmod 600 /home/$SSH_USER/.ssh/authorized_keys
112+EOF
113+
114+ adb $ADBOPTS push $script /tmp
115+ adb $ADBOPTS shell sh $script
116+ adb $ADBOPTS shell rm $script
117+ rm $script
118+
119+ # verify that we can connect through ssh
120+ local ssh_cmd="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $IDENTITY -p $port -l $SSH_USER localhost"
121+ for retry in `seq 10`; do
122+ if $ssh_cmd true; then
123+ can_ssh=1
124+ break
125+ fi
126+ sleep 2
127+ done
128+ if [ -z "$can_ssh" ]; then
129+ echo "ssh setup failed, cannot connect" >&2
130+ exit 1
131+ fi
132+
133+ # try to auto-detect sudo password from common ones used by CI
134+ for p in phablet 0000; do
135+ if $ssh_cmd "echo $p | sudo -S true" >/dev/null 2>&1; then
136+ SUDO_PASSWORD="$p"
137+ break
138+ fi
139+ done
140+
141+ # print info for adt-virt-ssh
142+ cat<<EOF
143+login=$SSH_USER
144+hostname=localhost
145+port=$port
146+capabilities=$CAPABILITIES
147+identity=$IDENTITY
148+extraopts=--no-reset --fwd-port=$port
149+EOF
150+ if [ -n "$SUDO_PASSWORD" ]; then
151+ echo "password=$SUDO_PASSWORD"
152+ fi
153+}
154+
155+wait_booted() {
156+ echo "Waiting for device ADB to appear..." >&2
157+ if ! timeout 300 adb $ADBOPTS wait-for-device >/dev/null; then
158+ echo "ERROR: Timed out waiting for adb device" >&2
159+ fi
160+}
161+
162+# configure Ubuntu device for testing
163+ubuntu_prepare_config() {
164+ if [ -z "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
165+ # not an Ubuntu phone
166+ return
167+ fi
168+
169+ if ! type phablet-config >/dev/null 2>&1; then
170+ echo "ERROR: phablet-config not found! Install phablet-tools package or" >&2
171+ echo "bzr branch lp:phablet-tools and run with PHABLET_TOOLS_PATH=<checkout dir>" >&2
172+ exit 1
173+ fi
174+
175+ echo "Configuring Ubuntu phone for testing..." >&2
176+
177+ # disable first-time wizards; these fail due to adb instability from time
178+ # to time, so retry
179+ for retry in `seq 5`; do
180+ if phablet-config $ADBOPTS welcome-wizard --disable >/dev/null; then
181+ break
182+ else
183+ echo "Failed to disable welcome wizard, retrying (attempt $retry)..." >&2
184+ sleep 1
185+ fi
186+ done
187+ # this needs accounts-daemon running
188+ adb $ADBOPTS shell 'while ! pidof accounts-daemon >/dev/null; do sleep 1; done'
189+ for retry in `seq 5`; do
190+ if phablet-config $ADBOPTS edges-intro --disable >/dev/null; then
191+ break
192+ else
193+ echo "Failed to disable edges intro, retrying (attempt $retry)..." >&2
194+ sleep 1
195+ fi
196+ done
197+
198+ # kill an already running welcome wizard
199+ adb $ADBOPTS shell 'kill `pidof system-settings-wizard` 2>/dev/null'
200+}
201+
202+# test run time setup for Ubuntu device
203+ubuntu_prepare_for_testing() {
204+ if [ -z "$(adb $ADBOPTS shell 'type unity8 2>/dev/null')" ]; then
205+ # not an Ubuntu phone
206+ return
207+ fi
208+
209+ echo "Preparing Ubuntu phone for running tests..." >&2
210+
211+ echo "Waiting for desktop to boot" >&2
212+ local timeout=$(($(date +%s) + 300))
213+ while [ "$(date +%s)" -le $timeout ]; do
214+ 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')
215+ if [ -n "$out" ]; then
216+ timeout=0
217+ break
218+ fi
219+ sleep 5
220+ done
221+ if [ "$timeout" -gt 0 ]; then
222+ echo "ERROR: timed out waiting for Unity greeter" >&2
223+ exit 1
224+ fi
225+
226+ # disable screen dimming; ugly, but pretty much everything else hangs forever
227+ adb $ADBOPTS shell "setsid powerd-cli display </dev/null >/dev/null 2>&1 & disown;
228+ while ! pidof powerd-cli >/dev/null; do sleep 0.1; done"
229+
230+ # unlock the greeter
231+ adb $ADBOPTS shell "gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked" >/dev/null
232+}
233+
234+revert() {
235+ # revert is only offered on Ubuntu images
236+ echo "Performing factory reset, this will take a minute..." >&2
237+
238+ # save current network connections
239+ NETCONF=$(phablet-config $ADBOPTS network --read) || true:
240+
241+ # do factory reset
242+ adb $ADBOPTS shell 'gdbus call --system -d com.canonical.SystemImage -o /Service -m com.canonical.SystemImage.FactoryReset'
243+ wait_booted
244+ adb $ADBOPTS shell 'while ! pidof NetworkManager >/dev/null; do sleep 1; done'
245+
246+ # restore network connections
247+ if [ -n "$NETCONF" ]; then
248+ phablet-config $ADBOPTS network --write "$NETCONF"
249+ fi
250+
251+ ubuntu_prepare_config
252+ ubuntu_prepare_for_testing
253+}
254+
255+reboot() {
256+ if [ -z "$FWD_PORT" ]; then
257+ echo "ERROR: Must pass --fwd-port" >&2
258+ exit 1
259+ fi
260+ BOOT_TARGET=$(adb pull /run/adt_reboot_target /dev/stdout) || BOOT_TARGET=""
261+ adb $ADBOPTS reboot $BOOT_TARGET
262+ wait_booted
263+ adb $ADBOPTS forward tcp:$FWD_PORT tcp:22
264+ adb $ADBOPTS shell "gdbus call -y -d com.canonical.PropertyService -o /com/canonical/PropertyService -m com.canonical.PropertyService.SetProperty ssh true >/dev/null"
265+ ubuntu_prepare_for_testing
266+}
267+
268+cleanup() {
269+ adb $ADBOPTS shell pkill powerd-cli
270+}
271+
272+
273+#
274+# main
275+#
276+
277+# argument parsing
278+SHORTOPTS="l:,p:,s:,w,r,b"
279+LONGOPTS="login:,password:,serial:,rw,apt-update,reset,reboot,no-reset,fwd-port:"
280+
281+TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
282+eval set -- "$TEMP"
283+
284+while true; do
285+ case "$1" in
286+ -l|--login)
287+ SSH_USER=$2
288+ shift 2;;
289+ -p|--password)
290+ SUDO_PASSWORD="$2"
291+ shift 2;;
292+ -s|--serial)
293+ ADBOPTS="$ADBOPTS -s $2"
294+ shift 2;;
295+ -b|--reboot)
296+ REBOOT="1"
297+ shift;;
298+ -r|--reset)
299+ echo "--reset is currently broken as it does not restore PIN/developer mode. Use -b/--reboot instead." >&2
300+ exit 1
301+ RESET="1"
302+ shift;;
303+ # passed in "extraopts" so that --reset is only applied once, not
304+ # in between tests that call "revert"
305+ --no-reset)
306+ RESET=""
307+ shift;;
308+ --fwd-port)
309+ FWD_PORT="$2"
310+ shift 2;;
311+ --)
312+ shift;
313+ break;;
314+ *)
315+ echo "E: $(basename $0): Unsupported option $1" >&2
316+ exit 1;;
317+ esac
318+done
319+
320+if [ -z "$1" ]; then
321+ echo "Needs to be called with command as first argument" >&2
322+ exit 1
323+fi
324+
325+cmd=$(echo "$1"|tr [[:upper:]] [[:lower:]])
326+shift
327+
328+case $cmd in
329+ open)
330+ open;;
331+ revert)
332+ revert;;
333+ reboot)
334+ reboot;;
335+ cleanup)
336+ cleanup;;
337+ *)
338+ echo "invalid command $cmd" >&2
339+ exit 1
340+ ;;
341+esac
342
343=== modified file 'debian/tests/control'
344--- debian/tests/control 2015-03-05 00:36:08 +0000
345+++ debian/tests/control 2015-03-09 21:35:41 +0000
346@@ -1,2 +1,5 @@
347 Tests: ota_basic
348-Depends:
349+Restrictions: needs-root allow-stderr
350+Depends: python3-fixtures,
351+ python3-psutil,
352+ system-image-dbus (>=3.0)
353
354=== modified file 'debian/tests/ota_basic'
355--- debian/tests/ota_basic 2015-03-03 02:58:26 +0000
356+++ debian/tests/ota_basic 2015-03-09 21:35:41 +0000
357@@ -1,4 +1,4 @@
358-#!/bin/bash
359+#!/usr/bin/python3
360
361 #
362 # Ubuntu OTA Tests
363@@ -18,12 +18,31 @@
364 # along with this program. If not, see <http://www.gnu.org/licenses/>.
365 #
366
367-# Steps:
368-# - Flash device with revision x
369-# - Check device flashed correctly
370-# - Trigger upgrade to revision x+1
371-# - (Wait for upgrade)
372-# - Reboot device
373-# - Check the upgrade worked as expected.
374-
375-exit 0
376+import os
377+import subprocess
378+
379+from ubuntu_ota_tests import services
380+
381+
382+def write_adt_apply_config():
383+ config_path = get_system_image_config_dir()
384+ adt_apply_config_path = os.path.join(config_path, '01adt_apply.ini')
385+ with open(adt_apply_config_path, 'w') as apply_config_file:
386+ apply_config_file.write('[hooks]\n')
387+ apply_config_file.write(
388+ 'apply: ubuntu_ota_tests.hooks.ADTRebootToRecovery')
389+
390+
391+def get_system_image_config_dir():
392+ return os.environ.get('ADT_ARTIFACTS')
393+
394+
395+if __name__ == '__main__':
396+ rebooted_mark = os.environ.get('ADT_REBOOT_MARK', None)
397+ if not rebooted_mark:
398+ write_adt_apply_config()
399+ services.ensure_system_image_dbus_not_running()
400+ subprocess.check_call(
401+ ['system-image-dbus', '-v', '-C', get_system_image_config_dir()])
402+ else:
403+ print('Rebooted')
404
405=== added directory 'debian/tests/ubuntu_ota_tests'
406=== added file 'debian/tests/ubuntu_ota_tests/__init__.py'
407--- debian/tests/ubuntu_ota_tests/__init__.py 1970-01-01 00:00:00 +0000
408+++ debian/tests/ubuntu_ota_tests/__init__.py 2015-03-09 21:35:41 +0000
409@@ -0,0 +1,27 @@
410+#
411+# Ubuntu OTA Tests
412+# Copyright (C) 2015 Canonical
413+#
414+# This program is free software: you can redistribute it and/or modify
415+# it under the terms of the GNU General Public License as published by
416+# the Free Software Foundation, either version 3 of the License, or
417+# (at your option) any later version.
418+#
419+# This program is distributed in the hope that it will be useful,
420+# but WITHOUT ANY WARRANTY; without even the implied warranty of
421+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
422+# GNU General Public License for more details.
423+#
424+# You should have received a copy of the GNU General Public License
425+# along with this program. If not, see <http://www.gnu.org/licenses/>.
426+#
427+
428+from ubuntu_ota_tests import (
429+ services,
430+ system,
431+)
432+
433+__all__ = [
434+ 'services',
435+ 'system',
436+]
437
438=== added file 'debian/tests/ubuntu_ota_tests/hooks.py'
439--- debian/tests/ubuntu_ota_tests/hooks.py 1970-01-01 00:00:00 +0000
440+++ debian/tests/ubuntu_ota_tests/hooks.py 2015-03-09 21:35:41 +0000
441@@ -0,0 +1,42 @@
442+#
443+# Ubuntu OTA Tests
444+# Copyright (C) 2015 Canonical
445+#
446+# This program is free software: you can redistribute it and/or modify
447+# it under the terms of the GNU General Public License as published by
448+# the Free Software Foundation, either version 3 of the License, or
449+# (at your option) any later version.
450+#
451+# This program is distributed in the hope that it will be useful,
452+# but WITHOUT ANY WARRANTY; without even the implied warranty of
453+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
454+# GNU General Public License for more details.
455+#
456+# You should have received a copy of the GNU General Public License
457+# along with this program. If not, see <http://www.gnu.org/licenses/>.
458+#
459+
460+import logging
461+import subprocess
462+
463+from systemimage import apply
464+from systemimage.config import config
465+
466+
467+log = logging.getLogger('systemimage')
468+
469+
470+class ADTRebootToRecovery(apply.BaseApply):
471+
472+ def apply(self):
473+ try:
474+ with open('/run/adt_reboot_target', 'w') as reboot_target:
475+ reboot_target.write('recovery')
476+ subprocess.check_call(
477+ '/tmp/autopkgtest-reboot', universal_newlines=True)
478+ except subprocess.CalledProcessError as error:
479+ log.exception('reboot exit status: {}'.format(error.returncode))
480+ raise
481+ # This code may or may not run. We're racing against the system
482+ # reboot procedure.
483+ config.dbus_service.Rebooting(True)
484
485=== added file 'debian/tests/ubuntu_ota_tests/services.py'
486--- debian/tests/ubuntu_ota_tests/services.py 1970-01-01 00:00:00 +0000
487+++ debian/tests/ubuntu_ota_tests/services.py 2015-03-09 21:35:41 +0000
488@@ -0,0 +1,74 @@
489+#
490+# Ubuntu OTA Tests
491+# Copyright (C) 2015 Canonical
492+#
493+# This program is free software: you can redistribute it and/or modify
494+# it under the terms of the GNU General Public License as published by
495+# the Free Software Foundation, either version 3 of the License, or
496+# (at your option) any later version.
497+#
498+# This program is distributed in the hope that it will be useful,
499+# but WITHOUT ANY WARRANTY; without even the implied warranty of
500+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
501+# GNU General Public License for more details.
502+#
503+# You should have received a copy of the GNU General Public License
504+# along with this program. If not, see <http://www.gnu.org/licenses/>.
505+#
506+
507+import dbus
508+import logging
509+
510+from dbus.mainloop.glib import DBusGMainLoop
511+
512+from ubuntu_ota_tests import system
513+
514+
515+logger = logging.getLogger(__name__)
516+
517+
518+# Is there a better mechanism that we can use to ensure that DBusGMainLoop
519+# isn't called more than once?
520+_loop_running = False
521+
522+
523+def ensure_loop_running():
524+ global _loop_running
525+ if not _loop_running:
526+ DBusGMainLoop(set_as_default=True)
527+ _loop_running = True
528+
529+
530+def get_system_image_interface():
531+ """Return a dbus Interface for SystemImage Service.
532+
533+ Note calling this method will cause system-image-dbus to start (if it's not
534+ already started).
535+
536+ """
537+ ensure_loop_running()
538+
539+ system_bus = dbus.SystemBus()
540+ service = system_bus.get_object('com.canonical.SystemImage', '/Service')
541+ iface = dbus.Interface(service, 'com.canonical.SystemImage')
542+
543+ return iface
544+
545+
546+def ensure_system_image_dbus_not_running():
547+ if _is_system_image_process_running():
548+ sys_image_iface = get_system_image_interface()
549+ try:
550+ sys_image_iface.Exit()
551+ except dbus.DBusException:
552+ print("Attempted to exit system dbus when not running.")
553+ logger.debug("Attempted to exit system dbus when not running.")
554+
555+
556+def _is_system_image_process_running():
557+ """Return True if system-image-dbus process is running False otherwise."""
558+ # For some reason the process name is 'system-image-db' on the device.
559+ try:
560+ return system.get_process_by_name('system-image-db') is not None
561+ except OSError:
562+ return False
563
564=== added file 'debian/tests/ubuntu_ota_tests/system.py'
565--- debian/tests/ubuntu_ota_tests/system.py 1970-01-01 00:00:00 +0000
566+++ debian/tests/ubuntu_ota_tests/system.py 2015-03-09 21:35:41 +0000
567@@ -0,0 +1,33 @@
568+#
569+# Ubuntu OTA Tests
570+# Copyright (C) 2015 Canonical
571+#
572+# This program is free software: you can redistribute it and/or modify
573+# it under the terms of the GNU General Public License as published by
574+# the Free Software Foundation, either version 3 of the License, or
575+# (at your option) any later version.
576+#
577+# This program is distributed in the hope that it will be useful,
578+# but WITHOUT ANY WARRANTY; without even the implied warranty of
579+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
580+# GNU General Public License for more details.
581+#
582+# You should have received a copy of the GNU General Public License
583+# along with this program. If not, see <http://www.gnu.org/licenses/>.
584+#
585+
586+import psutil
587+
588+
589+def get_process_by_name(process_name):
590+ """Return a psutil.Process for the process with the given name.
591+
592+ :raises err something: if a process cannot be found with the given name.
593+
594+ """
595+ try:
596+ return [
597+ p for p in psutil.process_iter() if p.name() == process_name
598+ ][0]
599+ except IndexError:
600+ raise OSError('No process found with the name "'+process_name+'"')

Subscribers

People subscribed via source and target branches

to all changes: