Xixuan Wu | 0722448 | 2019-04-11 18:08:19 -0700 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """This is a temporary module to help scheduling paygen suites in trampoline. |
| 6 | |
| 7 | In trampoline, paygen suites are scheduled via skylab create-test, to schedule |
| 8 | every paygen test independently, instead of creating a paygen suite via |
| 9 | skylab create-suite. |
| 10 | """ |
| 11 | |
| 12 | import re |
| 13 | |
| 14 | import common |
| 15 | |
| 16 | from autotest_lib.server.cros.dynamic_suite import control_file_getter |
| 17 | from autotest_lib.server.cros.dynamic_suite import suite_common |
| 18 | |
| 19 | |
| 20 | def is_paygen_suite(suite_name): |
| 21 | """Check if it's to run a paygen suite in trampoline.""" |
| 22 | paygen_au_regexp = 'paygen_au_*' |
| 23 | return re.match(paygen_au_regexp, suite_name) is not None |
| 24 | |
| 25 | |
| 26 | def get_paygen_tests(build, suite_name): |
| 27 | """Parse paygen tests from au control files.""" |
| 28 | if not is_paygen_suite(suite_name): |
| 29 | raise ValueError('Cannot download paygen test control files for ' |
| 30 | 'non-paygen suite %s' % suite_name) |
| 31 | |
| 32 | ds, _ = suite_common.stage_build_artifacts( |
| 33 | build, artifacts=['%s_suite' % suite_name]) |
| 34 | cf_getter = control_file_getter.DevServerGetter(build, ds) |
| 35 | tests = suite_common.retrieve_for_suite(cf_getter, suite_name) |
| 36 | return suite_common.filter_tests( |
| 37 | tests, suite_common.name_in_tag_predicate(suite_name)) |
| 38 | |
| 39 | |
| 40 | def paygen_skylab_args(test, suite_name, image, pool, board, model, |
| 41 | timeout_mins, qs_account, service_account): |
| 42 | """Form args for requesting paygen tests in skylab.""" |
| 43 | args = ['-image', image] |
| 44 | args += ['-pool', pool] |
| 45 | if board is not None: |
| 46 | args += ['-board', board] |
| 47 | |
| 48 | if model is not None: |
| 49 | args += ['-model', model] |
| 50 | |
| 51 | args += ['-timeout-mins', str(timeout_mins)] |
| 52 | |
| 53 | tags = ['skylab:run_suite_trampoline', |
| 54 | 'build:%s' % image, |
| 55 | 'suite:%s' % suite_name] |
| 56 | for t in tags: |
| 57 | args += ['-tag', t] |
| 58 | |
| 59 | keyvals = ['build:%s' % image, |
| 60 | 'suite:%s' % suite_name, |
| 61 | 'label:%s/%s/%s' % (image, suite_name, test.name)] |
| 62 | for k in keyvals: |
| 63 | args += ['-keyval', k] |
| 64 | |
| 65 | # Paygen test expects a space-separated string of name=value pairs. |
| 66 | # See http://shortn/_C8r3rC0rOP. |
| 67 | test_args = ['name=%s' % test.suite, |
| 68 | 'update_type=%s' % test.update_type, |
| 69 | 'source_release=%s' % test.source_release, |
| 70 | 'target_release=%s' % test.target_release, |
| 71 | 'target_payload_uri=%s' % test.target_payload_uri, |
| 72 | 'source_payload_uri=%s' % test.source_payload_uri, |
| 73 | 'suite=%s' % test.suite, |
| 74 | 'source_archive_uri=%s' % test.source_archive_uri] |
| 75 | args += ['-test-args', ' '.join(test_args)] |
| 76 | |
| 77 | if qs_account: |
| 78 | args += ['-qs-account', qs_account] |
| 79 | args += ['-service-account-json', service_account] |
| 80 | |
| 81 | return args + ['autoupdate_EndToEndTest'] |