blob: 2279407a3f0bac69e8513149e7ad0f738a7887ac [file] [log] [blame]
mbligh0a669132008-10-10 20:02:32 +00001#!/usr/bin/python -u
mblighbe630eb2008-08-01 16:41:48 +00002#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
mblighfb8f0ab2008-11-13 01:11:48 +00005
mblighbe630eb2008-08-01 16:41:48 +00006"""Tests for job."""
7
Richard Barnette41e617b2016-05-19 16:18:16 -07008# pylint: disable=missing-docstring
9
10import copy, getpass, unittest, sys
mblighbe630eb2008-08-01 16:41:48 +000011
12import common
Richard Barnette41e617b2016-05-19 16:18:16 -070013from autotest_lib.cli import cli_mock, job
showard53cb10c2009-05-01 00:09:36 +000014from autotest_lib.client.common_lib.test_utils import mock
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070015from autotest_lib.client.common_lib import control_data
Allen Li352b86a2016-12-14 12:11:27 -080016from autotest_lib.client.common_lib import priorities
mblighbe630eb2008-08-01 16:41:48 +000017
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070018CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
19SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
mblighbe630eb2008-08-01 16:41:48 +000020
21class job_unittest(cli_mock.cli_unittest):
22 def setUp(self):
23 super(job_unittest, self).setUp()
mblighbe630eb2008-08-01 16:41:48 +000024 self.values = copy.deepcopy(self.values_template)
25
26 results = [{u'status_counts': {u'Aborted': 1},
27 u'control_file':
28 u"job.run_test('sleeptest')\n",
29 u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070030 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000031 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -080032 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000033 u'owner': u'user0',
34 u'created_on':
35 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +000036 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +000037 u'id': 180},
38 {u'status_counts': {u'Queued': 1},
39 u'control_file':
40 u"job.run_test('sleeptest')\n",
41 u'name': u'test_job1',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070042 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000043 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -080044 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000045 u'owner': u'user0',
46 u'created_on':
47 u'2008-07-08 12:17:47',
48 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +000049 u'id': 338}]
50
51
52 values_template = [{u'id': 180, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080053 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000054 u'name': u'test_job0',
55 u'owner': u'Cringer',
mbligh0887d402009-01-30 00:50:29 +000056 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000057 u'created_on': u'2008-07-02 13:02:40',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070058 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000059 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000060 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000061 {u'id': 338, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080062 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000063 u'name': u'test_job1',
64 u'owner': u'Fisto',
mbligh0887d402009-01-30 00:50:29 +000065 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000066 u'created_on': u'2008-07-06 14:05:33',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070067 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000068 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000069 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000070 {u'id': 339, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080071 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000072 u'name': u'test_job2',
73 u'owner': u'Roboto',
mbligh0887d402009-01-30 00:50:29 +000074 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000075 u'created_on': u'2008-07-07 15:33:18',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070076 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000077 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000078 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000079 {u'id': 340, # Invalid job priority
Allen Li352b86a2016-12-14 12:11:27 -080080 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000081 u'name': u'test_job3',
82 u'owner': u'Panthor',
mbligh0887d402009-01-30 00:50:29 +000083 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000084 u'created_on': u'2008-07-04 00:00:01',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070085 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000086 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000087 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000088 {u'id': 350, # Invalid job created_on
Allen Li352b86a2016-12-14 12:11:27 -080089 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000090 u'name': u'test_job4',
91 u'owner': u'Icer',
mbligh0887d402009-01-30 00:50:29 +000092 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000093 u'created_on': u'Today',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070094 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000095 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000096 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000097 {u'id': 420, # Invalid job control_type
98 u'priority': 'Urgent',
99 u'name': u'test_job5',
100 u'owner': u'Spikor',
mbligh0887d402009-01-30 00:50:29 +0000101 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000102 u'created_on': u'2012-08-08 18:54:37',
103 u'control_type': u'Child',
104 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +0000105 u'synch_count': 2}]
mblighbe630eb2008-08-01 16:41:48 +0000106
107
108class job_list_unittest(job_unittest):
109 def test_job_list_jobs(self):
showardf4a68992010-02-03 20:29:59 +0000110 self.god.stub_function(getpass, 'getuser')
mblighbe630eb2008-08-01 16:41:48 +0000111 getpass.getuser.expect_call().and_return('user0')
mbligha212d712009-02-11 01:22:36 +0000112 self.run_cmd(argv=['atest', 'job', 'list', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000113 rpcs=[('get_jobs_summary', {'owner': 'user0',
114 'running': None},
115 True, self.values)],
116 out_words_ok=['test_job0', 'test_job1', 'test_job2'],
117 out_words_no=['Uber', 'Today', 'Child'])
118
119
120 def test_job_list_jobs_only_user(self):
121 values = [item for item in self.values if item['owner'] == 'Cringer']
mbligha212d712009-02-11 01:22:36 +0000122 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer',
123 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000124 rpcs=[('get_jobs_summary', {'owner': 'Cringer',
125 'running': None},
126 True, values)],
127 out_words_ok=['Cringer'],
128 out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
129 'Spikor'])
130
131
132 def test_job_list_jobs_all(self):
mbligha212d712009-02-11 01:22:36 +0000133 self.run_cmd(argv=['atest', 'job', 'list', '--all',
134 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000135 rpcs=[('get_jobs_summary', {'running': None},
136 True, self.values)],
137 out_words_ok=['Fisto', 'Roboto', 'Panthor',
138 'Icer', 'Spikor', 'Cringer'],
139 out_words_no=['Created', 'Priority'])
140
141
142 def test_job_list_jobs_id(self):
mbligha212d712009-02-11 01:22:36 +0000143 self.run_cmd(argv=['atest', 'job', 'list', '5964',
144 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000145 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
146 'running': None},
147 True,
148 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700149 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
mblighbe630eb2008-08-01 16:41:48 +0000150 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700151 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000152 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800153 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000154 u'owner': u'user0',
155 u'created_on': u'2008-07-28 12:42:52',
156 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000157 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000158 u'id': 5964}])],
159 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700160 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000161
162
163 def test_job_list_jobs_id_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000164 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v',
165 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000166 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
167 'running': None},
168 True,
169 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700170 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
mblighbe630eb2008-08-01 16:41:48 +0000171 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700172 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000173 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800174 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000175 u'owner': u'user0',
176 u'created_on': u'2008-07-28 12:42:52',
177 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000178 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000179 u'id': 5964}])],
180 out_words_ok=['user0', 'Completed', '1', '5964',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700181 CLIENT, '2008', 'Priority'],
mblighbe630eb2008-08-01 16:41:48 +0000182 out_words_no=['sleeptest'])
183
184
185 def test_job_list_jobs_name(self):
mbligha212d712009-02-11 01:22:36 +0000186 self.run_cmd(argv=['atest', 'job', 'list', 'myt*',
187 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000188 rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
189 'running': None},
190 True,
191 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700192 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
mblighbe630eb2008-08-01 16:41:48 +0000193 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700194 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000195 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800196 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000197 u'owner': u'user0',
198 u'created_on': u'2008-07-28 12:42:52',
199 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000200 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000201 u'id': 5964}])],
202 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700203 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000204
205
206 def test_job_list_jobs_all_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000207 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose',
208 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000209 rpcs=[('get_jobs_summary', {'running': None},
210 True, self.values)],
211 out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
212 'Created'])
213
214
showard53cb10c2009-05-01 00:09:36 +0000215class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +0000216 def test_job_list_jobs_all_and_user(self):
217 testjob = job.job_list()
mbligha212d712009-02-11 01:22:36 +0000218 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0',
219 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000220 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000221 (sys.exit.expect_call(mock.anything_comparator())
222 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000223 self.assertRaises(cli_mock.ExitException, testjob.parse)
224 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000225 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000226
227
228class job_stat_unittest(job_unittest):
229 def test_job_stat_job(self):
230 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000231 self.run_cmd(argv=['atest', 'job', 'stat', '180',
232 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000233 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
234 [results[0]]),
235 ('get_host_queue_entries', {'job__in': ['180']},
236 True,
237 [{u'status': u'Failed',
238 u'complete': 1,
239 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000240 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000241 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000242 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000243 u'id': 4432,
244 u'synch_id': None},
245 u'priority': 1,
246 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000247 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000248 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700249 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000250 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800251 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000252 u'owner': u'user0',
253 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000254 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000255 u'id': 180},
256 u'active': 0,
257 u'id': 101084}])],
258 out_words_ok=['test_job0', 'host0', 'Failed',
259 'Aborted'])
260
261
mblighfca5ed12009-11-06 02:59:56 +0000262
263 def test_job_stat_list_unassigned_host(self):
264 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
265 '--list-hosts', '--ignore_site_file'],
266 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
267 [{u'status_counts': {u'Queued': 1},
268 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
269 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700270 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000271 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800272 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000273 u'owner': u'user0',
274 u'created_on': u'2008-07-30 22:15:43',
275 u'timeout': 144,
276 u'synch_count': 1,
277 u'id': 6761}]),
278 ('get_host_queue_entries', {'job__in': ['6761']},
279 True,
280 [{u'status': u'Queued',
281 u'complete': 0,
282 u'deleted': 0,
283 u'host': None,
284 u'priority': 1,
285 u'meta_host': u'Xeon',
286 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
287 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700288 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000289 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800290 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000291 u'owner': u'user0',
292 u'created_on': u'2008-07-30 22:15:43',
293 u'timeout': 144,
294 u'synch_count': 1,
295 u'id': 6761},
296 u'active': 0,
297 u'id': 193166} ])],
298 err_words_ok=['unassigned', 'meta-hosts'],
299 out_words_no=['Xeon'])
300
301
302 def test_job_stat_list_hosts(self):
303 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
304 '--list-hosts', '--ignore_site_file'],
305 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
306 [{u'status_counts': {u'Queued': 1},
307 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
308 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700309 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000310 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800311 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000312 u'owner': u'user0',
313 u'created_on': u'2008-07-30 22:15:43',
314 u'timeout': 144,
315 u'synch_count': 1,
316 u'id': 6761}]),
317 ('get_host_queue_entries', {'job__in': ['6761']},
318 True,
319 [{u'status': u'Queued',
320 u'complete': 0,
321 u'deleted': 0,
322 u'host': {u'status': u'Running',
323 u'lock_time': None,
324 u'hostname': u'host41',
325 u'locked': False,
326 u'locked_by': None,
327 u'invalid': False,
328 u'id': 4833,
329 u'protection': u'Repair filesystem only',
330 u'synch_id': None},
331 u'priority': 1,
332 u'meta_host': u'Xeon',
333 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
334 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700335 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000336 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800337 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000338 u'owner': u'user0',
339 u'created_on': u'2008-07-30 22:15:43',
340 u'timeout': 144,
341 u'synch_count': 1,
342 u'id': 6761},
343 u'active': 0,
344 u'id': 193166},
345 {u'status': u'Running',
346 u'complete': 0,
347 u'deleted': 0,
348 u'host': {u'status': u'Running',
349 u'lock_time': None,
350 u'hostname': u'host42',
351 u'locked': False,
352 u'locked_by': None,
353 u'invalid': False,
354 u'id': 4833,
355 u'protection': u'Repair filesystem only',
356 u'synch_id': None},
357 u'priority': 1,
358 u'meta_host': u'Xeon',
359 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
360 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700361 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000362 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800363 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000364 u'owner': u'user0',
365 u'created_on': u'2008-07-30 22:15:43',
366 u'timeout': 144,
367 u'synch_count': 1,
368 u'id': 6761},
369 u'active': 0,
370 u'id': 193166} ])],
371 out_words_ok=['host41', 'host42'],
372 out_words_no=['Xeon', 'Running', 'Queued'],
373 err_words_no=['unassigned'])
374
375
376 def test_job_stat_list_hosts_status(self):
377 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
378 '--list-hosts-status', 'Running,Queued',
379 '--ignore_site_file'],
380 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
381 [{u'status_counts': {u'Queued': 1, u'Running': 1},
382 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
383 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700384 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000385 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800386 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000387 u'owner': u'user0',
388 u'created_on': u'2008-07-30 22:15:43',
389 u'timeout': 144,
390 u'synch_count': 1,
391 u'id': 6761}]),
392 ('get_host_queue_entries', {'job__in': ['6761']},
393 True,
394 [{u'status': u'Queued',
395 u'complete': 0,
396 u'deleted': 0,
397 u'host': {u'status': u'Queued',
398 u'lock_time': None,
399 u'hostname': u'host41',
400 u'locked': False,
401 u'locked_by': None,
402 u'invalid': False,
403 u'id': 4833,
404 u'protection': u'Repair filesystem only',
405 u'synch_id': None},
406 u'priority': 1,
407 u'meta_host': None,
408 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
409 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700410 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000411 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800412 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000413 u'owner': u'user0',
414 u'created_on': u'2008-07-30 22:15:43',
415 u'timeout': 144,
416 u'synch_count': 1,
417 u'id': 6761},
418 u'active': 0,
419 u'id': 193166},
420 {u'status': u'Running',
421 u'complete': 0,
422 u'deleted': 0,
423 u'host': {u'status': u'Running',
424 u'lock_time': None,
425 u'hostname': u'host42',
426 u'locked': False,
427 u'locked_by': None,
428 u'invalid': False,
429 u'id': 4833,
430 u'protection': u'Repair filesystem only',
431 u'synch_id': None},
432 u'priority': 1,
433 u'meta_host': None,
434 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
435 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700436 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000437 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800438 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000439 u'owner': u'user0',
440 u'created_on': u'2008-07-30 22:15:43',
441 u'timeout': 144,
442 u'synch_count': 1,
443 u'id': 6761},
444 u'active': 0,
445 u'id': 193166} ])],
446 out_words_ok=['Queued', 'Running', 'host41', 'host42'],
447 out_words_no=['Xeon'],
448 err_words_no=['unassigned'])
449
450
mblighbe630eb2008-08-01 16:41:48 +0000451 def test_job_stat_job_multiple_hosts(self):
mbligha212d712009-02-11 01:22:36 +0000452 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
453 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000454 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
455 [{u'status_counts': {u'Running': 1,
456 u'Queued': 4},
457 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
458 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700459 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000460 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800461 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000462 u'owner': u'user0',
463 u'created_on': u'2008-07-30 22:15:43',
464 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000465 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000466 u'id': 6761}]),
467 ('get_host_queue_entries', {'job__in': ['6761']},
468 True,
469 [{u'status': u'Queued',
470 u'complete': 0,
471 u'deleted': 0,
472 u'host': None,
473 u'priority': 1,
474 u'meta_host': u'Xeon',
475 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
476 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700477 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000478 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800479 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000480 u'owner': u'user0',
481 u'created_on': u'2008-07-30 22:15:43',
482 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000483 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000484 u'id': 6761},
485 u'active': 0,
486 u'id': 193166},
487 {u'status': u'Queued',
488 u'complete': 0,
489 u'deleted': 0,
490 u'host': None,
491 u'priority': 1,
492 u'meta_host': u'Xeon',
493 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
494 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700495 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000496 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800497 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000498 u'owner': u'user0',
499 u'created_on': u'2008-07-30 22:15:43',
500 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000501 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000502 u'id': 6761},
503 u'active': 0,
504 u'id': 193167},
505 {u'status': u'Queued',
506 u'complete': 0,
507 u'deleted': 0,
508 u'host': None,
509 u'priority': 1,
510 u'meta_host': u'Athlon',
511 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
512 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700513 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000514 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800515 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000516 u'owner': u'user0',
517 u'created_on': u'2008-07-30 22:15:43',
518 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000519 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000520 u'id': 6761},
521 u'active': 0,
522 u'id': 193168},
523 {u'status': u'Queued',
524 u'complete': 0,
525 u'deleted': 0,
526 u'host': None,
527 u'priority': 1,
528 u'meta_host': u'x286',
529 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
530 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700531 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000532 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800533 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000534 u'owner': u'user0',
535 u'created_on': u'2008-07-30 22:15:43',
536 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000537 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000538 u'id': 6761},
539 u'active': 0,
540 u'id': 193169},
541 {u'status': u'Running',
542 u'complete': 0,
543 u'deleted': 0,
544 u'host': {u'status': u'Running',
545 u'lock_time': None,
546 u'hostname': u'host42',
mbligh0887d402009-01-30 00:50:29 +0000547 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000548 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000549 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000550 u'id': 4833,
551 u'protection': u'Repair filesystem only',
552 u'synch_id': None},
553 u'priority': 1,
554 u'meta_host': u'Athlon',
555 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
556 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700557 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000558 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800559 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000560 u'owner': u'user0',
561 u'created_on': u'2008-07-30 22:15:43',
562 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000563 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000564 u'id': 6761},
565 u'active': 1,
566 u'id': 193170} ])],
567 out_words_ok=['test_on_meta_hosts',
568 'host42', 'Queued', 'Running'],
569 out_words_no=['Athlon', 'Xeon', 'x286'])
570
571
572 def test_job_stat_job_no_host_in_qes(self):
573 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000574 self.run_cmd(argv=['atest', 'job', 'stat', '180',
575 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000576 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
577 [results[0]]),
578 ('get_host_queue_entries', {'job__in': ['180']},
579 True,
580 [{u'status': u'Failed',
581 u'complete': 1,
582 u'host': None,
583 u'priority': 1,
584 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000585 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000586 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700587 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800588 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000589 u'owner': u'user0',
590 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000591 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000592 u'id': 180},
593 u'active': 0,
594 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000595 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000596
597
598 def test_job_stat_multi_jobs(self):
599 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000600 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338',
601 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000602 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
603 True, results),
604 ('get_host_queue_entries',
605 {'job__in': ['180', '338']},
606 True,
607 [{u'status': u'Failed',
608 u'complete': 1,
609 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000610 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000611 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000612 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000613 u'id': 4432,
614 u'synch_id': None},
615 u'priority': 1,
616 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000617 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000618 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700619 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800620 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000621 u'owner': u'user0',
622 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000623 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000624 u'id': 180},
625 u'active': 0,
626 u'id': 101084},
627 {u'status': u'Failed',
628 u'complete': 1,
629 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000630 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000631 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000632 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000633 u'id': 4432,
634 u'synch_id': None},
635 u'priority': 1,
636 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000637 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000638 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700639 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800640 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000641 u'owner': u'user0',
642 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000643 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000644 u'id': 338},
645 u'active': 0,
646 u'id': 101084}])],
647 out_words_ok=['test_job0', 'test_job1'])
648
649
650 def test_job_stat_multi_jobs_name_id(self):
mbligha212d712009-02-11 01:22:36 +0000651 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180',
652 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000653 rpcs=[('get_jobs_summary', {'id__in': ['180']},
654 True,
655 [{u'status_counts': {u'Aborted': 1},
656 u'control_file':
657 u"job.run_test('sleeptest')\n",
658 u'name': u'job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700659 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000660 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800661 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000662 u'owner': u'user0',
663 u'created_on':
664 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000665 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000666 u'id': 180}]),
667 ('get_jobs_summary', {'name__in': ['mytest']},
668 True,
669 [{u'status_counts': {u'Queued': 1},
670 u'control_file':
671 u"job.run_test('sleeptest')\n",
672 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700673 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800675 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000676 u'owner': u'user0',
677 u'created_on': u'2008-07-08 12:17:47',
678 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000679 u'id': 338}]),
680 ('get_host_queue_entries',
681 {'job__in': ['180']},
682 True,
683 [{u'status': u'Failed',
684 u'complete': 1,
685 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000686 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000687 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000688 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000689 u'id': 4432,
690 u'synch_id': None},
691 u'priority': 1,
692 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000693 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000694 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700695 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000696 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800697 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'owner': u'user0',
699 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000700 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000701 u'id': 180},
702 u'active': 0,
703 u'id': 101084}]),
704 ('get_host_queue_entries',
705 {'job__name__in': ['mytest']},
706 True,
707 [{u'status': u'Failed',
708 u'complete': 1,
709 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000710 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000711 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000712 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000713 u'id': 4432,
714 u'synch_id': None},
715 u'priority': 1,
716 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000717 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
mblighbe630eb2008-08-01 16:41:48 +0000718 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700719 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000720 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800721 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000722 u'owner': u'user0',
723 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000724 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000725 u'id': 338},
726 u'active': 0,
727 u'id': 101084}])],
728 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
Allen Li352b86a2016-12-14 12:11:27 -0800729 'Failed', str(priorities.Priority.DEFAULT)])
mblighbe630eb2008-08-01 16:41:48 +0000730
731
732class job_create_unittest(cli_mock.cli_unittest):
733 ctrl_file = '\ndef step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME =\n "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1\n second by default. It\'s a good way to test\n profilers and double check\n that autotest is working.\n The seconds argument can also be modified to\n make the machine sleep for as\n long as needed.\n """\n \n\n job.run_test(\'sleeptest\', seconds = 1)'
734
Richard Barnette41e617b2016-05-19 16:18:16 -0700735 kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n job.next_step([step_test])\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)'
mblighbe630eb2008-08-01 16:41:48 +0000736
mbligh120351e2009-01-24 01:40:45 +0000737 trivial_ctrl_file = 'print "Hello"\n'
738
Allen Li352b86a2016-12-14 12:11:27 -0800739 data = {'priority': priorities.Priority.DEFAULT, 'control_file': ctrl_file,
740 'hosts': ['host0'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700741 'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
Dan Shiec1d47d2015-02-13 11:38:13 -0800742 'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
743 'require_ssp': False}
mblighbe630eb2008-08-01 16:41:48 +0000744
745
746 def test_execute_create_job(self):
747 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
mbligha212d712009-02-11 01:22:36 +0000748 'test_job0', '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000749 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000750 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000751 True,
752 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000753 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000754 'is_server' : False,
755 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000756 ('create_job', self.data, True, 180)],
757 out_words_ok=['test_job0', 'Created'],
758 out_words_no=['Uploading', 'Done'])
759
760
761 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000762 file_temp = cli_mock.create_file(self.ctrl_file)
763 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000764 'test_job0', '-m', 'host0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000765 rpcs=[('create_job', self.data, True, 42)],
766 out_words_ok=['test_job0', 'Created'],
767 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000768 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000769
770
mbligh0a669132008-10-10 20:02:32 +0000771 def test_execute_create_job_with_control_and_email(self):
772 data = self.data.copy()
773 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000774 file_temp = cli_mock.create_file(self.ctrl_file)
775 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000776 'test_job0', '-m', 'host0', '-e', 'em',
777 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000778 rpcs=[('create_job', data, True, 42)],
779 out_words_ok=['test_job0', 'Created'],
780 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000781 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000782
783
showardb27f4ad2009-05-01 00:08:26 +0000784 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000785 data = self.data.copy()
786 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000787 file_temp = cli_mock.create_file(self.ctrl_file)
788 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +0000789 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000790 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000791 rpcs=[('create_job', data, True, 42)],
792 out_words_ok=['test_job0', 'Created'],
793 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000794 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000795
796
Eric Li8a12e802011-02-17 14:24:13 -0800797 def test_execute_create_job_with_control_and_comma_dependencies(self):
798 data = self.data.copy()
799 data['dependencies'] = ['dep2,False', 'dep1,True']
800 file_temp = cli_mock.create_file(self.ctrl_file)
801 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
802 'test_job0', '-m', 'host0', '-d',
803 'dep1\,True, dep2\,False ', '--ignore_site_file'],
804 rpcs=[('create_job', data, True, 42)],
805 out_words_ok=['test_job0', 'Created'],
806 out_words_no=['Uploading', 'Done'])
807 file_temp.clean()
808
809
showard7bce1022008-11-14 22:51:05 +0000810 def test_execute_create_job_with_synch_count(self):
811 data = self.data.copy()
812 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000813 file_temp = cli_mock.create_file(self.ctrl_file)
814 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000815 'test_job0', '-m', 'host0', '-y', '2',
816 '--ignore_site_file'],
showard7bce1022008-11-14 22:51:05 +0000817 rpcs=[('create_job', data, True, 42)],
818 out_words_ok=['test_job0', 'Created'],
819 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000820 file_temp.clean()
showard7bce1022008-11-14 22:51:05 +0000821
822
showardb27f4ad2009-05-01 00:08:26 +0000823 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000824 data = self.data.copy()
825 data['dependencies'] = ['dep1', 'dep2', 'dep3']
826 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
showardb27f4ad2009-05-01 00:08:26 +0000827 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000828 '--ignore_site_file'],
mblighb9a8b162008-10-29 16:47:29 +0000829 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000830 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000831 True,
832 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000833 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000834 'is_server' : False,
835 'dependencies' : ['dep3']}),
836 ('create_job', data, True, 42)],
837 out_words_ok=['test_job0', 'Created'],
838 out_words_no=['Uploading', 'Done'])
839
840
Eric Li8a12e802011-02-17 14:24:13 -0800841 def test_execute_create_job_with_test_and_comma_dependencies(self):
842 data = self.data.copy()
843 data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
844 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
845 'test_job0', '-m', 'host0', '-d',
846 'dep1\,True dep2\,False ', '--ignore_site_file'],
847 rpcs=[('generate_control_file',
848 {'tests': ['sleeptest']},
849 True,
850 {'control_file' : self.ctrl_file,
851 'synch_count' : 1,
852 'is_server' : False,
853 'dependencies' : ['dep3,123']}),
854 ('create_job', data, True, 42)],
855 out_words_ok=['test_job0', 'Created'],
856 out_words_no=['Uploading', 'Done'])
857
858
mblighbe630eb2008-08-01 16:41:48 +0000859 def test_execute_create_job_no_args(self):
860 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000861 sys.argv = ['atest', 'job', 'create', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000862 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000863 (sys.exit.expect_call(mock.anything_comparator())
864 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000865 self.assertRaises(cli_mock.ExitException, testjob.parse)
866 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000867 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000868
869
870 def test_execute_create_job_no_hosts(self):
871 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000872 file_temp = cli_mock.create_file(self.ctrl_file)
873 sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
874 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000875 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000876 (sys.exit.expect_call(mock.anything_comparator())
877 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000878 self.assertRaises(cli_mock.ExitException, testjob.parse)
879 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000880 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000881 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000882
883
884 def test_execute_create_job_cfile_and_tests(self):
885 testjob = job.job_create()
886 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
mbligha212d712009-02-11 01:22:36 +0000887 'control_file', 'test_job0', '-m', 'host0',
888 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000889 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000890 (sys.exit.expect_call(mock.anything_comparator())
891 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000892 self.assertRaises(cli_mock.ExitException, testjob.parse)
893 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000894 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000895
896
mblighbe630eb2008-08-01 16:41:48 +0000897 def test_execute_create_job_bad_cfile(self):
898 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000899 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
900 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000901 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000902 (sys.exit.expect_call(mock.anything_comparator())
903 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +0000904 self.assertRaises(IOError, testjob.parse)
905 self.god.unmock_io()
906
907
908 def test_execute_create_job_bad_priority(self):
909 testjob = job.job_create()
910 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
mbligha212d712009-02-11 01:22:36 +0000911 '-m', 'host0', 'test_job0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000912 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000913 (sys.exit.expect_call(mock.anything_comparator())
914 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000915 self.assertRaises(cli_mock.ExitException, testjob.parse)
916 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000917 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000918
919
920 def test_execute_create_job_with_mfile(self):
921 data = self.data.copy()
922 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +0000923 ctemp = cli_mock.create_file(self.ctrl_file)
924 file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
925 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
926 '-f', ctemp.name, 'test_job0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000927 rpcs=[('create_job', data, True, 42)],
928 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +0000929 ctemp.clean()
930 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000931
932
mbligh5d0b4b32008-12-22 14:43:01 +0000933 def test_execute_create_job_with_timeout(self):
934 data = self.data.copy()
Simran Basi7e605742013-11-12 13:43:36 -0800935 data['timeout_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000936 file_temp = cli_mock.create_file(self.ctrl_file)
937 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi7e605742013-11-12 13:43:36 -0800938 'test_job0', '-m', 'host0', '-o', '13320',
mbligha212d712009-02-11 01:22:36 +0000939 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +0000940 rpcs=[('create_job', data, True, 42)],
941 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000942 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000943
944
showard12f3e322009-05-13 21:27:42 +0000945 def test_execute_create_job_with_max_runtime(self):
946 data = self.data.copy()
Simran Basi34217022012-11-06 13:43:15 -0800947 data['max_runtime_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000948 file_temp = cli_mock.create_file(self.ctrl_file)
949 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi34217022012-11-06 13:43:15 -0800950 'test_job0', '-m', 'host0', '--max_runtime',
951 '13320', '--ignore_site_file'],
showard12f3e322009-05-13 21:27:42 +0000952 rpcs=[('create_job', data, True, 42)],
953 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000954 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +0000955
956
957
mbligh5d0b4b32008-12-22 14:43:01 +0000958 def test_execute_create_job_with_noverify(self):
959 data = self.data.copy()
960 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +0000961 file_temp = cli_mock.create_file(self.ctrl_file)
962 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000963 'test_job0', '-m', 'host0', '-n',
964 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +0000965 rpcs=[('create_job', data, True, 42)],
966 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000967 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000968
969
mblighce348642009-02-12 21:50:39 +0000970 def test_execute_create_job_oth(self):
971 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000972 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000973 data['one_time_hosts'] = ['host0']
974 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
975 'test_job0', '--one-time-hosts', 'host0'],
976 rpcs=[('generate_control_file',
977 {'tests': ['sleeptest']},
978 True,
979 {'control_file' : self.ctrl_file,
980 'synch_count' : 1,
981 'is_server' : False,
982 'dependencies' : []}),
983 ('create_job', data, True, 180)],
984 out_words_ok=['test_job0', 'Created'],
985 out_words_no=['Uploading', 'Done'])
986
987
988 def test_execute_create_job_multi_oth(self):
989 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000990 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000991 data['one_time_hosts'] = ['host1', 'host0']
992 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
993 'test_job0', '--one-time-hosts', 'host0,host1'],
994 rpcs=[('generate_control_file',
995 {'tests': ['sleeptest']},
996 True,
997 {'control_file' : self.ctrl_file,
998 'synch_count' : 1,
999 'is_server' : False,
1000 'dependencies' : []}),
1001 ('create_job', data, True, 180)],
1002 out_words_ok=['test_job0', 'Created'],
1003 out_words_no=['Uploading', 'Done'])
1004
1005
1006 def test_execute_create_job_oth_exists(self):
1007 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001008 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001009 data['one_time_hosts'] = ['host0']
1010 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1011 'test_job0', '--one-time-hosts', 'host0'],
1012 rpcs=[('generate_control_file',
1013 {'tests': ['sleeptest']},
1014 True,
1015 {'control_file' : self.ctrl_file,
1016 'synch_count' : 1,
1017 'is_server' : False,
1018 'dependencies' : []}),
1019 ('create_job', data, False,
1020 '''ValidationError: {'hostname': 'host0 '''
1021 '''already exists in the autotest DB. '''
1022 '''Select it rather than entering it as '''
1023 '''a one time host.'}''')],
1024 out_words_no=['test_job0', 'Created'],
1025 err_words_ok=['failed', 'already exists'])
1026
1027
showardb27f4ad2009-05-01 00:08:26 +00001028 def test_execute_create_job_with_control_and_labels(self):
1029 data = self.data.copy()
1030 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001031 file_temp = cli_mock.create_file(self.ctrl_file)
1032 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001033 'test_job0', '-m', 'host0', '-b', 'label1,label2',
1034 '--ignore_site_file'],
1035 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1036 'label2']}, True,
1037 [{u'status': u'Running', u'lock_time': None,
1038 u'hostname': u'host1', u'locked': False,
1039 u'locked_by': None, u'invalid': False, u'id': 42,
1040 u'labels': [u'label1'], u'platform':
1041 u'Warp18_Diskfull', u'protection':
1042 u'Repair software only', u'dirty':
1043 True, u'synch_id': None},
1044 {u'status': u'Running', u'lock_time': None,
1045 u'hostname': u'host2', u'locked': False,
1046 u'locked_by': None, u'invalid': False, u'id': 43,
1047 u'labels': [u'label2'], u'platform':
1048 u'Warp18_Diskfull', u'protection':
1049 u'Repair software only', u'dirty': True,
1050 u'synch_id': None}]),
1051 ('create_job', data, True, 42)],
1052 out_words_ok=['test_job0', 'Created'],
1053 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001054 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001055
1056
1057 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1058 data = self.data.copy()
1059 data['hosts'] = ['host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001060 file_temp = cli_mock.create_file(self.ctrl_file)
1061 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001062 'test_job0', '-m', 'host0,host1', '-b', 'label1',
1063 '--ignore_site_file'],
1064 rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1065 [{u'status': u'Running', u'lock_time': None,
1066 u'hostname': u'host1', u'locked': False,
1067 u'locked_by': None, u'invalid': False, u'id': 42,
1068 u'labels': [u'label1'], u'platform':
1069 u'Warp18_Diskfull', u'protection':
1070 u'Repair software only', u'dirty':
1071 True, u'synch_id': None}]),
1072 ('create_job', data, True, 42)],
1073 out_words_ok=['test_job0', 'Created'],
1074 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001075 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001076
1077
jamesrenc2863162010-07-12 21:20:51 +00001078 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1079 data = self.data.copy()
1080 data['hosts'] = ['host1', 'host0']
1081 file_temp = cli_mock.create_file(self.ctrl_file)
1082 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1083 'test_job0', '-m', 'host0,host1', '-b',
1084 'label1,label\\,2', '--ignore_site_file'],
1085 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1086 'label,2']}, True,
1087 [{u'status': u'Running', u'lock_time': None,
1088 u'hostname': u'host1', u'locked': False,
1089 u'locked_by': None, u'invalid': False, u'id': 42,
1090 u'labels': [u'label1', u'label,2'], u'platform':
1091 u'Warp18_Diskfull', u'protection':
1092 u'Repair software only', u'dirty':
1093 True, u'synch_id': None}]),
1094 ('create_job', data, True, 42)],
1095 out_words_ok=['test_job0', 'Created'],
1096 out_words_no=['Uploading', 'Done'])
1097 file_temp.clean()
1098
1099
1100 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1101 data = self.data.copy()
1102 data['hosts'] = ['host1', 'host0']
1103 file_temp = cli_mock.create_file(self.ctrl_file)
1104 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1105 'test_job0', '-m', 'host0,host1', '-b',
1106 'label1,label\\,2\\\\,label3', '--ignore_site_file'],
1107 rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1108 'label1', 'label3']}, True,
1109 [{u'status': u'Running', u'lock_time': None,
1110 u'hostname': u'host1', u'locked': False,
1111 u'locked_by': None, u'invalid': False, u'id': 42,
1112 u'labels': [u'label1', u'label,2\\', u'label3'],
1113 u'platform': u'Warp18_Diskfull', u'protection':
1114 u'Repair software only', u'dirty':
1115 True, u'synch_id': None}]),
1116 ('create_job', data, True, 42)],
1117 out_words_ok=['test_job0', 'Created'],
1118 out_words_no=['Uploading', 'Done'])
1119 file_temp.clean()
1120
1121
mblighbe630eb2008-08-01 16:41:48 +00001122 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001123 testjob = job.job_create_or_clone()
1124 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001125 self.assertEqualNoOrder(hosts, exp_hosts)
1126 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1127
1128
1129 def test_parse_hosts_regular(self):
1130 self._test_parse_hosts(['host0'], ['host0'])
1131
1132
1133 def test_parse_hosts_regulars(self):
1134 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1135
1136
1137 def test_parse_hosts_meta_one(self):
1138 self._test_parse_hosts(['*meta0'], [], ['meta0'])
1139
1140
1141 def test_parse_hosts_meta_five(self):
1142 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1143
1144
1145 def test_parse_hosts_metas_five(self):
1146 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1147 ['meta0']*5 + ['meta1']*2)
1148
1149
1150 def test_parse_hosts_mix(self):
1151 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1152 '*meta2'], ['host0', 'host1'],
1153 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1154
1155
mbligh5a496082009-08-03 16:44:54 +00001156class job_clone_unittest(cli_mock.cli_unittest):
1157 job_data = {'control_file': u'NAME = \'Server Sleeptest\'\nAUTHOR = \'mbligh@google.com (Martin Bligh)\'\nTIME = \'SHORT\'\nTEST_CLASS = \'Software\'\nTEST_CATEGORY = \'Functional\'\nTEST_TYPE = \'server\'\nEXPERIMENTAL = \'False\'\n\nDOC = """\nruns sleep for one second on the list of machines.\n"""\n\ndef run(machine):\n host = hosts.create_host(machine)\n job.run_test(\'sleeptest\')\n\njob.parallel_simple(run, machines)\n',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001158 'control_type': SERVER,
mbligh5a496082009-08-03 16:44:54 +00001159 'dependencies': [],
1160 'email_list': u'',
Simran Basi34217022012-11-06 13:43:15 -08001161 'max_runtime_mins': 28800,
mbligh5a496082009-08-03 16:44:54 +00001162 'parse_failed_repair': True,
Allen Li352b86a2016-12-14 12:11:27 -08001163 'priority': priorities.Priority.DEFAULT,
mbligh5a496082009-08-03 16:44:54 +00001164 'reboot_after': u'Always',
1165 'reboot_before': u'If dirty',
1166 'run_verify': True,
1167 'synch_count': 1,
Simran Basi7e605742013-11-12 13:43:36 -08001168 'timeout_mins': 480}
mbligh5a496082009-08-03 16:44:54 +00001169
mbligh56f1f4a2009-08-03 16:45:12 +00001170 local_hosts = [{u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001171 u'attributes': {},
1172 u'dirty': False,
1173 u'hostname': u'host0',
1174 u'id': 8,
1175 u'invalid': False,
1176 u'labels': [u'label0', u'label1'],
1177 u'lock_time': None,
1178 u'locked': False,
1179 u'locked_by': None,
1180 u'other_labels': u'label0, label1',
1181 u'platform': u'plat0',
1182 u'protection': u'Repair software only',
1183 u'status': u'Ready',
1184 u'synch_id': None},
1185 {u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001186 u'attributes': {},
1187 u'dirty': False,
1188 u'hostname': u'host1',
1189 u'id': 9,
1190 u'invalid': False,
1191 u'labels': [u'label0', u'label1'],
1192 u'lock_time': None,
1193 u'locked': False,
1194 u'locked_by': None,
1195 u'other_labels': u'label0, label1',
1196 u'platform': u'plat0',
1197 u'protection': u'Repair software only',
1198 u'status': u'Ready',
1199 u'synch_id': None}]
1200
1201
mbligh5a496082009-08-03 16:44:54 +00001202 def setUp(self):
1203 super(job_clone_unittest, self).setUp()
1204 self.job_data_clone_info = copy.deepcopy(self.job_data)
1205 self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1206 self.job_data_clone_info['name'] = 'testing_clone'
1207 self.job_data_clone_info['id'] = 42
1208 self.job_data_clone_info['owner'] = 'user0'
1209
1210 self.job_data_cloned = copy.deepcopy(self.job_data)
1211 self.job_data_cloned['name'] = 'cloned'
1212 self.job_data_cloned['hosts'] = [u'host0']
1213 self.job_data_cloned['meta_hosts'] = []
1214
1215
1216 def test_backward_compat(self):
1217 self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1218 '-r', 'cloned'],
1219 rpcs=[('get_info_for_clone', {'id': '42',
1220 'preserve_metahosts': True},
1221 True,
Allen Li335f2162017-02-01 14:47:01 -08001222 {u'hosts': [{u'acls': [u'acl0'],
mbligh5a496082009-08-03 16:44:54 +00001223 u'attributes': {},
1224 u'dirty': False,
1225 u'hostname': u'host0',
1226 u'id': 4378,
1227 u'invalid': False,
1228 u'labels': [u'label0', u'label1'],
1229 u'lock_time': None,
1230 u'locked': False,
1231 u'locked_by': None,
1232 u'other_labels': u'label0, label1',
1233 u'platform': u'plat0',
1234 u'protection': u'Repair software only',
1235 u'status': u'Ready',
1236 u'synch_id': None}],
1237 u'job': self.job_data_clone_info,
1238 u'meta_host_counts': {}}),
1239 ('create_job', self.job_data_cloned, True, 43)],
1240 out_words_ok=['Created job', '43'])
1241
1242
1243 def test_clone_reuse_hosts(self):
mbligh56f1f4a2009-08-03 16:45:12 +00001244 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001245 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1246 '-r', 'cloned'],
1247 rpcs=[('get_info_for_clone', {'id': '42',
1248 'preserve_metahosts': True},
1249 True,
Allen Li335f2162017-02-01 14:47:01 -08001250 {u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001251 u'job': self.job_data_clone_info,
1252 u'meta_host_counts': {}}),
1253 ('create_job', self.job_data_cloned, True, 43)],
1254 out_words_ok=['Created job', '43'])
1255
1256
mbligh56f1f4a2009-08-03 16:45:12 +00001257 def test_clone_reuse_metahosts(self):
1258 self.job_data_cloned['hosts'] = []
1259 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1260 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1261 '-r', 'cloned'],
1262 rpcs=[('get_info_for_clone', {'id': '42',
1263 'preserve_metahosts': True},
1264 True,
Allen Li335f2162017-02-01 14:47:01 -08001265 {u'hosts': [],
mbligh56f1f4a2009-08-03 16:45:12 +00001266 u'job': self.job_data_clone_info,
1267 u'meta_host_counts': {u'type0': 1,
1268 u'type1': 4}}),
1269 ('create_job', self.job_data_cloned, True, 43)],
1270 out_words_ok=['Created job', '43'])
1271
1272
1273 def test_clone_reuse_both(self):
1274 self.job_data_cloned['hosts'] = [u'host0', 'host1']
1275 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1276 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1277 '-r', 'cloned'],
1278 rpcs=[('get_info_for_clone', {'id': '42',
1279 'preserve_metahosts': True},
1280 True,
Allen Li335f2162017-02-01 14:47:01 -08001281 {
mbligh56f1f4a2009-08-03 16:45:12 +00001282 u'hosts': self.local_hosts,
1283 u'job': self.job_data_clone_info,
1284 u'meta_host_counts': {u'type0': 1,
1285 u'type1': 4}}),
1286 ('create_job', self.job_data_cloned, True, 43)],
1287 out_words_ok=['Created job', '43'])
1288
1289
mbligh5a496082009-08-03 16:44:54 +00001290 def test_clone_no_hosts(self):
1291 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1292 exit_code=1,
1293 out_words_ok=['usage'],
1294 err_words_ok=['machine'])
1295
1296
mbligh56f1f4a2009-08-03 16:45:12 +00001297 def test_clone_reuse_and_hosts(self):
1298 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1299 '-r', '-m', 'host5', 'cloned'],
1300 exit_code=1,
1301 out_words_ok=['usage'],
1302 err_words_ok=['specify'])
1303
1304
1305 def test_clone_new_multiple_hosts(self):
1306 self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1307 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1308 '-m', 'host5,host4,host3', 'cloned'],
1309 rpcs=[('get_info_for_clone', {'id': '42',
1310 'preserve_metahosts': False},
1311 True,
Allen Li335f2162017-02-01 14:47:01 -08001312 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001313 u'job': self.job_data_clone_info,
1314 u'meta_host_counts': {}}),
1315 ('create_job', self.job_data_cloned, True, 43)],
1316 out_words_ok=['Created job', '43'])
1317
1318
1319 def test_clone_oth(self):
1320 self.job_data_cloned['hosts'] = []
1321 self.job_data_cloned['one_time_hosts'] = [u'host5']
1322 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1323 '--one-time-hosts', 'host5', 'cloned'],
1324 rpcs=[('get_info_for_clone', {'id': '42',
1325 'preserve_metahosts': False},
1326 True,
Allen Li335f2162017-02-01 14:47:01 -08001327 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001328 u'job': self.job_data_clone_info,
1329 u'meta_host_counts': {}}),
1330 ('create_job', self.job_data_cloned, True, 43)],
1331 out_words_ok=['Created job', '43'])
mbligh5a496082009-08-03 16:44:54 +00001332
1333
mblighbe630eb2008-08-01 16:41:48 +00001334class job_abort_unittest(cli_mock.cli_unittest):
1335 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1336 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001337 u'control_type': SERVER, u'priority':
Allen Li352b86a2016-12-14 12:11:27 -08001338 priorities.Priority.DEFAULT, u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001339 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001340
1341 def test_execute_job_abort(self):
mbligha212d712009-02-11 01:22:36 +00001342 self.run_cmd(argv=['atest', 'job', 'abort', '180',
1343 '--ignore_site_file'],
mbligh206d50a2008-11-13 01:19:25 +00001344 rpcs=[('abort_host_queue_entries',
1345 {'job__id__in': ['180']}, True, None)],
1346 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001347
1348
1349if __name__ == '__main__':
1350 unittest.main()