Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 1 | #!/usr/bin/python -t |
| 2 | # |
| 3 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | |
| 8 | """ |
| 9 | Usage: ./abort_suite.py [-i and -s you passed to run_suite.py] |
| 10 | |
| 11 | This code exists to allow buildbot to abort a HWTest run if another part of |
| 12 | the build fails while HWTesting is going on. If we're going to fail the |
| 13 | build anyway, there's no point in continuing to run tests. |
| 14 | |
| 15 | One can also pass just the build version to -i, to abort all boards running the |
| 16 | suite against that version. ie. |./abort_suite.py -i R28-3993.0.0 -s dummy| |
| 17 | would abort all boards running dummy on R28-3993.0.0. |
| 18 | |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 19 | To achieve better performance, this script aborts suite jobs and relies on |
| 20 | autotest scheduler to aborts its subjobs instead of directly aborting subjobs. |
| 21 | So only synchronous suites is supported. |
| 22 | |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 23 | """ |
| 24 | |
| 25 | |
| 26 | import argparse |
| 27 | import getpass |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 28 | import logging |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 29 | import os |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 30 | import sys |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 31 | from datetime import datetime |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 32 | |
| 33 | import common |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 34 | from autotest_lib.client.common_lib.cros.graphite import stats |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 35 | from autotest_lib.server import frontend |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 36 | from autotest_lib.server import utils |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 37 | |
| 38 | |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 39 | LOG_NAME_TEMPLATE = 'abort_suite-%s.log' |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 40 | SUITE_JOB_NAME_TEMPLATE = '%s-test_suites/control.%s' |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 41 | _timer = stats.Timer('abort_suites') |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 42 | |
| 43 | |
| 44 | def parse_args(): |
| 45 | """ |
| 46 | Parse the arguments to this script. |
| 47 | |
| 48 | @return The arguments to this script. |
| 49 | |
| 50 | """ |
| 51 | parser = argparse.ArgumentParser() |
| 52 | parser.add_argument('-s', '--suite_name', dest='name') |
| 53 | parser.add_argument('-i', '--build', dest='build') |
| 54 | return parser.parse_args() |
| 55 | |
| 56 | |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 57 | @_timer.decorate |
| 58 | def abort_suites(afe, substring): |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 59 | """ |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 60 | Abort the suite. |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 61 | |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 62 | This method aborts the suite jobs whose name contains |substring|. |
| 63 | Aborting a suite job will lead to all its child jobs to be aborted |
| 64 | by autotest scheduler. |
| 65 | |
| 66 | @param afe: An instance of frontend.AFE to make RPCs with. |
| 67 | @param substring: A string used to search for the jobs. |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 68 | |
| 69 | """ |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 70 | hqe_info = afe.run('abort_host_queue_entries', |
| 71 | job__name__contains=substring, job__owner=getpass.getuser(), |
| 72 | job__parent_job__isnull=True) |
| 73 | if hqe_info: |
| 74 | logging.info('The following suites have been aborted:\n%s', hqe_info) |
| 75 | else: |
| 76 | logging.info('No suites have been aborted. The suite jobs may have ' |
| 77 | 'already been aborted/completed? Note this script does ' |
| 78 | 'not support asynchronus suites.') |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 79 | |
| 80 | |
| 81 | def main(): |
| 82 | """Main.""" |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 83 | args = parse_args() |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 84 | |
| 85 | log_dir = os.path.join(common.autotest_dir, 'logs') |
| 86 | if not os.path.exists(log_dir): |
| 87 | os.makedirs(log_dir) |
| 88 | log_name = LOG_NAME_TEMPLATE % args.build.replace('/', '_') |
| 89 | log_name = os.path.join(log_dir, log_name) |
| 90 | |
MK Ryu | 2d0a364 | 2015-01-07 15:11:19 -0800 | [diff] [blame^] | 91 | utils.setup_logging(logfile=log_name, prefix=True) |
MK Ryu | 8318435 | 2014-12-10 14:59:40 -0800 | [diff] [blame] | 92 | |
| 93 | afe = frontend.AFE() |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 94 | name = SUITE_JOB_NAME_TEMPLATE % (args.build, args.name) |
Fang Deng | 63b0e45 | 2014-12-19 14:38:15 -0800 | [diff] [blame] | 95 | abort_suites(afe, name) |
Alex Miller | de78111 | 2013-04-27 23:50:28 -0700 | [diff] [blame] | 96 | return 0 |
| 97 | |
| 98 | |
| 99 | if __name__ == '__main__': |
| 100 | sys.exit(main()) |