Merge lp:~heber013/ubuntu-system-tests/add-install-package-option into lp:ubuntu-system-tests

Proposed by Heber Parrucci
Status: Needs review
Proposed branch: lp:~heber013/ubuntu-system-tests/add-install-package-option
Merge into: lp:ubuntu-system-tests
Diff against target: 194 lines (+99/-12)
5 files modified
README.rst (+15/-0)
ubuntu_system_tests/host/command_line.py (+20/-6)
ubuntu_system_tests/host/enable_proposed.py (+58/-0)
ubuntu_system_tests/host/targets.py (+4/-4)
ubuntu_system_tests/selftests/utils.py (+2/-2)
To merge this branch: bzr merge lp:~heber013/ubuntu-system-tests/add-install-package-option
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Approve
Jean-Baptiste Lallement Pending
Review via email: mp+337886@code.launchpad.net

Commit message

Adding option to install packages as part of the setup

Description of the change

Adding option to setup in order to install one or more packages in the device as part of the setup process:

  $ ubuntu-system-tests setup --install-packages package1,package2

You can also install packages from proposed archive:

  $ ubuntu-system-tests setup --install-packages package1/*release*-proposed

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
583. By Heber Parrucci

Fixing flake8 issues

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
584. By Heber Parrucci

fixing selftest

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
585. By Heber Parrucci

Add file in sources.list.d for enabling proposed

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

585. By Heber Parrucci

Add file in sources.list.d for enabling proposed

584. By Heber Parrucci

fixing selftest

583. By Heber Parrucci

Fixing flake8 issues

582. By Heber Parrucci

Adding option to install packages as part of the setup

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 2017-06-27 20:33:54 +0000
3+++ README.rst 2018-03-23 12:23:17 +0000
4@@ -596,6 +596,21 @@
5 $ ubuntu-system-tests setup --install-tests package1 package2.module2
6
7
8+Install packages in the device
9+------------------------------
10+It is possible to install one or more packages in the device as part of the setup process.
11+It can be used by using *--install-packages* from command line:
12+
13+::
14+
15+ $ ubuntu-system-tests setup --install-packages package1,package2
16+
17+You can also install packages from proposed archive:
18+::
19+
20+ $ ubuntu-system-tests setup --install-packages package1/*release*-proposed
21+
22+
23 Upgrade device using dist-upgrade
24 ---------------------------------
25
26
27=== modified file 'ubuntu_system_tests/host/command_line.py'
28--- ubuntu_system_tests/host/command_line.py 2017-08-16 18:53:17 +0000
29+++ ubuntu_system_tests/host/command_line.py 2018-03-23 12:23:17 +0000
30@@ -110,6 +110,9 @@
31 'of {a} are also supported. The list of tests returned from Practitest '
32 'will be used in addition to any tests specified in the '
33 'suites parameter.'.format(a=', '.join(FILTER_ALIAS.keys()))})
34+OPTION_INSTALL_PACKAGES = Option(
35+ ['--install-packages'],
36+ {'help': 'Comma separated list of packages to install as part of the setup'})
37 OPTION_QEMU_HEADLESS = Option(
38 ['--headless', '-l'],
39 {'action': 'store_true',
40@@ -216,6 +219,7 @@
41 OPTION_CACHE_DEPS,
42 OPTION_DIST_UPGRADE,
43 OPTION_INSTALL_TESTS,
44+ OPTION_INSTALL_PACKAGES,
45 OPTION_UPDATE_APT,
46 OPTION_PPA_LIST,
47 OPTION_SETUP_SUITES,
48@@ -685,7 +689,7 @@
49 status = target.run_setup().status
50 if status and count < 1:
51 # Error was reported after first setup attempt,
52- # so reboot device and try again.
53+ # so reboot device and try again
54 print(
55 'Rebooting device after setup completed with '
56 'status {s}.'.format(s=status))
57@@ -698,11 +702,21 @@
58 """Run post setup actions on the target and return status result."""
59 if status:
60 print('Setup failed with status: {}.'.format(status))
61- elif args.cache_deps:
62- # Download dependencies using autopkgtest
63- adt_run_cmd = cmds.build_adt_run_test_command(
64- config_stack, args, target)
65- status = subprocess.call(adt_run_cmd)
66+ else:
67+ if args.install_packages:
68+ target.connect()
69+ target.push_setup_script(script='enable_proposed.py')
70+ command = '/usr/bin/python3 /tmp/enable_proposed.py'
71+ target.run_sudo(command)
72+ target.run_sudo('apt update')
73+ packages = args.install_packages.split(',')
74+ for package in packages:
75+ target.run_sudo('apt install %s -y' % package)
76+ if args.cache_deps:
77+ # Download dependencies using autopkgtest
78+ adt_run_cmd = cmds.build_adt_run_test_command(
79+ config_stack, args, target)
80+ status = subprocess.call(adt_run_cmd)
81 return status
82
83
84
85=== added file 'ubuntu_system_tests/host/enable_proposed.py'
86--- ubuntu_system_tests/host/enable_proposed.py 1970-01-01 00:00:00 +0000
87+++ ubuntu_system_tests/host/enable_proposed.py 2018-03-23 12:23:17 +0000
88@@ -0,0 +1,58 @@
89+#!/usr/bin/env python3
90+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
91+
92+#
93+# Ubuntu System Tests
94+# Copyright (C) 2018 Canonical
95+#
96+# This program is free software: you can redistribute it and/or modify
97+# it under the terms of the GNU General Public License as published by
98+# the Free Software Foundation, either version 3 of the License, or
99+# (at your option) any later version.
100+#
101+# This program is distributed in the hope that it will be useful,
102+# but WITHOUT ANY WARRANTY; without even the implied warranty of
103+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104+# GNU General Public License for more details.
105+#
106+# You should have received a copy of the GNU General Public License
107+# along with this program. If not, see <http://www.gnu.org/licenses/>.
108+#
109+
110+"""This script is copied to target and executed to perform enable proposed archive."""
111+
112+import subprocess
113+
114+import logging
115+
116+import os
117+
118+logger = logging.getLogger(__name__)
119+logger.setLevel(logging.INFO)
120+
121+
122+def enable_proposed():
123+ release_code_name = get_release_code_name()
124+ proposed = 'deb http://archive.ubuntu.com/ubuntu/ ' \
125+ '{}-proposed restricted main multiverse universe\n'.format(release_code_name)
126+ if not os.path.exists('/etc/apt/sources.list.d/proposed.list'):
127+ with open('/etc/apt/sources.list.d/proposed.list', 'w') as _f:
128+ _f.write(proposed)
129+ with open('/etc/apt/preferences.d/proposed-updates', 'w') as _f:
130+ _f.write('Package: *\n')
131+ _f.write('Pin: release a={}-proposed\n'.format(release_code_name))
132+ _f.write('Pin-Priority: 400\n')
133+
134+
135+def get_release_code_name():
136+ try:
137+ return subprocess.check_output(['lsb_release',
138+ '-c'],
139+ universal_newlines=True).strip().split('\t')[1]
140+ except subprocess.CalledProcessError:
141+ logger.error('Cannot get current release in target')
142+ raise
143+
144+
145+if __name__ == '__main__':
146+ enable_proposed()
147
148=== modified file 'ubuntu_system_tests/host/targets.py'
149--- ubuntu_system_tests/host/targets.py 2017-11-29 17:55:40 +0000
150+++ ubuntu_system_tests/host/targets.py 2018-03-23 12:23:17 +0000
151@@ -160,10 +160,10 @@
152 result.status = 1
153 return result
154
155- def _push_setup_script(self):
156+ def push_setup_script(self, script='target_setup.py'):
157 src = os.path.join(
158- os.path.dirname(os.path.realpath(__file__)), 'target_setup.py')
159- dst = os.path.join('/tmp/target_setup.py')
160+ os.path.dirname(os.path.realpath(__file__)), script)
161+ dst = os.path.join('/tmp/{}'.format(script))
162 self.put(src, dst)
163 if self.run_sudo('chmod 744 {}'.format(dst)).status:
164 raise RuntimeError(
165@@ -178,7 +178,7 @@
166 self.put(src, '/tmp/target_config.json')
167
168 def _run_target_setup(self):
169- self._push_setup_script()
170+ self.push_setup_script()
171 self._push_setup_config()
172 command = '/usr/bin/python3 /tmp/target_setup.py --config_path /tmp/target_config.json ' \
173 '--username %s' % self.config_stack.get('device_username')
174
175=== modified file 'ubuntu_system_tests/selftests/utils.py'
176--- ubuntu_system_tests/selftests/utils.py 2017-03-06 16:56:01 +0000
177+++ ubuntu_system_tests/selftests/utils.py 2018-03-23 12:23:17 +0000
178@@ -109,14 +109,14 @@
179 config_section=config.KEY_DEFAULT, network_ready=False, verbose=False,
180 cache_deps=False, dist_upgrade=False, install_tests=False,
181 update_apt=False, silent=False, headless=False, img=None,
182- suites=None, filters=None, ppa=None, ip=None, port=None):
183+ suites=None, filters=None, ppa=None, ip=None, port=None, install_packages=None):
184 suites = suites or []
185 return Namespace(
186 command=command, config=config, config_section=config_section,
187 network_ready=network_ready, verbose=verbose, cache_deps=cache_deps,
188 dist_upgrade=dist_upgrade, install_tests=install_tests,
189 update_apt=update_apt, silent=silent, suites=suites, filters=filters,
190- ppa=ppa, headless=headless, img=img, ip=ip, port=port)
191+ ppa=ppa, headless=headless, img=img, ip=ip, port=port, install_packages=install_packages)
192
193
194 def set_uniq_cwd(test, prefix=None):

Subscribers

People subscribed via source and target branches