Merge lp:~canonical-platform-qa/ubuntu-ota-tests/dbus-upgrade into lp:ubuntu-ota-tests
- dbus-upgrade
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Brendan Donegan |
Approved revision: | 68 |
Merged at revision: | 15 |
Proposed branch: | lp:~canonical-platform-qa/ubuntu-ota-tests/dbus-upgrade |
Merge into: | lp:ubuntu-ota-tests |
Prerequisite: | lp:~barry/ubuntu-ota-tests/packaging |
Diff against target: | 237 lines (+127/-10) 7 files modified debian/tests/control (+4/-2) debian/tests/ota-dbus-upgrade (+35/-0) ubuntu_ota_tests/hooks.py (+4/-0) ubuntu_ota_tests/reactors.py (+1/-0) ubuntu_ota_tests/selftests/test_services.py (+2/-1) ubuntu_ota_tests/tests/test_basic_upgrade.py (+27/-5) ubuntu_ota_tests/upgrade.py (+54/-2) |
To merge this branch: | bzr merge lp:~canonical-platform-qa/ubuntu-ota-tests/dbus-upgrade |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Christopher Lee (community) | Approve | ||
Barry Warsaw (community) | Approve | ||
Review via email: |
This proposal supersedes a proposal from 2015-03-17.
Commit message
Added the upgrade through dbus.
Description of the change
To get this working with si 3.0:
$ ubuntu-device-flash --revision=-1 touch --developer-mode --password 0000 --channel=
$ phablet-network
$ phablet-shell
phablet@
phablet@
phablet@
phablet@
phablet@
phablet@
$ adt-run -B --unbuilt-tree=. --testname command1 --- ssh -s ./adb-reboot-

Barry Warsaw (barry) wrote : | # |

Barry Warsaw (barry) wrote : | # |
A couple of minor comments, but nothing to hold up approval.

Barry Warsaw (barry) wrote : | # |
Hmm, I am getting some test failures. My device is flashed to 154, but I hacked /etc/system-
=======
FAIL: test_basic_
-------
Traceback (most recent call last):
File "/tmp/adt-
self.upgrade()
File "/tmp/adt-
upgrade.
File "/tmp/adt-
assert status.
AssertionError: Update not available
I also see check-for-update failing on an ImportError, but that's probably because it doesn't do the PYTHONPATH workaround.

Federico Gimenez (fgimenez) wrote : | # |
It seems that the command
system-image-dbus -v -C {config_dir}
in ubuntu_
Could anyone please confirm this? I'm running the tests with:
$ ubuntu-device-flash --revision=-1 touch --developer-mode --password 0000 --channel=
$ adt-run -B --unbuilt-tree=. --setup-commands 'mount -o remount,rw /' --setup-commands 'apt-add-repository -y ppa:barry/

Barry Warsaw (barry) wrote : | # |
On Mar 24, 2015, at 11:33 AM, Federico Gimenez wrote:
>It seems that the command
>
> system-image-dbus -v -C {config_dir}
>
>in ubuntu_
>
>Could anyone please confirm this? I'm running the tests with:
>
>$ ubuntu-device-flash --revision=-1 touch --developer-mode --password 0000 --channel=
>
>$ adt-run -B --unbuilt-tree=. --setup-commands 'mount -o remount,rw /' --setup-commands 'apt-add-repository -y ppa:barry/
>
When I run the above adt-run command, I get this:
=======
FAIL: test_basic_
-------
Traceback (most recent call last):
File "/tmp/adt-
self.upgrade()
File "/tmp/adt-
upgrade.
File "/tmp/adt-
assert status.
AssertionError: Update not available
which is telling me that there's no upgrade available, possibly because a
previous test actually performed the update, such that the device is at the
current revision. This doesn't seem right though because:
root@ubuntu-
Upgrade path is 154:155:156:157:158
Target phase: 33%
Looking back through the logs though I see:
[systemimage] Mar 24 14:00:08 2015 (10604) no matching channel: daily
and yet:
root@ubuntu-
current build number: 153
device name: krillin
channel: ubuntu-
alias: ubuntu-
last update: 2015-03-19 18:27:46
version version: 153
version ubuntu: 20150319.1
version device: 20150310-ae1ddec
version custom: 20150319.1
I'm not sure where this 'daily' channel is coming from though.

Federico Gimenez (fgimenez) wrote : | # |
Thanks Barry, yes, this seems to be the same behaviour that you described above, there's an update available but services.
Could you please replace the 'command' variable definition at [1] with:
command = 'system-image-dbus -v'
and run the test again, including the reflash? In that case, I'm seeing that the update is detected correctly and all seems to go well, but the apply hook is not defined. So it seems that when -C is passed to system-image-dbus (or when there's a .ini file like the one we are creating) the detection of the update doesn't work the same way, could you please confirm this?
Cheers!

Barry Warsaw (barry) wrote : | # |
On Mar 24, 2015, at 02:40 PM, Federico Gimenez wrote:
>Could you please replace the 'command' variable definition at [1] with:
>
> command = 'system-image-dbus -v'
>
>and run the test again, including the reflash? In that case, I'm seeing that
>the update is detected correctly and all seems to go well, but the apply hook
>is not defined. So it seems that when -C is passed to system-image-dbus (or
>when there's a .ini file like the one we are creating) the detection of the
>update doesn't work the same way, could you please confirm this?
Before running the above, I made this change:
=== modified file 'ubuntu_
--- ubuntu_
+++ ubuntu_
@@ -39,10 +39,15 @@
def upgrade_
if systemimage.
+ config_dir = _get_system_
+ command = 'system-image-dbus -v -C {}'.format(
+ print('Starting system-image with', command)
+ for filename in sorted(
+ print('=====', filename, '=====')
+ with open(os.
+ encoding='utf-8') as fp:
+ print(fp.read())
- command = 'system-image-dbus -v -C {config_
- config_
- print('Starting system-image with', command)
# as Popen doesn't block without the following sleep this is printed:
# [systemimage] Mar 23 16:18:10 2015 (26139) Cannot get exclusive ownership of bus name.
Then I ran the test and watched the output. What I see makes me think that
_get_system_
Starting system-image with system-image-dbus -v -C /tmp/adt-
===== 99_adt_apply.ini =====
[hooks]
apply: ubuntu_
See? 99_adt_apply.ini appears to be the *only* .ini file in
/tmp/adt-
[systemimage] Mar 24 18:16:27 2015 (5682) no matching channel: daily
makes sense because 'daily' is the baked-in default channel when there is none
defined in an on-system config file.
So I think the test setup is not happening as you expect. Note that the
adt-run command described in d/t/ota-
correctly set up /etc/systemimag
$ADT_ARTIFACTS directory is *not* set up correctly.
I'm not sure what the intent of using $ADT_ARTIFACTS is, but if you really
want the -C config dir to point there, you should at least copy all the .ini
files from /etc/system-
99_adt_apply.ini
I haven't investigated, but I wonder if this is the same reason that
test_download_

Federico Gimenez (fgimenez) wrote : | # |
Thanks Barry, with the default config files in the custom directory all goes fine. We are using this directory because during the test execution the filesystem is in ro mode, this way we can add the file for defining the apply hook there.
I'm now looking into the download timeout, the services' module download_update function seems to be broken. Anyway with a manual download from the device the reboot doesn't seem to apply it, it seems to boot into recovery mode without applying the update. I'll go for this once the timeout is fixed.
Cheers!
- 65. By Federico Gimenez
-
Disabled upgrade assertion for subtask

Christopher Lee (veebers) wrote : | # |
Looking good to me, a couple of minor comments inline.
Ran it locally and it works fine.
- 66. By Federico Gimenez
-
Added bug references for test command comment and the required fix for apply upgrade
- 67. By Federico Gimenez
-
flake8
- 68. By Federico Gimenez
-
Better log message

Federico Gimenez (fgimenez) wrote : | # |
Thanks Chris, added log messages describing the type of upgrade and references to the bugs, they are [1] and [2], I'll refer to them also from the trello cards.
I'll make another branch for the apply upgrade fix with this as a prerequisite.
Cheers!
[1] https:/
[2] https:/

PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'debian/tests/control' |
2 | --- debian/tests/control 2015-03-18 19:55:33 +0000 |
3 | +++ debian/tests/control 2015-03-26 09:27:19 +0000 |
4 | @@ -5,11 +5,13 @@ |
5 | python3-psutil, |
6 | system-image-dbus |
7 | |
8 | -Test-Command: python3 -m unittest ubuntu_ota_tests.tests.test_basic_upgrade |
9 | +Tests: ota-dbus-upgrade |
10 | Restrictions: needs-root allow-stderr |
11 | Depends: python3-autopilot, |
12 | python3-psutil, |
13 | - system-image-cli |
14 | + system-image-cli, |
15 | + system-image-common, |
16 | + system-image-dbus |
17 | |
18 | Tests: check-for-update |
19 | Depends: system-image-common, |
20 | |
21 | === added file 'debian/tests/ota-dbus-upgrade' |
22 | --- debian/tests/ota-dbus-upgrade 1970-01-01 00:00:00 +0000 |
23 | +++ debian/tests/ota-dbus-upgrade 2015-03-26 09:27:19 +0000 |
24 | @@ -0,0 +1,35 @@ |
25 | +#!/bin/bash |
26 | + |
27 | +# |
28 | +# Ubuntu OTA Tests |
29 | +# Copyright (C) 2015 Canonical |
30 | +# |
31 | +# This program is free software: you can redistribute it and/or modify |
32 | +# it under the terms of the GNU General Public License as published by |
33 | +# the Free Software Foundation, either version 3 of the License, or |
34 | +# (at your option) any later version. |
35 | +# |
36 | +# This program is distributed in the hope that it will be useful, |
37 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
38 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
39 | +# GNU General Public License for more details. |
40 | +# |
41 | +# You should have received a copy of the GNU General Public License |
42 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
43 | +# |
44 | + |
45 | +# This test requires a device upgradable, for example with: |
46 | +# |
47 | +# $ ubuntu-device-flash --revision=-1 touch --developer-mode --password 0000 --channel="ubuntu-touch/devel-proposed" --wipe |
48 | +# |
49 | +# The test can be executed with this command: |
50 | +# |
51 | +# $ adt-run -B --unbuilt-tree=. --setup-commands 'mount -o remount,rw /' --setup-commands 'apt-add-repository -y ppa:barry/systemimage' --setup-commands 'apt-get --no-list-cleanup update -o Dir::Etc::SourceList=/dev/null' --setup-commands 'apt-get install -y -q system-image-cli system-image-common system-image-dbus' --setup-commands 'if [ ! -d "/etc/system-image/config.d" ]; then mkdir -p /etc/system-image/config.d && cd /etc/system-image && cp client.ini config.d/00_default.ini && cp channel.ini config.d/01_channel.ini; fi' --setup-commands 'sync; sleep 2; mount -o remount,ro /' --- ssh -s ./adb-reboot-to-recovery |
52 | +# |
53 | +# When si 3.0 reaches the archive this can be executed normally |
54 | +# Ref. bug: https://bugs.launchpad.net/ubuntu-ota-tests/+bug/1436730 |
55 | +# |
56 | + |
57 | +set -e |
58 | + |
59 | +PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m unittest ubuntu_ota_tests.tests.test_basic_upgrade |
60 | |
61 | === modified file 'ubuntu_ota_tests/hooks.py' |
62 | --- ubuntu_ota_tests/hooks.py 2015-03-24 11:32:24 +0000 |
63 | +++ ubuntu_ota_tests/hooks.py 2015-03-26 09:27:19 +0000 |
64 | @@ -26,6 +26,7 @@ |
65 | # si 2.5 |
66 | from systemimage.reboot import BaseReboot as Base |
67 | |
68 | +from systemimage.config import config |
69 | |
70 | log = logging.getLogger('systemimage') |
71 | |
72 | @@ -59,6 +60,9 @@ |
73 | log.exception('reboot exit status: {}'.format(error.returncode)) |
74 | log.exception('reboot command output: {}'.format(error.output)) |
75 | raise |
76 | + # This code may or may not run. We're racing against the system |
77 | + # reboot procedure. |
78 | + config.dbus_service.Rebooting(True) |
79 | |
80 | # si 2.5 |
81 | reboot = apply |
82 | |
83 | === modified file 'ubuntu_ota_tests/reactors.py' |
84 | --- ubuntu_ota_tests/reactors.py 2015-03-18 19:58:04 +0000 |
85 | +++ ubuntu_ota_tests/reactors.py 2015-03-26 09:27:19 +0000 |
86 | @@ -75,6 +75,7 @@ |
87 | |
88 | def _do_Applied(self, signal, path, *args): |
89 | self.signals.append(AppliedRecord(*args)) |
90 | + self.quit() |
91 | |
92 | |
93 | class DownloadReactor(BaseReactor): |
94 | |
95 | === modified file 'ubuntu_ota_tests/selftests/test_services.py' |
96 | --- ubuntu_ota_tests/selftests/test_services.py 2015-03-24 11:32:24 +0000 |
97 | +++ ubuntu_ota_tests/selftests/test_services.py 2015-03-26 09:27:19 +0000 |
98 | @@ -59,6 +59,8 @@ |
99 | services.set_auto_download(True) |
100 | self.assertEqual(True, services.get_auto_download()) |
101 | |
102 | + @unittest.skipIf(is_update_available(), |
103 | + 'Update available, would make DownloadUpdate fail') |
104 | def test_check_for_update(self): |
105 | status = services.check_for_update() |
106 | utcnow = datetime.utcnow().replace(microsecond=0).isoformat(' ') |
107 | @@ -89,7 +91,6 @@ |
108 | def test_download_update(self): |
109 | sys_image_iface = services.get_system_image_interface() |
110 | self.assertEqual(sys_image_iface.CancelUpdate(), '') |
111 | - self.assertTrue(is_update_available()) |
112 | signals = services.download_update() |
113 | # validate that last record was a successful download signal |
114 | self.validate_successful_download(signals[-1]) |
115 | |
116 | === modified file 'ubuntu_ota_tests/tests/test_basic_upgrade.py' |
117 | --- ubuntu_ota_tests/tests/test_basic_upgrade.py 2015-03-12 15:37:04 +0000 |
118 | +++ ubuntu_ota_tests/tests/test_basic_upgrade.py 2015-03-26 09:27:19 +0000 |
119 | @@ -16,19 +16,41 @@ |
120 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
121 | # |
122 | |
123 | +import logging |
124 | import os |
125 | import unittest |
126 | |
127 | -from ubuntu_ota_tests import upgrade |
128 | +from ubuntu_ota_tests import ( |
129 | + services, |
130 | + upgrade |
131 | +) |
132 | + |
133 | +logger = logging.getLogger(__name__) |
134 | |
135 | |
136 | class OTABasicUpgradeTestCase(unittest.TestCase): |
137 | |
138 | + def before_upgrade(self): |
139 | + pass |
140 | + |
141 | + def upgrade(self): |
142 | + try: |
143 | + logger.info('Trying to upgrade with system-image-dbus') |
144 | + upgrade.upgrade_with_system_image_dbus() |
145 | + except NotImplementedError: |
146 | + logger.info('Upgrading with system-image-cli') |
147 | + upgrade.upgrade_with_system_image_cli() |
148 | + |
149 | + def after_upgrade(self): |
150 | + services.check_for_update() |
151 | + # XXX: enable this test when the upgrade will work |
152 | + # Ref. bug: https://bugs.launchpad.net/ubuntu-ota-tests/+bug/1436753 |
153 | + # self.assertFalse(status.is_available, 'Update available') |
154 | + |
155 | def test_basic_over_the_air_upgrade(self): |
156 | rebooted_mark = os.environ.get('ADT_REBOOT_MARK', None) |
157 | if not rebooted_mark: |
158 | - # The upgrade with dbus needs more work, it's getting stuck. |
159 | - # upgrade.upgrade_with_system_image_dbus() |
160 | - upgrade.upgrade_with_system_image_cli() |
161 | + self.before_upgrade() |
162 | + self.upgrade() |
163 | else: |
164 | - print('Rebooted') |
165 | + self.after_upgrade() |
166 | |
167 | === modified file 'ubuntu_ota_tests/upgrade.py' |
168 | --- ubuntu_ota_tests/upgrade.py 2015-03-10 21:46:22 +0000 |
169 | +++ ubuntu_ota_tests/upgrade.py 2015-03-26 09:27:19 +0000 |
170 | @@ -16,13 +16,65 @@ |
171 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
172 | # |
173 | |
174 | +import glob |
175 | +import os |
176 | import subprocess |
177 | |
178 | -from ubuntu_ota_tests import hooks |
179 | +import systemimage.service |
180 | +import shutil |
181 | +import time |
182 | + |
183 | +from ubuntu_ota_tests import ( |
184 | + hooks, |
185 | + services |
186 | +) |
187 | |
188 | |
189 | def upgrade_with_system_image_cli(): |
190 | command = 'system-image-cli -v -g' |
191 | - print('Upgrading with ' + command) |
192 | + print('Upgrading with ', command) |
193 | subprocess.check_call(command.split()) |
194 | hooks.ADTRebootToRecovery().reboot() |
195 | + |
196 | + |
197 | +def upgrade_with_system_image_dbus(): |
198 | + if systemimage.service.__version__.startswith('3.0'): |
199 | + _write_adt_apply_config() |
200 | + _copy_default_system_image_config() |
201 | + services.ensure_system_image_dbus_not_running() |
202 | + command = 'system-image-dbus -v -C {config_dir}'.format( |
203 | + config_dir=_get_system_image_config_dir()) |
204 | + print('Starting system-image with', command) |
205 | + subprocess.Popen(command.split()) |
206 | + # as Popen doesn't block without the following sleep this is printed: |
207 | + # [systemimage] (26139) Cannot get exclusive ownership of bus name. |
208 | + time.sleep(1) |
209 | + services.set_auto_download(False) |
210 | + status = services.check_for_update() |
211 | + assert status.is_available, 'Update not available' |
212 | + services.download_update() |
213 | + services.apply_update() |
214 | + else: |
215 | + raise NotImplementedError( |
216 | + 'dbus upgrade not implemented for system-image 2.5') |
217 | + |
218 | + |
219 | +def _write_adt_apply_config(): |
220 | + config_path = _get_system_image_config_dir() |
221 | + adt_apply_config_path = os.path.join(config_path, '99_adt_apply.ini') |
222 | + with open(adt_apply_config_path, 'w+') as apply_config_file: |
223 | + print("""\ |
224 | +[hooks] |
225 | +apply: ubuntu_ota_tests.hooks.ADTRebootToRecovery |
226 | +""", file=apply_config_file) |
227 | + |
228 | + |
229 | +def _copy_default_system_image_config(): |
230 | + config_path = _get_system_image_config_dir() |
231 | + default_path = '/etc/system-image/config.d' |
232 | + for file in glob.glob('{path}/*.ini'.format(path=default_path)): |
233 | + shutil.copy(file, config_path) |
234 | + |
235 | + |
236 | +def _get_system_image_config_dir(): |
237 | + return os.environ.get('ADT_ARTIFACTS') |
After installing si 3.0:
$ sudo -s d/00_default. ini d/01_channel. ini
$ cd /etc/system-image
$ mkdir config.d
$ cp client.ini config.
$ cp channel.ini config.
$ exit
Eventually that wouldn't be needed.