blob: c461463e3cd78c26650ff26a7693ec3eb64a5dd9 [file] [log] [blame]
Alex Millerde781112013-04-27 23:50:28 -07001#!/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"""
9Usage: ./abort_suite.py [-i and -s you passed to run_suite.py]
10
11This code exists to allow buildbot to abort a HWTest run if another part of
12the build fails while HWTesting is going on. If we're going to fail the
13build anyway, there's no point in continuing to run tests.
14
15One can also pass just the build version to -i, to abort all boards running the
16suite against that version. ie. |./abort_suite.py -i R28-3993.0.0 -s dummy|
17would abort all boards running dummy on R28-3993.0.0.
18
Fang Deng63b0e452014-12-19 14:38:15 -080019To achieve better performance, this script aborts suite jobs and relies on
20autotest scheduler to aborts its subjobs instead of directly aborting subjobs.
21So only synchronous suites is supported.
22
Alex Millerde781112013-04-27 23:50:28 -070023"""
24
25
26import argparse
27import getpass
Fang Deng63b0e452014-12-19 14:38:15 -080028import logging
MK Ryu83184352014-12-10 14:59:40 -080029import os
Alex Millerde781112013-04-27 23:50:28 -070030import sys
31
32import common
33from autotest_lib.server import frontend
MK Ryu83184352014-12-10 14:59:40 -080034from autotest_lib.server import utils
Alex Millerde781112013-04-27 23:50:28 -070035
36
MK Ryu83184352014-12-10 14:59:40 -080037LOG_NAME_TEMPLATE = 'abort_suite-%s.log'
Alex Millerde781112013-04-27 23:50:28 -070038SUITE_JOB_NAME_TEMPLATE = '%s-test_suites/control.%s'
Alex Millerde781112013-04-27 23:50:28 -070039
40
41def parse_args():
42 """
43 Parse the arguments to this script.
44
45 @return The arguments to this script.
46
47 """
48 parser = argparse.ArgumentParser()
49 parser.add_argument('-s', '--suite_name', dest='name')
50 parser.add_argument('-i', '--build', dest='build')
51 return parser.parse_args()
52
53
Fang Deng63b0e452014-12-19 14:38:15 -080054def abort_suites(afe, substring):
Alex Millerde781112013-04-27 23:50:28 -070055 """
Fang Deng63b0e452014-12-19 14:38:15 -080056 Abort the suite.
Alex Millerde781112013-04-27 23:50:28 -070057
Fang Deng63b0e452014-12-19 14:38:15 -080058 This method aborts the suite jobs whose name contains |substring|.
59 Aborting a suite job will lead to all its child jobs to be aborted
60 by autotest scheduler.
61
62 @param afe: An instance of frontend.AFE to make RPCs with.
Prathmesh Prabhuf31d36c2017-04-06 10:39:56 -070063 @param substring: A string used to search for the jobs (case insensitive
64 matching).
Alex Millerde781112013-04-27 23:50:28 -070065
66 """
Fang Deng63b0e452014-12-19 14:38:15 -080067 hqe_info = afe.run('abort_host_queue_entries',
Prathmesh Prabhuf31d36c2017-04-06 10:39:56 -070068 job__name__icontains=substring, job__owner=getpass.getuser(),
Fang Deng63b0e452014-12-19 14:38:15 -080069 job__parent_job__isnull=True)
70 if hqe_info:
71 logging.info('The following suites have been aborted:\n%s', hqe_info)
72 else:
73 logging.info('No suites have been aborted. The suite jobs may have '
74 'already been aborted/completed? Note this script does '
75 'not support asynchronus suites.')
Alex Millerde781112013-04-27 23:50:28 -070076
77
78def main():
79 """Main."""
Alex Millerde781112013-04-27 23:50:28 -070080 args = parse_args()
MK Ryu83184352014-12-10 14:59:40 -080081
82 log_dir = os.path.join(common.autotest_dir, 'logs')
83 if not os.path.exists(log_dir):
84 os.makedirs(log_dir)
85 log_name = LOG_NAME_TEMPLATE % args.build.replace('/', '_')
86 log_name = os.path.join(log_dir, log_name)
87
MK Ryu2d0a3642015-01-07 15:11:19 -080088 utils.setup_logging(logfile=log_name, prefix=True)
MK Ryu83184352014-12-10 14:59:40 -080089
90 afe = frontend.AFE()
Alex Millerde781112013-04-27 23:50:28 -070091 name = SUITE_JOB_NAME_TEMPLATE % (args.build, args.name)
Ningning Xiac0c10612016-11-23 13:15:26 -080092
Fang Deng63b0e452014-12-19 14:38:15 -080093 abort_suites(afe, name)
Alex Millerde781112013-04-27 23:50:28 -070094 return 0
95
96
97if __name__ == '__main__':
98 sys.exit(main())