Merge lp:~canonical-platform-qa/ubuntu-system-tests/qemu-build-snap into lp:ubuntu-system-tests

Proposed by Richard Huddie
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/ubuntu-system-tests/qemu-build-snap
Merge into: lp:ubuntu-system-tests
Diff against target: 314 lines (+114/-9) (has conflicts)
6 files modified
ubuntu_system_tests/host/command_line.py (+15/-0)
ubuntu_system_tests/host/preseed.cfg (+3/-0)
ubuntu_system_tests/host/qemu-scripts/qemu-setup.py (+61/-4)
ubuntu_system_tests/host/qemu-scripts/qemu-setup.service (+1/-1)
ubuntu_system_tests/host/qemu.py (+27/-2)
ubuntu_system_tests/selftests/test_qemu.py (+7/-2)
Text conflict in ubuntu_system_tests/host/command_line.py
Text conflict in ubuntu_system_tests/host/qemu-scripts/qemu-setup.py
Text conflict in ubuntu_system_tests/host/qemu.py
Text conflict in ubuntu_system_tests/selftests/test_qemu.py
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-system-tests/qemu-build-snap
Reviewer Review Type Date Requested Status
Canonical Platform QA Team Pending
Review via email: mp+319065@code.launchpad.net

Description of the change

WIP

To post a comment you must log in.

Unmerged revisions

502. By Richard Huddie

Minor fix.

501. By Richard Huddie

Fix flake8.

500. By Richard Huddie

Merge from trunk.

499. By Richard Huddie

Docstring updates.

498. By Richard Huddie

Fix existing self tests.

497. By Richard Huddie

Add a json config file to use with qemu-setup which controls whether to install unity8 as snap.

496. By Richard Huddie

Add snap option and create qemu-setup-config.json.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_system_tests/common/config.py'
2=== modified file 'ubuntu_system_tests/host/command_line.py'
3--- ubuntu_system_tests/host/command_line.py 2017-02-24 14:02:45 +0000
4+++ ubuntu_system_tests/host/command_line.py 2017-03-06 13:53:57 +0000
5@@ -113,6 +113,7 @@
6 OPTION_QEMU_ISO_PATH = Option(
7 ['--iso', '-i'],
8 {'help': 'Path to local iso file to install into QEMU image.'})
9+<<<<<<< TREE
10 OPTION_QEMU_NO_OVERLAY = Option(
11 ['--no-overlay', '-o'],
12 {'action': 'store_true',
13@@ -122,6 +123,14 @@
14 'be launched with a temporary overlay image to prevent any '
15 'persistent changes being made to the base image.',
16 'default': False})
17+=======
18+OPTION_QEMU_SNAP = Option(
19+ ['--snap'],
20+ {'action': 'store_true',
21+ 'help': 'Install unity8 session as snap into QEMU image and use as '
22+ 'default user session.',
23+ 'default': False})
24+>>>>>>> MERGE-SOURCE
25 OPTION_LIST_SUITES = Option(
26 ['suites'],
27 {'nargs': '*',
28@@ -208,6 +217,7 @@
29 OPTION_QEMU_IMG_PATH,
30 OPTION_QEMU_ISO_PATH,
31 OPTION_QEMU_HEADLESS,
32+ OPTION_QEMU_SNAP,
33 OPTION_VERBOSE,
34 ]
35
36@@ -406,8 +416,13 @@
37 iso_path = qemu_utils.download_iso(iso, arch, data_folder, max_count)
38
39 qemu.build_qemu(
40+<<<<<<< TREE
41 img_path, iso_path, cpu, ram, img_disk_size, headless, args.verbose,
42 username, password, display_name)
43+=======
44+ img_path, iso_path, cpu, ram, img_disk_size, AUTOPKGTEST_USER,
45+ AUTOPKGTEST_PASS, AUTOPKGTEST_NAME, headless, args.verbose, args.snap)
46+>>>>>>> MERGE-SOURCE
47 # Cleanup the iso cache folder. Leave image file in place as this will
48 # be used for further testing.
49 qemu_utils.clean_iso_cache_folder(data_folder, max_count)
50
51=== modified file 'ubuntu_system_tests/host/preseed.cfg'
52--- ubuntu_system_tests/host/preseed.cfg 2016-11-08 09:56:06 +0000
53+++ ubuntu_system_tests/host/preseed.cfg 2017-03-06 13:53:57 +0000
54@@ -57,6 +57,9 @@
55 ubiquity ubiquity/success_command string \
56 cp qemu-setup.py /target/usr/local/bin/qemu-setup.py; \
57 chmod 755 /target/usr/local/bin/qemu-setup.py; \
58+mkdir -p /target/usr/local/share/ubuntu-system-tests; \
59+cp qemu-setup-config.json /target/usr/local/share/ubuntu-system-tests/qemu-setup-config.json; \
60+chmod 744 /target/usr/local/share/ubuntu-system-tests/qemu-setup-config.json; \
61 cp qemu-setup.service /target/lib/systemd/system/qemu-setup.service; \
62 chmod 644 /target/lib/systemd/system/qemu-setup.service; \
63 chroot /target /bin/systemctl enable qemu-setup.service; \
64
65=== modified file 'ubuntu_system_tests/host/qemu-scripts/qemu-setup.py'
66--- ubuntu_system_tests/host/qemu-scripts/qemu-setup.py 2017-01-03 11:39:29 +0000
67+++ ubuntu_system_tests/host/qemu-scripts/qemu-setup.py 2017-03-06 13:53:57 +0000
68@@ -18,8 +18,14 @@
69 # along with this program. If not, see <http://www.gnu.org/licenses/>.
70 #
71
72+<<<<<<< TREE
73+=======
74+import dbus
75+import json
76+>>>>>>> MERGE-SOURCE
77 import os
78 import subprocess
79+import sys
80 import time
81
82 AUTOPKGTEST_NAME = 'autopkgtest.service'
83@@ -88,15 +94,41 @@
84 subprocess.check_call(['apt-get', 'install', '-y'] + packages)
85
86
87+<<<<<<< TREE
88+=======
89+def install_unity8_snap():
90+ """Run unity8-snap-install to install unity8 and application snaps."""
91+ subprocess.check_call(['unity8-snap-install'])
92+
93+
94+def upgrade_system():
95+ """Perform dist-upgrade on system."""
96+ wait_for_locks()
97+ # Add a timeout in case dist-upgrade hangs. This can happen when
98+ # updating snapd during boot process: https://launchpad.net/bugs/1621336
99+ subprocess.check_call(['apt-get', '-y', 'dist-upgrade'], timeout=600)
100+ wait_for_locks()
101+
102+
103+>>>>>>> MERGE-SOURCE
104 def create_file(path, content):
105 """Create a file with specified path and content."""
106 with open(path, 'w') as f:
107 f.write(content)
108
109
110+<<<<<<< TREE
111 def setup_root_shell_service():
112 """Setup root shell service on ttyS1 for use by autopkgtest."""
113+=======
114+def set_unity8_default_session(snap):
115+ """Set unity8 to be the default session for user login.
116+ :param snap: Whether to use unity8 snap session or default unity8 session.
117+ """
118+ session = 'unity8-snap' if snap else 'unity8'
119+>>>>>>> MERGE-SOURCE
120 create_file(
121+<<<<<<< TREE
122 AUTOPKGTEST_SERVICE,
123 '[Unit]\n'
124 'Description=autopkgtest root shell on ttyS1\n'
125@@ -111,6 +143,11 @@
126 'SuccessExitStatus=0 208 SIGHUP SIGINT SIGTERM SIGPIPE\n\n'
127 '[Install]\n'
128 'WantedBy=multi-user.target\n'
129+=======
130+ '/etc/lightdm/lightdm.conf',
131+ '[Seat:*]\n'
132+ 'user-session={}\n'.format(session)
133+>>>>>>> MERGE-SOURCE
134 )
135 os.chmod(AUTOPKGTEST_SERVICE, 0o644)
136 subprocess.check_call(['systemctl', 'enable', AUTOPKGTEST_NAME])
137@@ -197,11 +234,27 @@
138 subprocess.call(['shutdown', '--poweroff', '0'])
139
140
141-def do_setup():
142- """Complete first boot setup actions."""
143+def do_setup(config):
144+ """Complete first boot setup actions.
145+ :param config: Setup config dictionary.
146+ """
147 wait_for_network()
148 setup_serial_console()
149+<<<<<<< TREE
150 install_packages(['openssh-server'])
151+=======
152+ add_overlay_ppa()
153+ snap = config.get('snap', False)
154+ install_pkgs = ['openssh-server']
155+ if snap:
156+ install_packages(install_pkgs + ['unity8-session-snap'])
157+ install_unity8_snap()
158+ else:
159+ install_packages(install_pkgs + ['unity8-desktop-session'])
160+ upgrade_system()
161+ set_unity8_default_session(snap)
162+ set_auto_login()
163+>>>>>>> MERGE-SOURCE
164
165
166 def do_teardown():
167@@ -210,9 +263,13 @@
168 system_shutdown()
169
170
171-def main():
172+def main(argv=None):
173+ args = argv or sys.argv[1:]
174+ config_path = args[0]
175+ with open(config_path, 'r') as f:
176+ config = json.loads(f.read())
177 try:
178- do_setup()
179+ do_setup(config)
180 finally:
181 do_teardown()
182
183
184=== modified file 'ubuntu_system_tests/host/qemu-scripts/qemu-setup.service'
185--- ubuntu_system_tests/host/qemu-scripts/qemu-setup.service 2016-11-03 12:25:57 +0000
186+++ ubuntu_system_tests/host/qemu-scripts/qemu-setup.service 2017-03-06 13:53:57 +0000
187@@ -3,7 +3,7 @@
188
189 [Service]
190 Type=oneshot
191-ExecStart=/bin/sh -c "/usr/bin/python3 /usr/local/bin/qemu-setup.py > /dev/ttyS0 2>&1"
192+ExecStart=/bin/sh -c "/usr/bin/python3 /usr/local/bin/qemu-setup.py /usr/local/share/ubuntu-system-tests/qemu-setup-config.json > /dev/ttyS0 2>&1"
193
194 [Install]
195 WantedBy=multi-user.target
196
197=== modified file 'ubuntu_system_tests/host/qemu.py'
198--- ubuntu_system_tests/host/qemu.py 2017-02-20 19:49:08 +0000
199+++ ubuntu_system_tests/host/qemu.py 2017-03-06 13:53:57 +0000
200@@ -19,6 +19,7 @@
201 # along with this program. If not, see <http://www.gnu.org/licenses/>.
202 #
203
204+import json
205 import os
206 import shlex
207 import shutil
208@@ -170,8 +171,13 @@
209 subprocess.check_call(['wait', pid], shell=True)
210
211
212+<<<<<<< TREE
213 def build_qemu(img_path, iso_path, cpu, ram, img_disk_size, headless, verbose,
214 username, password, display_name):
215+=======
216+def build_qemu(img_path, iso_path, cpu, ram, img_disk_size, username, password,
217+ display_name, headless, verbose, snap):
218+>>>>>>> MERGE-SOURCE
219 """
220 Build a qemu image file using specified ISO file as installer.
221 :param img_path: Path of img file to use.
222@@ -180,15 +186,20 @@
223 :param ram: Amount of ram to allocate to qemu process.
224 :param img_disk_size: Maximum size of disk for img file.
225 :param headless: Whether to show installer UI during installation process.
226+<<<<<<< TREE
227 :param username: Username to setup during installation.
228 :param password: Password of user account.
229 :param display_name: Display name of user account.
230+=======
231+ :param snap: Whether to install unity8 session as snap.
232+>>>>>>> MERGE-SOURCE
233 """
234 create_disk_image(img_path, img_disk_size)
235 with TempDir() as working_dir:
236 kernel = get_kernel(iso_path)
237 extract_kernel(iso_path, kernel, working_dir.path)
238- prepare_initrd(working_dir.path, username, password, display_name)
239+ prepare_initrd(
240+ working_dir.path, username, password, display_name, snap)
241 # launch qemu with installer options to start install process
242 launch_qemu_with_image_cleanup(
243 working_dir.path, img_path, ram, cpu, headless, SERIAL_LOG,
244@@ -300,7 +311,18 @@
245 os.chmod(dst, mask)
246
247
248-def prepare_initrd(working_dir, username, password, display_name):
249+def create_setup_config(initrd_work_dir, snap):
250+ """Create json file containing setup configuration in initrd work dir.
251+ :param initrd_work_dir: Working dir to save the json file.
252+ :param snap: Whether snap or default session should be used.
253+ """
254+ config_file = os.path.join(initrd_work_dir, 'qemu-setup-config.json')
255+ config = {'snap': snap}
256+ with open(config_file, 'w') as f:
257+ f.write(json.dumps(config))
258+
259+
260+def prepare_initrd(working_dir, username, password, display_name, snap):
261 """
262 Prepare the initial ram disk. This is used to add all required custom test
263 actions to the installation process and adds the preseed file to the root
264@@ -310,6 +332,7 @@
265 :param password: Password of user account.
266 :param display_name: Display name of user account.
267 :param auto_login: Whether to enable auto login for user.
268+ :param snap: Whether snap or default session should be used.
269 :return: Path of initrd file with installer scripts added.
270 """
271 initrd_path = os.path.join(working_dir, CASPER_INITRD)
272@@ -323,6 +346,8 @@
273 ps.wait()
274 # copy the qemu scripts into initrd
275 copy_qemu_scripts_to_path(initrd_work_dir)
276+ # create the setup config file
277+ create_setup_config(initrd_work_dir, snap)
278 casper_prov = os.path.join(initrd_work_dir, 'qemu-casper-provision')
279 add_script_to_casper_setup(initrd_work_dir, casper_prov)
280 # create the preseed file
281
282=== modified file 'ubuntu_system_tests/selftests/test_qemu.py'
283--- ubuntu_system_tests/selftests/test_qemu.py 2017-02-20 19:49:08 +0000
284+++ ubuntu_system_tests/selftests/test_qemu.py 2017-03-06 13:53:57 +0000
285@@ -153,7 +153,7 @@
286 mock_check_call, mock_popen, mock_chdir, mock_mkdir):
287 with patch('builtins.open', mock_open()) as o:
288 initrd_path = qemu.prepare_initrd(
289- '/tmp/work_dir', 'user1', 'pass1', 'disp1')
290+ '/tmp/work_dir', 'user1', 'pass1', 'disp1', False)
291 self.assertEqual(
292 '/tmp/work_dir/{}'.format(qemu.CASPER_INITRD), initrd_path)
293 expected_check_calls = [
294@@ -247,14 +247,19 @@
295 mock_prepare_initrd, mock_extract_kernel, mock_get_kernel,
296 mock_create_disk_image):
297 qemu.build_qemu(
298+<<<<<<< TREE
299 '/tmp/disk.img', '/tmp/disk.iso', 3, 4096, '8G', False, False,
300 'user1', 'pass1', 'User 1')
301+=======
302+ '/tmp/disk.img', '/tmp/disk.iso', 3, 4096, '8G',
303+ 'user1', 'pass1', 'User 1', False, False, False)
304+>>>>>>> MERGE-SOURCE
305 mock_create_disk_image.assert_called_once_with('/tmp/disk.img', '8G')
306 mock_get_kernel.assert_called_once_with('/tmp/disk.iso')
307 mock_extract_kernel.assert_called_once_with(
308 '/tmp/disk.iso', '/tmp/kernel', '/tmp/12345')
309 mock_prepare_initrd.assert_called_once_with(
310- '/tmp/12345', 'user1', 'pass1', 'User 1')
311+ '/tmp/12345', 'user1', 'pass1', 'User 1', False)
312 mock_wait.assert_called_once_with('/tmp/12345')
313 launch_qemu_expected_calls = [
314 call(['/tmp/qemu', '-m', '4096', '-smp', '3', '-pidfile',

Subscribers

People subscribed via source and target branches

to all changes: