Merge lp:~terceiro/lava-dispatcher/modularize-distro-support into lp:lava-dispatcher

Proposed by Antonio Terceiro
Status: Merged
Merged at revision: 580
Proposed branch: lp:~terceiro/lava-dispatcher/modularize-distro-support
Merge into: lp:lava-dispatcher
Diff against target: 257 lines (+60/-82)
8 files modified
lava_dispatcher/actions/lava_test_shell.py (+28/-57)
lava_test_shell/README (+11/-0)
lava_test_shell/distro/ubuntu/lava-install-packages (+4/-0)
lava_test_shell/distro/ubuntu/lava-installed-packages (+3/-0)
lava_test_shell/distro/ubuntu/lava-os-build (+3/-0)
lava_test_shell/lava-installed-packages (+3/-0)
lava_test_shell/lava-os-build (+3/-0)
lava_test_shell/lava-test-runner (+5/-25)
To merge this branch: bzr merge lp:~terceiro/lava-dispatcher/modularize-distro-support
Reviewer Review Type Date Requested Status
Fathi Boudra Approve
Linaro Validation Team Pending
Review via email: mp+159007@code.launchpad.net

This proposal supersedes a proposal from 2013-04-11.

Description of the change

This branch makes some changes to the dispatcher in order to ease the addition of new supported distros. I think we can improve the situation even further, but this is already a good start.

This is a pre-requisite for adding Fedora support (bug #1165999) in a more-or-less clean way.

To post a comment you must log in.
Revision history for this message
Fathi Boudra (fboudra) wrote : Posted in a previous version of this proposal

Looks good to me. +1

review: Approve
Revision history for this message
Fathi Boudra (fboudra) wrote :

+1 still :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_dispatcher/actions/lava_test_shell.py'
2--- lava_dispatcher/actions/lava_test_shell.py 2013-04-07 19:43:05 +0000
3+++ lava_dispatcher/actions/lava_test_shell.py 2013-04-15 19:40:37 +0000
4@@ -106,7 +106,7 @@
5 # to the host and turned into a bundle for submission to the dashboard.
6
7 from datetime import datetime
8-import glob
9+from glob import glob
10 import logging
11 import os
12 import pexpect
13@@ -132,38 +132,18 @@
14 from lava_dispatcher.downloader import download_image
15
16 LAVA_TEST_DIR = '%s/../../lava_test_shell' % os.path.dirname(__file__)
17-LAVA_TEST_ANDROID = '%s/lava-test-runner-android' % LAVA_TEST_DIR
18-LAVA_TEST_UBUNTU = '%s/lava-test-runner-ubuntu' % LAVA_TEST_DIR
19-LAVA_TEST_UPSTART = '%s/lava-test-runner.conf' % LAVA_TEST_DIR
20-LAVA_TEST_INITD = '%s/lava-test-runner.init.d' % LAVA_TEST_DIR
21-LAVA_TEST_SHELL = '%s/lava-test-shell' % LAVA_TEST_DIR
22-LAVA_TEST_CASE = '%s/lava-test-case' % LAVA_TEST_DIR
23-LAVA_TEST_CASE_ATTACH = '%s/lava-test-case-attach' % LAVA_TEST_DIR
24-LAVA_TEST_RUN_ATTACH = '%s/lava-test-run-attach' % LAVA_TEST_DIR
25
26-Target.android_deployment_data['lava_test_runner'] = LAVA_TEST_ANDROID
27-Target.android_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
28-Target.android_deployment_data['lava_test_case'] = LAVA_TEST_CASE
29-Target.android_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
30-Target.android_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
31+Target.android_deployment_data['distro'] = 'android'
32 Target.android_deployment_data['lava_test_sh_cmd'] = '/system/bin/mksh'
33 Target.android_deployment_data['lava_test_dir'] = '/data/lava'
34 Target.android_deployment_data['lava_test_results_part_attr'] = 'data_part_android_org'
35
36-Target.ubuntu_deployment_data['lava_test_runner'] = LAVA_TEST_UBUNTU
37-Target.ubuntu_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
38-Target.ubuntu_deployment_data['lava_test_case'] = LAVA_TEST_CASE
39-Target.ubuntu_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
40-Target.ubuntu_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
41+Target.ubuntu_deployment_data['distro'] = 'ubuntu'
42 Target.ubuntu_deployment_data['lava_test_sh_cmd'] = '/bin/bash'
43 Target.ubuntu_deployment_data['lava_test_dir'] = '/lava'
44 Target.ubuntu_deployment_data['lava_test_results_part_attr'] = 'root_part'
45
46-Target.oe_deployment_data['lava_test_runner'] = LAVA_TEST_UBUNTU
47-Target.oe_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
48-Target.oe_deployment_data['lava_test_case'] = LAVA_TEST_CASE
49-Target.oe_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
50-Target.oe_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
51+Target.oe_deployment_data['distro'] = 'oe'
52 Target.oe_deployment_data['lava_test_sh_cmd'] = '/bin/sh'
53 Target.oe_deployment_data['lava_test_dir'] = '/lava'
54 Target.oe_deployment_data['lava_test_results_part_attr'] = 'root_part'
55@@ -376,11 +356,17 @@
56 f.write('set -ex\n')
57 f.write('cd %s\n' % targetdir)
58
59- # TODO how should we handle this for Android?
60+ distro = self.context.client.target_device.deployment_data['distro']
61+
62+ # generic dependencies - must be named the same across all distros
63+ # supported by the testdef
64 deps = self.testdef['install'].get('deps', [])
65+
66+ # distro-specific dependencies
67+ deps = deps + self.testdef['install'].get('deps-' + distro, [])
68+
69 if deps:
70- f.write('sudo apt-get update\n')
71- f.write('sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q ')
72+ f.write('lava-install-packages ')
73 for dep in deps:
74 f.write('%s ' % dep)
75 f.write('\n')
76@@ -484,7 +470,6 @@
77
78 def run(self, testdef_urls=None, testdef_repos=None, timeout=-1):
79 target = self.client.target_device
80- self._assert_target(target)
81
82 testdefs_by_uuid = self._configure_target(target, testdef_urls, testdef_repos)
83
84@@ -533,26 +518,25 @@
85 return False
86
87 def _copy_runner(self, mntdir, target):
88- runner = target.deployment_data['lava_test_runner']
89- shutil.copy(runner, '%s/bin/lava-test-runner' % mntdir)
90- os.chmod('%s/bin/lava-test-runner' % mntdir, XMOD)
91-
92- shcmd = target.deployment_data['lava_test_sh_cmd']
93-
94- for key in ['lava_test_shell', 'lava_test_case_attach', 'lava_test_run_attach']:
95- fname = target.deployment_data[key]
96+ shell = target.deployment_data['lava_test_sh_cmd']
97+
98+ # Generic scripts
99+ scripts_to_copy = glob(os.path.join(LAVA_TEST_DIR, 'lava-*'))
100+
101+ # Distro-specific scripts override the generic ones
102+ distro = target.deployment_data['distro']
103+ distro_support_dir = '%s/distro/%s' % (LAVA_TEST_DIR, distro)
104+ for script in glob(os.path.join(distro_support_dir, 'lava-*')):
105+ scripts_to_copy.append(script)
106+
107+ for fname in scripts_to_copy:
108 with open(fname, 'r') as fin:
109- with open('%s/bin/%s' % (mntdir, os.path.basename(fname)), 'w') as fout:
110- fout.write("#!%s\n\n" % shcmd)
111+ foutname = os.path.basename(fname)
112+ with open('%s/bin/%s' % (mntdir, foutname), 'w') as fout:
113+ fout.write("#!%s\n\n" % shell)
114 fout.write(fin.read())
115 os.fchmod(fout.fileno(), XMOD)
116
117- tc = target.deployment_data['lava_test_case']
118- with open(tc, 'r') as fin:
119- with open('%s/bin/lava-test-case' % mntdir, 'w') as fout:
120- fout.write('#!%s\n\n' % shcmd)
121- fout.write(fin.read())
122- os.fchmod(fout.fileno(), XMOD)
123
124 def _mk_runner_dirs(self, mntdir):
125 utils.ensure_directory('%s/bin' % mntdir)
126@@ -618,16 +602,3 @@
127 with os.fdopen(fd, 'w') as f:
128 DocumentIO.dump(f, bundle)
129
130- def _assert_target(self, target):
131- """ Ensure the target has the proper deployment data required by this
132- action. This allows us to exit the action early rather than going 75%
133- through the steps before discovering something required is missing
134- """
135- if not target.deployment_data:
136- raise RuntimeError('Target includes no deployment_data')
137-
138- keys = ['lava_test_runner', 'lava_test_shell', 'lava_test_dir',
139- 'lava_test_sh_cmd']
140- for k in keys:
141- if k not in target.deployment_data:
142- raise RuntimeError('Target deployment_data missing %s' % k)
143
144=== added file 'lava_test_shell/README'
145--- lava_test_shell/README 1970-01-01 00:00:00 +0000
146+++ lava_test_shell/README 2013-04-15 19:40:37 +0000
147@@ -0,0 +1,11 @@
148+This directory contains support scripts for lava-test-shell.
149+
150+The scripts in this directory will be copied into the target device and will be
151+in $PATH during the lava-test-shell execution.
152+
153+Distribution-specific scripts can be placed in distro/$distroname, and will
154+override the ones in the top level directory. For example,
155+distro/android/lava-test-runner will be used on Android instead of the
156+lava-test-runner script present at the same directory as this README file.
157+
158+All scripts have to be named using a "lava-" suffix.
159
160=== added directory 'lava_test_shell/distro'
161=== added directory 'lava_test_shell/distro/android'
162=== renamed file 'lava_test_shell/lava-test-runner-android' => 'lava_test_shell/distro/android/lava-test-runner'
163=== added directory 'lava_test_shell/distro/ubuntu'
164=== added file 'lava_test_shell/distro/ubuntu/lava-install-packages'
165--- lava_test_shell/distro/ubuntu/lava-install-packages 1970-01-01 00:00:00 +0000
166+++ lava_test_shell/distro/ubuntu/lava-install-packages 2013-04-15 19:40:37 +0000
167@@ -0,0 +1,4 @@
168+#!/bin/sh
169+
170+sudo DEBIAN_FRONTEND=noninteractive apt-get update
171+sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q "$@"
172
173=== added file 'lava_test_shell/distro/ubuntu/lava-installed-packages'
174--- lava_test_shell/distro/ubuntu/lava-installed-packages 1970-01-01 00:00:00 +0000
175+++ lava_test_shell/distro/ubuntu/lava-installed-packages 2013-04-15 19:40:37 +0000
176@@ -0,0 +1,3 @@
177+#!/bin/sh
178+
179+dpkg-query -W -f '${status} ${package} : ${version}\n' | sed -n 's/^install ok installed/package:/p'
180
181=== added file 'lava_test_shell/distro/ubuntu/lava-os-build'
182--- lava_test_shell/distro/ubuntu/lava-os-build 1970-01-01 00:00:00 +0000
183+++ lava_test_shell/distro/ubuntu/lava-os-build 2013-04-15 19:40:37 +0000
184@@ -0,0 +1,3 @@
185+#!/bin/sh
186+
187+cat /etc/lsb-release | grep DESCRIPTION | cut -d\" -f2
188
189=== added file 'lava_test_shell/lava-installed-packages'
190--- lava_test_shell/lava-installed-packages 1970-01-01 00:00:00 +0000
191+++ lava_test_shell/lava-installed-packages 2013-04-15 19:40:37 +0000
192@@ -0,0 +1,3 @@
193+#!/bin/sh
194+
195+echo 'Unsupported distro: cannot obtain list of installed packages'
196
197=== added file 'lava_test_shell/lava-os-build'
198--- lava_test_shell/lava-os-build 1970-01-01 00:00:00 +0000
199+++ lava_test_shell/lava-os-build 2013-04-15 19:40:37 +0000
200@@ -0,0 +1,3 @@
201+#!/bin/sh
202+
203+echo 'Unsupported distro: cannot determine build version'
204
205=== renamed file 'lava_test_shell/lava-test-runner-ubuntu' => 'lava_test_shell/lava-test-runner'
206--- lava_test_shell/lava-test-runner-ubuntu 2013-03-15 16:50:30 +0000
207+++ lava_test_shell/lava-test-runner 2013-04-15 19:40:37 +0000
208@@ -5,12 +5,6 @@
209 RESULTSDIR="/lava/results"
210 BINDIR="/lava/bin"
211
212-detect_distro() {
213- test -x /usr/bin/dpkg-query && echo "debian_based" && return
214-
215- echo "unknown"
216-}
217-
218 hwcontext()
219 {
220 mkdir -p ${RESULTSDIR}/hwcontext
221@@ -21,31 +15,17 @@
222 [ -f ${meminfo} ] || cat /proc/meminfo > ${meminfo}
223 }
224
225-unknown_swcontext() {
226- mkdir -p ${RESULTSDIR}/swcontext
227- build=${RESULTSDIR}/swcontext/build.txt
228- pkgs=${RESULTSDIR}/swcontext/pkgs.txt
229-
230- # we don't know about the software context
231- echo 'Unsupported distro: cannot determine build version' > "$build"
232- echo 'Unsupported distro: cannot obtain list of installed packages' > "$pkgs"
233-}
234-
235-debian_based_swcontext()
236+swcontext()
237 {
238 mkdir -p ${RESULTSDIR}/swcontext
239 build=${RESULTSDIR}/swcontext/build.txt
240 pkgs=${RESULTSDIR}/swcontext/pkgs.txt
241
242- [ -f ${build} ] || cat /etc/lsb-release | grep DESCRIPTION | cut -d\" -f2 > ${build}
243- # this does a query of installed packaged that will look similar to
244+ lava-os-build > ${build}
245+
246+ # this has to print a list of installed packages that will look similar to
247 # what android's package list does
248- [ -f ${pkgs} ] || dpkg-query -W -f '${status} ${package} : ${version}\n' | sed -n 's/^install ok installed/package:/p' > ${pkgs}
249-}
250-
251-swcontext() {
252- distro=$(detect_distro)
253- ${distro}_swcontext
254+ lava-installed-packages > ${pkgs}
255 }
256
257 cleanup()

Subscribers

People subscribed via source and target branches