~pwlars/ubuntu-test-cases/krillin-recovery

« back to all changes in this revision

Viewing changes to scripts/run-smoke

  • Committer: Andy Doan
  • Date: 2014-01-07 17:56:16 UTC
  • Revision ID: andy.doan@canonical.com-20140107175616-hazstr3a5x75d021
add ability to optionally update the dashboard in realtime

if the right combination of environment variables are provided to
this script then we'll update the dashboard with realtime status
of a smoke run.

Variables needed by a job to enable this are:

  DASHBOARD_HOST
  DASHBOARD_USER
  DASHBOARD_KEY

Optional values are:

  DASHBOARD_PORT
  DASHBOARD_PREFIX

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import shutil
7
7
import subprocess
8
8
 
 
9
import yaml
 
10
 
 
11
from phabletutils.environment import detect_device
 
12
 
 
13
import dashboard
9
14
import statsd
10
15
 
11
16
log = logging.getLogger()
12
17
script_dir = os.path.dirname(__file__)
13
18
res_dir = os.path.join(os.getcwd(), 'clientlogs')
14
19
 
 
20
dashboard_api = dashboard.API()
 
21
 
15
22
 
16
23
class SerialAction(argparse.Action):
17
24
    def __call__(self, parser, namespace, values, option_string=None):
148
155
            exit(1)
149
156
 
150
157
 
 
158
def _image_info():
 
159
    info = subprocess.check_output(['adb', 'shell', 'system-image-cli', '-i'])
 
160
    v_ver = u_ver = d_ver = channel = None
 
161
    for line in info.split('\n'):
 
162
        if not line.strip():
 
163
            continue
 
164
        key, val = line.split(':', 1)
 
165
        if key == 'version version':
 
166
            v_ver = val.strip()
 
167
        elif key == 'version ubuntu':
 
168
            u_ver = val.strip()
 
169
        elif key == 'version device':
 
170
            d_ver = val.strip()
 
171
        elif key == 'channel':
 
172
            channel = val.strip()
 
173
    ver = '%s:%s:%s' % (v_ver, u_ver, d_ver)
 
174
    return ver, channel
 
175
 
 
176
 
151
177
def _assert_image(args):
152
178
    log.info('checking if device has proper image ...')
153
179
    os.environ['INSTALL_URL'] = args.install_url
177
203
        _run(cargs)
178
204
 
179
205
 
180
 
def _test_autopilot(args):
 
206
def _test_autopilot(args, build, image):
181
207
    if args.app:
 
208
        os.environ['DASHBOARD_BUILD'] = build
 
209
        os.environ['DASHBOARD_IMAGE'] = image
182
210
        cargs = [os.path.join(script_dir, 'run-autopilot-tests.sh')]
183
211
        for app in args.app:
184
212
            cargs.extend(['-a', app])
186
214
            _run(cargs)
187
215
 
188
216
 
189
 
def _test_utah(args):
 
217
def _sync_results(build, image, test, fname):
 
218
    with open(fname) as f:
 
219
        d = yaml.safe_load(f)
 
220
        dashboard_api.result_syncing(
 
221
            image, build, test, d['passes'], d['failures'], d['errors'])
 
222
 
 
223
 
 
224
def _test_utah(args, build, image):
190
225
    if args.test:
191
226
        cargs = [os.path.join(script_dir, 'jenkins.sh')]
192
227
        with statsd.time_it('TESTS'):
193
228
            for test in args.test:
194
229
                os.environ['RESDIR'] = os.path.join(res_dir, test)
 
230
                dashboard_api.result_running(image, build, test)
195
231
                _run(cargs + ['-a', test], ignore_error=True)
 
232
                fname = os.path.join(res_dir, test, 'utah.yaml')
 
233
                _sync_results(build, image, test, fname)
 
234
 
 
235
 
 
236
def _image_add(args):
 
237
    build_number, channel = _image_info()
 
238
    release = channel.split('-')[0]
 
239
    return dashboard_api.image_add(
 
240
        build_number, release, args.image_type, detect_device(None), 'ubuntu')
196
241
 
197
242
 
198
243
def main(args):
202
247
            shutil.rmtree(res_dir)
203
248
        os.mkdir(res_dir)
204
249
 
 
250
        job_name = os.environ['JOB_NAME']
 
251
        job_number = os.environ['BUILD_NUMBER']
 
252
        build = dashboard_api.build_add(job_name, job_number)
 
253
 
205
254
        if args.install_url:
206
255
            _assert_image(args)
207
256
        else:
208
257
            _provision(args)
209
258
 
210
 
        _test_autopilot(args)
211
 
 
212
 
        _test_utah(args)
 
259
        # TODO - this should be incororated into provision and assert_image
 
260
        # so that the status is updated *before* flashing rather than after
 
261
        image = _image_add(args)
 
262
 
 
263
        if args.test:
 
264
            for x in args.test:
 
265
                dashboard_api.result_queue(image, build, x)
 
266
        if args.app:
 
267
            for x in args.app:
 
268
                dashboard_api.result_queue(image, build, x)
 
269
 
 
270
        _test_autopilot(args, build, image)
 
271
 
 
272
        _test_utah(args, build, image)
213
273
 
214
274
    return 0
215
275
 
217
277
if __name__ == '__main__':
218
278
    logging.basicConfig(level=logging.INFO)
219
279
    log.name = 'run-smoke'
 
280
    dashboard.log = logging.getLogger('dashboard')
220
281
 
221
282
    args = _get_parser().parse_args()
222
283
    if not _assert_args(args):