Xixuan Wu | c7bf77c | 2018-04-24 12:05:40 -0700 | [diff] [blame] | 1 | # Copyright 2018 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 | """Module for CrOS dynamic test suite generation and execution.""" |
| 6 | |
| 7 | from __future__ import absolute_import |
| 8 | from __future__ import division |
| 9 | from __future__ import print_function |
| 10 | |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 11 | import contextlib |
| 12 | import itertools |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 13 | import json |
Xixuan Wu | 6c04133 | 2018-05-07 16:04:36 -0700 | [diff] [blame] | 14 | import logging |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 15 | import os |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 16 | import re |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 17 | import time |
Xixuan Wu | 6c04133 | 2018-05-07 16:04:36 -0700 | [diff] [blame] | 18 | |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 19 | from lucifer import autotest |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 20 | from skylab_suite import cros_suite |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 21 | from skylab_suite import swarming_lib |
Xixuan Wu | c7bf77c | 2018-04-24 12:05:40 -0700 | [diff] [blame] | 22 | |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 23 | |
Allen Li | 1ccca8f | 2018-08-29 12:11:06 -0700 | [diff] [blame] | 24 | SKYLAB_DRONE_SWARMING_WORKER = '/opt/infra-tools/skylab_swarming_worker' |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 25 | SKYLAB_SUITE_USER = 'skylab_suite_runner' |
| 26 | SKYLAB_TOOL = '/opt/infra-tools/skylab' |
Xixuan Wu | c7bf77c | 2018-04-24 12:05:40 -0700 | [diff] [blame] | 27 | |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 28 | SUITE_WAIT_SLEEP_INTERVAL_SECONDS = 30 |
| 29 | |
Xixuan Wu | 79d1466 | 2018-08-20 11:15:41 -0700 | [diff] [blame] | 30 | # See #5 in crbug.com/873886 for more details. |
| 31 | _NOT_SUPPORTED_DEPENDENCIES = ['skip_provision', 'cleanup-reboot', 'rpm', |
| 32 | 'modem_repair'] |
| 33 | |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 34 | |
Aviv Keshet | 3baa47b | 2019-05-22 16:24:21 -0700 | [diff] [blame] | 35 | def run_suite(test_specs, suite_handler, dry_run=False): |
| 36 | """Run a suite and wait for child results (if necessary).""" |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 37 | suite_id = os.environ.get('SWARMING_TASK_ID') |
Aviv Keshet | 73b9066 | 2019-03-28 14:01:58 -0700 | [diff] [blame] | 38 | if not suite_id: |
| 39 | raise ValueError("Unable to determine suite's task id from env var " |
| 40 | "SWARMING_TASK_ID.") |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 41 | _create_test_tasks(test_specs, suite_handler, suite_id, dry_run) |
Xixuan Wu | a79b5f7 | 2018-12-26 12:29:39 -0800 | [diff] [blame] | 42 | suite_handler.set_suite_id(suite_id) |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 43 | |
Aviv Keshet | 73b9066 | 2019-03-28 14:01:58 -0700 | [diff] [blame] | 44 | if suite_handler.should_wait(): |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 45 | _wait_for_results(suite_handler, dry_run=dry_run) |
| 46 | |
| 47 | |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 48 | def _create_test_tasks(test_specs, suite_handler, suite_id, dry_run=False): |
| 49 | """Create test tasks for a list of tests (TestSpecs). |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 50 | |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 51 | Given a list of TestSpec object, this function will schedule them on |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 52 | swarming one by one, and add them to the swarming_task_id-to-test map |
| 53 | of suite_handler to keep monitoring them. |
| 54 | |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 55 | @param test_specs: A list of cros_suite.TestSpec objects to schedule. |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 56 | @param suite_handler: A cros_suite.SuiteHandler object to monitor the |
| 57 | test_specs' progress. |
| 58 | @param suite_id: A string ID for a suite task, it's the parent task id for |
| 59 | these to-be-scheduled test_specs. |
| 60 | @param dry_run: Whether to kick off dry runs of the tests. |
| 61 | """ |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 62 | for test_spec in test_specs: |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 63 | test_task_id = _create_test_task( |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 64 | test_spec, |
Xixuan Wu | 5cb5a40 | 2018-06-04 16:37:23 -0700 | [diff] [blame] | 65 | suite_id=suite_id, |
| 66 | dry_run=dry_run) |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 67 | suite_handler.add_test_by_task_id( |
| 68 | test_task_id, |
Xixuan Wu | 9d5d703 | 2018-07-12 16:44:02 -0700 | [diff] [blame] | 69 | cros_suite.TestHandlerSpec( |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 70 | test_spec=test_spec, |
Alex Zamorzaev | 0cbec77 | 2019-04-12 16:26:54 -0700 | [diff] [blame] | 71 | remaining_retries=test_spec.test.job_retries, |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 72 | previous_retried_ids=[])) |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 73 | |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 74 | |
Aviv Keshet | ea09ac3 | 2019-04-05 15:47:44 -0700 | [diff] [blame] | 75 | def _create_test_task(test_spec, suite_id=None, dry_run=False): |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 76 | """Create a test task for a given test spec. |
Xixuan Wu | c7bf77c | 2018-04-24 12:05:40 -0700 | [diff] [blame] | 77 | |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 78 | @param test_spec: A cros_suite.TestSpec object. |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 79 | @param suite_id: the suite task id of the test. |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 80 | @param dry_run: If true, don't actually create task. |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 81 | |
| 82 | @return the swarming task id of this task. |
Xixuan Wu | c7bf77c | 2018-04-24 12:05:40 -0700 | [diff] [blame] | 83 | """ |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 84 | logging.info('Creating task for test %s', test_spec.test.name) |
Aviv Keshet | 2c25d06 | 2019-03-19 13:18:23 -0700 | [diff] [blame] | 85 | skylab_tool_path = os.environ.get('SKYLAB_TOOL', SKYLAB_TOOL) |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 86 | |
| 87 | cmd = [ |
Aviv Keshet | af01647 | 2019-08-01 13:36:36 -0700 | [diff] [blame^] | 88 | skylab_tool_path, 'create-test', '-bb=False', |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 89 | '-board', test_spec.board, |
| 90 | '-image', test_spec.build, |
Aviv Keshet | 399692f | 2019-04-02 12:17:51 -0700 | [diff] [blame] | 91 | '-service-account-json', os.environ['SWARMING_CREDS'], |
Xixuan Wu | 17dcb1d | 2019-04-19 14:33:25 -0700 | [diff] [blame] | 92 | '-priority', str(test_spec.priority), |
Aviv Keshet | f0f1b49 | 2019-04-03 15:30:48 -0700 | [diff] [blame] | 93 | '-timeout-mins', str(test_spec.execution_timeout_mins), |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 94 | ] |
Aviv Keshet | b70c709 | 2019-04-02 12:05:56 -0700 | [diff] [blame] | 95 | if _is_dev(): |
| 96 | cmd += ['-dev'] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 97 | if test_spec.pool: |
| 98 | # TODO(akeshet): Clean up this hack around pool name translation. |
| 99 | autotest_pool_label = 'pool:%s' % test_spec.pool |
| 100 | pool_dependency_value = swarming_lib.task_dependencies_from_labels( |
| 101 | [autotest_pool_label])['label-pool'] |
| 102 | cmd += ['-pool', pool_dependency_value] |
| 103 | |
| 104 | if test_spec.model: |
| 105 | cmd += ['-model', test_spec.model] |
| 106 | if test_spec.quota_account: |
| 107 | cmd += ['-qs-account', test_spec.quota_account] |
| 108 | if test_spec.test.test_type.lower() == 'client': |
| 109 | cmd += ['-client-test'] |
Aviv Keshet | 18e485f | 2019-05-02 16:04:20 -0700 | [diff] [blame] | 110 | if suite_id is not None: |
| 111 | cmd += ['-parent-task-run-id', suite_id] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 112 | |
Aviv Keshet | f0f1b49 | 2019-04-03 15:30:48 -0700 | [diff] [blame] | 113 | |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 114 | tags = _compute_tags(test_spec.build, suite_id) |
Aviv Keshet | 1df6963 | 2019-04-05 16:10:55 -0700 | [diff] [blame] | 115 | dimensions = _compute_dimensions(test_spec.test.dependencies) |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 116 | keyvals_flat = _compute_job_keyvals_flat(test_spec.keyvals, suite_id) |
| 117 | |
Aviv Keshet | d6321a1 | 2019-07-30 18:31:31 -0700 | [diff] [blame] | 118 | for dim in dimensions: |
| 119 | cmd += ['-dim', dim] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 120 | for tag in tags: |
| 121 | cmd += ['-tag', tag] |
| 122 | for keyval in keyvals_flat: |
| 123 | cmd += ['-keyval', keyval] |
| 124 | cmd += [test_spec.test.name] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 125 | |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 126 | if dry_run: |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 127 | logging.info('Would have created task with command %s', cmd) |
| 128 | return |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 129 | |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 130 | # TODO(akeshet): Avoid this late chromite import. |
| 131 | cros_build_lib = autotest.chromite_load('cros_build_lib') |
| 132 | result = cros_build_lib.RunCommand(cmd, capture_output=True) |
| 133 | # TODO(akeshet): Use -json flag and json-parse output of the command instead |
| 134 | # of regex matching to determine task_id. |
| 135 | m = re.match('.*id=(.*)$', result.output) |
| 136 | task_id = m.group(1) |
| 137 | logging.info('Created task with id %s', task_id) |
| 138 | return task_id |
Xixuan Wu | 3dea7cf | 2018-12-10 17:50:45 -0800 | [diff] [blame] | 139 | |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 140 | |
Aviv Keshet | b70c709 | 2019-04-02 12:05:56 -0700 | [diff] [blame] | 141 | # TODO(akeshet): Eliminate the need for this, by either adding an explicit |
| 142 | # swarming_server argument to skylab tool, or having the tool respect the |
| 143 | # SWARMING_SERVER environment variable. See crbug.com/948774 |
| 144 | def _is_dev(): |
| 145 | """Detect whether skylab tool should be invoked with -dev flag.""" |
Aviv Keshet | aa3839d | 2019-04-02 16:13:42 -0700 | [diff] [blame] | 146 | return 'chromium-swarm-dev' in os.environ['SWARMING_SERVER'] |
Aviv Keshet | b70c709 | 2019-04-02 12:05:56 -0700 | [diff] [blame] | 147 | |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 148 | def _compute_tags(build, suite_id): |
| 149 | tags = [ |
| 150 | 'build:%s' % build, |
| 151 | ] |
| 152 | if suite_id is not None: |
| 153 | tags += ['parent_task_id:%s' % suite_id] |
| 154 | return tags |
| 155 | |
| 156 | |
Aviv Keshet | 1df6963 | 2019-04-05 16:10:55 -0700 | [diff] [blame] | 157 | def _compute_dimensions(dependencies): |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 158 | dimensions = [] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 159 | deps = _filter_unsupported_dependencies(dependencies) |
| 160 | flattened_swarming_deps = sorted([ |
| 161 | '%s:%s' % (k, v) for |
| 162 | k, v in swarming_lib.task_dependencies_from_labels(deps).items() |
| 163 | ]) |
| 164 | dimensions += flattened_swarming_deps |
| 165 | return dimensions |
| 166 | |
| 167 | |
| 168 | def _compute_job_keyvals_flat(keyvals, suite_id): |
| 169 | # Job keyvals calculation. |
| 170 | job_keyvals = keyvals.copy() |
| 171 | if suite_id is not None: |
| 172 | # TODO(akeshet): Avoid this late autotest constants import. |
| 173 | constants = autotest.load('server.cros.dynamic_suite.constants') |
| 174 | job_keyvals[constants.PARENT_JOB_ID] = suite_id |
| 175 | keyvals_flat = sorted( |
| 176 | ['%s:%s' % (k, v) for k, v in job_keyvals.items()]) |
| 177 | return keyvals_flat |
| 178 | |
| 179 | |
| 180 | def _filter_unsupported_dependencies(dependencies): |
| 181 | """Filter out Skylab-unsupported test dependencies, with a warning.""" |
Xixuan Wu | db053c8 | 2019-01-31 20:07:06 -0800 | [diff] [blame] | 182 | deps = [] |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 183 | for dep in dependencies: |
Xixuan Wu | 79d1466 | 2018-08-20 11:15:41 -0700 | [diff] [blame] | 184 | if dep in _NOT_SUPPORTED_DEPENDENCIES: |
| 185 | logging.warning('Dependency %s is not supported in skylab', dep) |
Aviv Keshet | f095121 | 2019-03-18 14:54:32 -0700 | [diff] [blame] | 186 | else: |
| 187 | deps.append(dep) |
| 188 | return deps |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 189 | |
| 190 | |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 191 | @contextlib.contextmanager |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 192 | def disable_logging(logging_level): |
| 193 | """Context manager for disabling logging of a given logging level.""" |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 194 | try: |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 195 | logging.disable(logging_level) |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 196 | yield |
| 197 | finally: |
| 198 | logging.disable(logging.NOTSET) |
| 199 | |
| 200 | |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 201 | def _loop_and_wait_forever(suite_handler, dry_run): |
| 202 | """Wait for child tasks to finish or break.""" |
| 203 | for iterations in itertools.count(0): |
| 204 | # Log progress every 300 seconds. |
| 205 | no_logging = bool(iterations * SUITE_WAIT_SLEEP_INTERVAL_SECONDS % 300) |
| 206 | with disable_logging(logging.INFO if no_logging else logging.NOTSET): |
Xixuan Wu | c6e28d3 | 2018-08-27 14:48:14 -0700 | [diff] [blame] | 207 | suite_handler.handle_results(suite_handler.suite_id) |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 208 | if suite_handler.is_finished_waiting(): |
| 209 | break |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 210 | |
Xixuan Wu | 4d5d014 | 2018-08-27 15:26:58 -0700 | [diff] [blame] | 211 | for t in suite_handler.retried_tasks: |
| 212 | _retry_test(suite_handler, t['task_id'], dry_run=dry_run) |
| 213 | |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 214 | time.sleep(SUITE_WAIT_SLEEP_INTERVAL_SECONDS) |
Xixuan Wu | 80795c8 | 2018-06-12 11:56:17 -0700 | [diff] [blame] | 215 | |
| 216 | |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 217 | def _wait_for_results(suite_handler, dry_run=False): |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 218 | """Wait for child tasks to finish and return their results. |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 219 | |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 220 | @param suite_handler: a cros_suite.SuiteHandler object. |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 221 | """ |
| 222 | timeout_util = autotest.chromite_load('timeout_util') |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 223 | try: |
Aviv Keshet | 5ae3671 | 2019-05-16 12:42:32 -0700 | [diff] [blame] | 224 | with timeout_util.Timeout(suite_handler.timeout_mins * 60): |
Xixuan Wu | f52e40d | 2018-06-14 12:10:44 -0700 | [diff] [blame] | 225 | _loop_and_wait_forever(suite_handler, dry_run) |
| 226 | except timeout_util.TimeoutError: |
| 227 | logging.error('Timeout in waiting for child tasks.') |
| 228 | return |
Xixuan Wu | 0bea952 | 2018-05-08 17:49:19 -0700 | [diff] [blame] | 229 | |
| 230 | logging.info('Finished to wait for child tasks.') |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 231 | |
| 232 | |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 233 | def _retry_test(suite_handler, task_id, dry_run=False): |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 234 | """Retry test for a suite. |
| 235 | |
| 236 | We will execute the following actions for retrying a test: |
| 237 | 1. Schedule the test. |
| 238 | 2. Add the test with the new swarming task id to the suite's |
| 239 | retry handler, but reduce its remaining retries by 1. |
| 240 | 3. Reduce the suite-level max retries by 1. |
| 241 | 4. Remove prevous failed test from retry handler since it's not |
| 242 | actively monitored by the suite. |
| 243 | |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 244 | @param suite_handler: a cros_suite.SuiteHandler object. |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 245 | @param task_id: The swarming task id for the retried test. |
| 246 | @param dry_run: Whether to retry a dry run of the test. |
| 247 | """ |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 248 | last_retry_spec = suite_handler.get_test_by_task_id(task_id) |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 249 | logging.info('Retrying test %s, remaining %d retries.', |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 250 | last_retry_spec.test_spec.test.name, |
| 251 | last_retry_spec.remaining_retries - 1) |
Aviv Keshet | d993510 | 2019-03-18 14:44:28 -0700 | [diff] [blame] | 252 | retried_task_id = _create_test_task( |
Xixuan Wu | b60c143 | 2019-03-07 17:15:39 +0000 | [diff] [blame] | 253 | last_retry_spec.test_spec, |
| 254 | suite_id=suite_handler.suite_id, |
Xixuan Wu | b60c143 | 2019-03-07 17:15:39 +0000 | [diff] [blame] | 255 | dry_run=dry_run) |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 256 | previous_retried_ids = last_retry_spec.previous_retried_ids + [task_id] |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 257 | suite_handler.add_test_by_task_id( |
| 258 | retried_task_id, |
Xixuan Wu | 9d5d703 | 2018-07-12 16:44:02 -0700 | [diff] [blame] | 259 | cros_suite.TestHandlerSpec( |
Xixuan Wu | 5811e83 | 2018-07-12 11:56:24 -0700 | [diff] [blame] | 260 | test_spec=last_retry_spec.test_spec, |
| 261 | remaining_retries=last_retry_spec.remaining_retries - 1, |
Xixuan Wu | 9af95a2 | 2018-05-18 10:46:42 -0700 | [diff] [blame] | 262 | previous_retried_ids=previous_retried_ids)) |
| 263 | suite_handler.set_max_retries(suite_handler.max_retries - 1) |
| 264 | suite_handler.remove_test_by_task_id(task_id) |
Xixuan Wu | 7a450c5 | 2018-07-20 15:07:51 -0700 | [diff] [blame] | 265 | |
| 266 | |
| 267 | def _convert_dict_to_string(input_dict): |
| 268 | """Convert dictionary to a string. |
| 269 | |
| 270 | @param input_dict: A dictionary. |
| 271 | """ |
| 272 | for k, v in input_dict.iteritems(): |
| 273 | if isinstance(v, dict): |
| 274 | input_dict[k] = _convert_dict_to_string(v) |
| 275 | else: |
| 276 | input_dict[k] = str(v) |
| 277 | |
| 278 | return json.dumps(input_dict) |