Merge lp:~canonical-platform-qa/ubuntu-ota-tests/current-version-number into lp:ubuntu-ota-tests

Proposed by Federico Gimenez on 2015-03-04
Status: Merged
Approved by: Leo Arias on 2015-03-11
Approved revision: 27
Merged at revision: 4
Proposed branch: lp:~canonical-platform-qa/ubuntu-ota-tests/current-version-number
Merge into: lp:ubuntu-ota-tests
Diff against target: 152 lines (+48/-30)
5 files modified
debian/tests/control (+3/-1)
debian/tests/ota_basic (+0/-29)
debian/tests/ota_selftests (+30/-0)
debian/tests/ubuntu_ota_tests/selftests/test_services.py (+8/-0)
debian/tests/ubuntu_ota_tests/services.py (+7/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-ota-tests/current-version-number
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-03-11
Leo Arias (community) 2015-03-09 Approve on 2015-03-11
Richard Huddie (community) Approve on 2015-03-09
Brendan Donegan (community) 2015-03-04 Approve on 2015-03-09
Review via email: mp+251774@code.launchpad.net

Commit Message

Getting the current version number through the D-Bus API

Description of the Change

For executing the tests:

  $ adt-run -B --unbuilt-tree=. --- ssh -s adb

To post a comment you must log in.
Brendan Donegan (brendan-donegan) wrote :

Why does the current_version script need to call adb? Tests shouldn't have to call adb that should be a matter for the runner - I would remove that if it doesn't have any purpose

review: Needs Information
Federico Gimenez (fgimenez) wrote :

You are right, it was a proof of concept. I've modified it to run from a test with a bash function that could be reused.

Barry Warsaw (barry) wrote :

Thoughts, suggestions, questions.

review: Needs Fixing
Federico Gimenez (fgimenez) wrote :

Some inline comments, thanks!

Federico Gimenez (fgimenez) wrote :

I've taken the opportunity to add some self tests for the current code. The get_systemimage_iface test reflects that the interaction with the dbus api is a bit complicated, Demeter must be turning in her grave (if she has one) :)

Brendan Donegan (brendan-donegan) wrote :

Thanks for the tests, but I'm confused by some of the refactoring you did.

review: Needs Information
Federico Gimenez (fgimenez) wrote :

@brendand finally I've reverted the initial approach, if we need to add more methods to interact with the api the iface would be instantiated one time for each one of them with the default value of the function as I had defined it.

Brendan Donegan (brendan-donegan) wrote :

Okay looks good to me. Try and get one more review

review: Approve
Brendan Donegan (brendan-donegan) wrote :

Some questions about debian/tests/control actually

review: Needs Information
Federico Gimenez (fgimenez) wrote :

Yes, ota_basic was a shell-script based test used in the first spikes, see for example this recent branch from Chris [1] where it is already removed.

Regarding the Tests-Directory configuration option I've leave it there as a remainder to myself (we can remove it of course), it is what Martin suggested in order to execute the autopkgtest scripts from the root of the project and being able to import the python modules placed there as well. I think that we still need to decide how are we going to handle this.

[1] https://code.launchpad.net/~canonical-platform-qa/ubuntu-ota-tests/check-for-running-service/+merge/252057

Brendan Donegan (brendan-donegan) wrote :

> Yes, ota_basic was a shell-script based test used in the first spikes, see for
> example this recent branch from Chris [1] where it is already removed.
>
> Regarding the Tests-Directory configuration option I've leave it there as a
> remainder to myself (we can remove it of course), it is what Martin suggested

If it's to serve as a reminder than put an actual reminder, something like '# We might be able to use Tests-Directory here instead of hacking the path in the scripts'

> in order to execute the autopkgtest scripts from the root of the project and
> being able to import the python modules placed there as well. I think that we
> still need to decide how are we going to handle this.
>
> [1] https://code.launchpad.net/~canonical-platform-qa/ubuntu-ota-tests/check-
> for-running-service/+merge/252057

Federico Gimenez (fgimenez) wrote :

Well, it was just a remainder for me :) I've removed it, let's see if we finally use it or not

Brendan Donegan (brendan-donegan) wrote :

Okay, approve

review: Approve
Leo Arias (elopio) wrote :

This branch has some small flake8 errors. Please fix them before merging. Other than that, looks good to me.

review: Needs Fixing
Federico Gimenez (fgimenez) wrote :

Ok, fixed. We could add a minimal setup.py file for executing flake8 (and perhaps coverage), don't know if it's worth the effort.

Thanks!

Richard Huddie (rhuddie) wrote :

Checked there were no flake8 errors and ran with adt-run, which gave the correct build number. Looks good, so approving.

review: Approve
Leo Arias (elopio) wrote :

135 +++ ubuntu_ota_tests/tests/test_client.py

This file is missing the copyright header. After that, +1 from me.

Federico Gimenez (fgimenez) wrote :

Ok, added the copyright; there's also a notice in the readme about how to run the unit tests

Thanks!

Federico Gimenez (fgimenez) wrote :

Merged [1] into this one, I've put this one back to in progress until that branch lands.

[1] https://code.launchpad.net/~canonical-platform-qa/ubuntu-ota-tests/check-for-running-service

24. By Federico Gimenez on 2015-03-11

flake8 fixes; reverted ota_basic

Brendan Donegan (brendan-donegan) wrote :

Already approved by me, I don't see anything else to be done

Leo Arias (elopio) wrote :

looks good. I'd just like the coverage command in a script.

review: Needs Fixing
25. By Federico Gimenez on 2015-03-11

returning an actual int

26. By Federico Gimenez on 2015-03-11

test instead of test command; moved coverage reports to ADT_ARTIFACTS; setup + addcleanup instead of teardown

Federico Gimenez (fgimenez) wrote :

Ok, I think that all the issues have been addressed... except the ota_basic one, it's a mistery for me why it is reported like that

Thanks!

Leo Arias (elopio) wrote :

Great, thanks Federico.
I think we should set -e to the ota_selftests script to be on the safe side.

I'll do it as I think you already EOD.

27. By Leo Arias on 2015-03-11

Added set -e to the selftests script.

Leo Arias (elopio) wrote :

85% coverage, not bad. Top-approving.

review: Approve
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/tests/control'
2--- debian/tests/control 2015-03-10 06:37:58 +0000
3+++ debian/tests/control 2015-03-11 17:57:10 +0000
4@@ -1,4 +1,6 @@
5-Test-Command: cd debian/tests; python3 -m unittest discover ubuntu_ota_tests.selftests
6+Tests: ota_selftests
7 Restrictions: allow-stderr
8 Depends: python3-autopilot,
9+ python3-coverage,
10 python3-psutil,
11+
12
13=== added file 'debian/tests/ota_basic'
14--- debian/tests/ota_basic 1970-01-01 00:00:00 +0000
15+++ debian/tests/ota_basic 2015-03-11 17:57:10 +0000
16@@ -0,0 +1,29 @@
17+#!/bin/bash
18+
19+#
20+# Ubuntu OTA Tests
21+# Copyright (C) 2015 Canonical
22+#
23+# This program is free software: you can redistribute it and/or modify
24+# it under the terms of the GNU General Public License as published by
25+# the Free Software Foundation, either version 3 of the License, or
26+# (at your option) any later version.
27+#
28+# This program is distributed in the hope that it will be useful,
29+# but WITHOUT ANY WARRANTY; without even the implied warranty of
30+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31+# GNU General Public License for more details.
32+#
33+# You should have received a copy of the GNU General Public License
34+# along with this program. If not, see <http://www.gnu.org/licenses/>.
35+#
36+
37+# Steps:
38+# - Flash device with revision x
39+# - Check device flashed correctly
40+# - Trigger upgrade to revision x+1
41+# - (Wait for upgrade)
42+# - Reboot device
43+# - Check the upgrade worked as expected.
44+
45+exit 0
46
47=== removed file 'debian/tests/ota_basic'
48--- debian/tests/ota_basic 2015-03-03 02:58:26 +0000
49+++ debian/tests/ota_basic 1970-01-01 00:00:00 +0000
50@@ -1,29 +0,0 @@
51-#!/bin/bash
52-
53-#
54-# Ubuntu OTA Tests
55-# Copyright (C) 2015 Canonical
56-#
57-# This program is free software: you can redistribute it and/or modify
58-# it under the terms of the GNU General Public License as published by
59-# the Free Software Foundation, either version 3 of the License, or
60-# (at your option) any later version.
61-#
62-# This program is distributed in the hope that it will be useful,
63-# but WITHOUT ANY WARRANTY; without even the implied warranty of
64-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65-# GNU General Public License for more details.
66-#
67-# You should have received a copy of the GNU General Public License
68-# along with this program. If not, see <http://www.gnu.org/licenses/>.
69-#
70-
71-# Steps:
72-# - Flash device with revision x
73-# - Check device flashed correctly
74-# - Trigger upgrade to revision x+1
75-# - (Wait for upgrade)
76-# - Reboot device
77-# - Check the upgrade worked as expected.
78-
79-exit 0
80
81=== added file 'debian/tests/ota_selftests'
82--- debian/tests/ota_selftests 1970-01-01 00:00:00 +0000
83+++ debian/tests/ota_selftests 2015-03-11 17:57:10 +0000
84@@ -0,0 +1,30 @@
85+#!/bin/bash
86+
87+#
88+# Ubuntu OTA Tests
89+# Copyright (C) 2015 Canonical
90+#
91+# This program is free software: you can redistribute it and/or modify
92+# it under the terms of the GNU General Public License as published by
93+# the Free Software Foundation, either version 3 of the License, or
94+# (at your option) any later version.
95+#
96+# This program is distributed in the hope that it will be useful,
97+# but WITHOUT ANY WARRANTY; without even the implied warranty of
98+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99+# GNU General Public License for more details.
100+#
101+# You should have received a copy of the GNU General Public License
102+# along with this program. If not, see <http://www.gnu.org/licenses/>.
103+#
104+
105+set -e
106+
107+cd debian/tests
108+
109+python3-coverage run --include=./ubuntu_ota_tests/* --omit=./ubuntu_ota_tests/selftests/*,./ubuntu_ota_tests/__init__.py -m unittest discover ubuntu_ota_tests.selftests
110+
111+mkdir -p $ADT_ARTIFACTS/coverage && python3-coverage report -m > $ADT_ARTIFACTS/coverage/report.txt
112+mv .coverage $ADT_ARTIFACTS/coverage
113+
114+exit 0
115
116=== modified file 'debian/tests/ubuntu_ota_tests/selftests/test_services.py'
117--- debian/tests/ubuntu_ota_tests/selftests/test_services.py 2015-03-10 05:55:55 +0000
118+++ debian/tests/ubuntu_ota_tests/selftests/test_services.py 2015-03-11 17:57:10 +0000
119@@ -23,6 +23,9 @@
120
121 class ServicesTestCase(unittest.TestCase):
122
123+ def setUp(self):
124+ self.addCleanup(services.ensure_system_image_dbus_not_running)
125+
126 def test_ensure_system_image_dbus_not_runnig_must_stop_process(self):
127 # start the dbus process if it isn't already
128 services.get_system_image_interface()
129@@ -30,3 +33,8 @@
130
131 services.ensure_system_image_dbus_not_running()
132 self.assertFalse(services._is_system_image_process_running())
133+
134+ def test_get_current_version_number(self):
135+ current_build_number = services.get_current_build_number()
136+ self.assertGreater(current_build_number, 0,
137+ 'The current build number should be greater than 0')
138
139=== modified file 'debian/tests/ubuntu_ota_tests/services.py'
140--- debian/tests/ubuntu_ota_tests/services.py 2015-03-10 03:31:34 +0000
141+++ debian/tests/ubuntu_ota_tests/services.py 2015-03-11 17:57:10 +0000
142@@ -84,3 +84,10 @@
143 return system.get_process_by_name(SYS_IMG_PROC_NAME) is not None
144 except OSError:
145 return False
146+
147+
148+def get_current_build_number():
149+ """Returns the build number of the current image"""
150+ sys_image_iface = get_system_image_interface()
151+ info = sys_image_iface.Information()
152+ return int(info['current_build_number'])

Subscribers

People subscribed via source and target branches

to all changes: