blob: bff7ef1b1ff539b14f95e1f0889f7e128005e51b [file] [log] [blame]
Chris Masone859fdec2012-01-30 08:38:09 -08001# 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"""
6The job module contains the objects and methods used to
7manage jobs in Autotest.
8
9The valid actions are:
10list: lists job(s)
11create: create a job
12abort: abort job(s)
13stat: detailed listing of job(s)
14
15The common options are:
16
17See topic_common.py for a High Level Design and Algorithm.
18"""
19
20from autotest_lib.cli import topic_common, action_common
21
22
23class site_suite(topic_common.atest):
24 """Suite class
25 atest suite [create] [options]"""
26 usage_action = '[create]'
27 topic = msg_topic = 'suite'
28 msg_items = ''
29
30
31class site_suite_help(site_suite):
32 """Just here to get the atest logic working.
33 Usage is set by its parent"""
34 pass
35
36
37class site_suite_create(action_common.atest_create, site_suite):
38 """Class containing the code for creating a suite."""
39 msg_items = 'suite_id'
40
41 def __init__(self):
42 super(site_suite_create, self).__init__()
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 Masone62579122012-03-08 15:18:43 -080052 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 Millerf43d0eb2012-10-01 13:43:13 -070058 self.parser.add_option('-f', '--file_bugs', default=False,
59 help='File bugs on test failures.',
60 action='store_true', metavar='FILE_BUGS')
Chris Masone46d0eb12012-07-27 18:56:39 -070061 self.parser.add_option('-n', '--num',
62 help='Number of machines to schedule across.',
63 metavar='NUM')
Chris Masonefc96a682012-02-23 13:28:30 -080064 self.parser.add_option('-p', '--pool', help='Pool of machines to use.',
65 metavar='POOL')
Chris Masone859fdec2012-01-30 08:38:09 -080066
67
68 def parse(self):
69 board_info = topic_common.item_parse_info(attribute_name='board',
70 inline_option='board')
71 build_info = topic_common.item_parse_info(attribute_name='build',
72 inline_option='build')
Chris Masone62579122012-03-08 15:18:43 -080073 pool_info = topic_common.item_parse_info(attribute_name='pool',
74 inline_option='pool')
Chris Masone46d0eb12012-07-27 18:56:39 -070075 num_info = topic_common.item_parse_info(attribute_name='num',
76 inline_option='num')
Chris Masone62579122012-03-08 15:18:43 -080077 check_info = topic_common.item_parse_info(attribute_name='check_hosts',
78 inline_option='check_hosts')
Alex Millerf43d0eb2012-10-01 13:43:13 -070079 bugs_info = topic_common.item_parse_info(attribute_name='file_bugs',
80 inline_option='file_bugs')
Chris Masone859fdec2012-01-30 08:38:09 -080081 suite_info = topic_common.item_parse_info(attribute_name='name',
82 use_leftover=True)
83
Chris Masone62579122012-03-08 15:18:43 -080084 options, leftover = site_suite.parse(
85 self,
Chris Masone46d0eb12012-07-27 18:56:39 -070086 [suite_info, board_info, build_info, pool_info, num_info,
Alex Millerf43d0eb2012-10-01 13:43:13 -070087 check_info, bugs_info],
Chris Masone62579122012-03-08 15:18:43 -080088 req_items='name')
Chris Masone859fdec2012-01-30 08:38:09 -080089 self.data = {}
90 name = getattr(self, 'name')
91 if len(name) > 1:
92 self.invalid_syntax('Too many arguments specified, only expected '
93 'to receive suite name: %s' % name)
94 self.data['suite_name'] = name[0]
Chris Masonefc96a682012-02-23 13:28:30 -080095 self.data['pool'] = options.pool # None is OK.
Chris Masone46d0eb12012-07-27 18:56:39 -070096 self.data['num'] = options.num # None is OK.
Chris Masone62579122012-03-08 15:18:43 -080097 self.data['check_hosts'] = options.check_hosts
Alex Millerf43d0eb2012-10-01 13:43:13 -070098 self.data['file_bugs'] = options.file_bugs
Chris Masone859fdec2012-01-30 08:38:09 -080099 if options.board:
100 self.data['board'] = options.board
101 else:
102 self.invalid_syntax('--board is required.')
103 if options.build:
104 self.data['build'] = options.build
105 else:
106 self.invalid_syntax('--build is required.')
107
108 return options, leftover
109
110
111 def execute(self):
112 return [self.execute_rpc(op='create_suite_job', **self.data)]