Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | """ |
| 6 | The job module contains the objects and methods used to |
| 7 | manage jobs in Autotest. |
| 8 | |
| 9 | The valid actions are: |
| 10 | list: lists job(s) |
| 11 | create: create a job |
| 12 | abort: abort job(s) |
| 13 | stat: detailed listing of job(s) |
| 14 | |
| 15 | The common options are: |
| 16 | |
| 17 | See topic_common.py for a High Level Design and Algorithm. |
| 18 | """ |
| 19 | |
| 20 | from autotest_lib.cli import topic_common, action_common |
| 21 | |
| 22 | |
Allen Li | b774aa2 | 2017-02-01 17:42:15 -0800 | [diff] [blame] | 23 | class suite(topic_common.atest): |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 24 | """Suite class |
| 25 | atest suite [create] [options]""" |
| 26 | usage_action = '[create]' |
| 27 | topic = msg_topic = 'suite' |
| 28 | msg_items = '' |
| 29 | |
| 30 | |
Allen Li | b774aa2 | 2017-02-01 17:42:15 -0800 | [diff] [blame] | 31 | class suite_help(suite): |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 32 | """Just here to get the atest logic working. |
| 33 | Usage is set by its parent""" |
| 34 | pass |
| 35 | |
| 36 | |
Allen Li | b774aa2 | 2017-02-01 17:42:15 -0800 | [diff] [blame] | 37 | class suite_create(action_common.atest_create, suite): |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 38 | """Class containing the code for creating a suite.""" |
| 39 | msg_items = 'suite_id' |
| 40 | |
| 41 | def __init__(self): |
Allen Li | b774aa2 | 2017-02-01 17:42:15 -0800 | [diff] [blame] | 42 | super(suite_create, self).__init__() |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 43 | |
| 44 | self.parser.add_option('-b', '--board', help='Board to test. Required.', |
| 45 | metavar='BOARD') |
| 46 | self.parser.add_option('-i', '--build', |
| 47 | help='OS image to install before running the ' |
| 48 | 'test, e.g. ' |
| 49 | 'x86-alex-release/R17-1412.144.0-a1-b115.' |
| 50 | ' Required.', |
| 51 | metavar='BUILD') |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 52 | self.parser.add_option('-c', '--check_hosts', |
| 53 | default=False, |
| 54 | help='Check that enough live hosts exist to '\ |
| 55 | 'run this suite. Default False.', |
| 56 | action='store_true', |
| 57 | metavar='CHECK_HOSTS') |
Alex Miller | f43d0eb | 2012-10-01 13:43:13 -0700 | [diff] [blame] | 58 | self.parser.add_option('-f', '--file_bugs', default=False, |
| 59 | help='File bugs on test failures.', |
| 60 | action='store_true', metavar='FILE_BUGS') |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 61 | self.parser.add_option('-n', '--num', type=int, |
Chris Masone | 46d0eb1 | 2012-07-27 18:56:39 -0700 | [diff] [blame] | 62 | help='Number of machines to schedule across.', |
| 63 | metavar='NUM') |
Chris Masone | fc96a68 | 2012-02-23 13:28:30 -0800 | [diff] [blame] | 64 | self.parser.add_option('-p', '--pool', help='Pool of machines to use.', |
| 65 | metavar='POOL') |
Dan Shi | 9512241 | 2013-11-12 16:20:33 -0800 | [diff] [blame] | 66 | self.parser.add_option('-w', '--wait_for_results', |
| 67 | default=True, |
| 68 | help=('Set to False for suite job to exit ' |
| 69 | 'without waiting for test jobs to finish. ' |
| 70 | 'Default is True.'), |
| 71 | metavar='WAIT_FOR_RESULTS') |
Dan Shi | 059261a | 2016-02-22 12:06:37 -0800 | [diff] [blame] | 72 | self.parser.add_option('-d', '--delay_minutes', type=int, default=0, |
| 73 | help=('Delay the creation of test jobs for a ' |
| 74 | 'given number of minutes. This argument ' |
| 75 | 'can be used to force provision jobs ' |
| 76 | 'being delayed, which helps to distribute ' |
| 77 | 'loads across devservers.'), |
| 78 | metavar='DELAY_MINUTES') |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 79 | |
| 80 | |
| 81 | def parse(self): |
| 82 | board_info = topic_common.item_parse_info(attribute_name='board', |
| 83 | inline_option='board') |
| 84 | build_info = topic_common.item_parse_info(attribute_name='build', |
| 85 | inline_option='build') |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 86 | pool_info = topic_common.item_parse_info(attribute_name='pool', |
| 87 | inline_option='pool') |
Chris Masone | 46d0eb1 | 2012-07-27 18:56:39 -0700 | [diff] [blame] | 88 | num_info = topic_common.item_parse_info(attribute_name='num', |
| 89 | inline_option='num') |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 90 | check_info = topic_common.item_parse_info(attribute_name='check_hosts', |
| 91 | inline_option='check_hosts') |
Alex Miller | f43d0eb | 2012-10-01 13:43:13 -0700 | [diff] [blame] | 92 | bugs_info = topic_common.item_parse_info(attribute_name='file_bugs', |
| 93 | inline_option='file_bugs') |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 94 | suite_info = topic_common.item_parse_info(attribute_name='name', |
| 95 | use_leftover=True) |
Dan Shi | 9512241 | 2013-11-12 16:20:33 -0800 | [diff] [blame] | 96 | wait_for_results_info = topic_common.item_parse_info( |
Dan Shi | 059261a | 2016-02-22 12:06:37 -0800 | [diff] [blame] | 97 | attribute_name='wait_for_results', |
| 98 | inline_option='wait_for_results') |
| 99 | delay_minutes_info = topic_common.item_parse_info( |
| 100 | attribute_name='delay_minutes', |
| 101 | inline_option='delay_minutes') |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 102 | |
Allen Li | b774aa2 | 2017-02-01 17:42:15 -0800 | [diff] [blame] | 103 | options, leftover = suite.parse( |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 104 | self, |
Chris Masone | 46d0eb1 | 2012-07-27 18:56:39 -0700 | [diff] [blame] | 105 | [suite_info, board_info, build_info, pool_info, num_info, |
Dan Shi | 059261a | 2016-02-22 12:06:37 -0800 | [diff] [blame] | 106 | check_info, bugs_info, wait_for_results_info, delay_minutes_info], |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 107 | req_items='name') |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 108 | self.data = {} |
| 109 | name = getattr(self, 'name') |
| 110 | if len(name) > 1: |
| 111 | self.invalid_syntax('Too many arguments specified, only expected ' |
| 112 | 'to receive suite name: %s' % name) |
| 113 | self.data['suite_name'] = name[0] |
Chris Masone | fc96a68 | 2012-02-23 13:28:30 -0800 | [diff] [blame] | 114 | self.data['pool'] = options.pool # None is OK. |
Chris Masone | 46d0eb1 | 2012-07-27 18:56:39 -0700 | [diff] [blame] | 115 | self.data['num'] = options.num # None is OK. |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 116 | self.data['check_hosts'] = options.check_hosts |
Alex Miller | f43d0eb | 2012-10-01 13:43:13 -0700 | [diff] [blame] | 117 | self.data['file_bugs'] = options.file_bugs |
Dan Shi | 9512241 | 2013-11-12 16:20:33 -0800 | [diff] [blame] | 118 | self.data['wait_for_results'] = options.wait_for_results |
Dan Shi | 059261a | 2016-02-22 12:06:37 -0800 | [diff] [blame] | 119 | self.data['delay_minutes'] = options.delay_minutes |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 120 | if options.board: |
| 121 | self.data['board'] = options.board |
| 122 | else: |
| 123 | self.invalid_syntax('--board is required.') |
| 124 | if options.build: |
| 125 | self.data['build'] = options.build |
| 126 | else: |
| 127 | self.invalid_syntax('--build is required.') |
| 128 | |
| 129 | return options, leftover |
| 130 | |
| 131 | |
| 132 | def execute(self): |
| 133 | return [self.execute_rpc(op='create_suite_job', **self.data)] |