| mbligh | 0a66913 | 2008-10-10 20:02:32 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2008 Google Inc. All Rights Reserved. |
| 4 | |
| mbligh | fb8f0ab | 2008-11-13 01:11:48 +0000 | [diff] [blame] | 5 | #TODO(rkubiak): Add unittest for job cloning |
| 6 | |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 7 | """Tests for job.""" |
| 8 | |
| 9 | import copy, getpass, unittest, sys, os |
| 10 | |
| 11 | import common |
| 12 | from autotest_lib.cli import cli_mock, topic_common, job |
| 13 | |
| 14 | |
| 15 | class job_unittest(cli_mock.cli_unittest): |
| 16 | def setUp(self): |
| 17 | super(job_unittest, self).setUp() |
| 18 | self.god.stub_function(getpass, 'getuser') |
| 19 | getpass.getuser.expect_call().and_return('user0') |
| 20 | self.values = copy.deepcopy(self.values_template) |
| 21 | |
| 22 | results = [{u'status_counts': {u'Aborted': 1}, |
| 23 | u'control_file': |
| 24 | u"job.run_test('sleeptest')\n", |
| 25 | u'name': u'test_job0', |
| 26 | u'control_type': u'Server', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 27 | u'priority': |
| 28 | u'Medium', |
| 29 | u'owner': u'user0', |
| 30 | u'created_on': |
| 31 | u'2008-07-08 17:45:44', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 32 | u'synch_count': 2, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 33 | u'id': 180}, |
| 34 | {u'status_counts': {u'Queued': 1}, |
| 35 | u'control_file': |
| 36 | u"job.run_test('sleeptest')\n", |
| 37 | u'name': u'test_job1', |
| 38 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 39 | u'priority': |
| 40 | u'High', |
| 41 | u'owner': u'user0', |
| 42 | u'created_on': |
| 43 | u'2008-07-08 12:17:47', |
| 44 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 45 | u'id': 338}] |
| 46 | |
| 47 | |
| 48 | values_template = [{u'id': 180, # Valid job |
| 49 | u'priority': u'Low', |
| 50 | u'name': u'test_job0', |
| 51 | u'owner': u'Cringer', |
| 52 | u'invalid': 0, |
| 53 | u'created_on': u'2008-07-02 13:02:40', |
| 54 | u'control_type': u'Server', |
| 55 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 56 | u'synch_count': 2}, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 57 | {u'id': 338, # Valid job |
| 58 | u'priority': 'High', |
| 59 | u'name': u'test_job1', |
| 60 | u'owner': u'Fisto', |
| 61 | u'invalid': 0, |
| 62 | u'created_on': u'2008-07-06 14:05:33', |
| 63 | u'control_type': u'Client', |
| 64 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 65 | u'synch_count': 1}, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 66 | {u'id': 339, # Valid job |
| 67 | u'priority': 'Medium', |
| 68 | u'name': u'test_job2', |
| 69 | u'owner': u'Roboto', |
| 70 | u'invalid': 0, |
| 71 | u'created_on': u'2008-07-07 15:33:18', |
| 72 | u'control_type': u'Server', |
| 73 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 74 | u'synch_count': 1}, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 75 | {u'id': 340, # Invalid job priority |
| 76 | u'priority': u'Uber', |
| 77 | u'name': u'test_job3', |
| 78 | u'owner': u'Panthor', |
| 79 | u'invalid': 1, |
| 80 | u'created_on': u'2008-07-04 00:00:01', |
| 81 | u'control_type': u'Server', |
| 82 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 83 | u'synch_count': 2}, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 84 | {u'id': 350, # Invalid job created_on |
| 85 | u'priority': 'Medium', |
| 86 | u'name': u'test_job4', |
| 87 | u'owner': u'Icer', |
| 88 | u'invalid': 1, |
| 89 | u'created_on': u'Today', |
| 90 | u'control_type': u'Client', |
| 91 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 92 | u'synch_count': 1}, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 93 | {u'id': 420, # Invalid job control_type |
| 94 | u'priority': 'Urgent', |
| 95 | u'name': u'test_job5', |
| 96 | u'owner': u'Spikor', |
| 97 | u'invalid': 1, |
| 98 | u'created_on': u'2012-08-08 18:54:37', |
| 99 | u'control_type': u'Child', |
| 100 | u'status_counts': {u'Queued': 1}, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 101 | u'synch_count': 2}] |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | class job_list_unittest(job_unittest): |
| 105 | def test_job_list_jobs(self): |
| 106 | getpass.getuser.expect_call().and_return('user0') |
| 107 | self.run_cmd(argv=['atest', 'job', 'list'], |
| 108 | rpcs=[('get_jobs_summary', {'owner': 'user0', |
| 109 | 'running': None}, |
| 110 | True, self.values)], |
| 111 | out_words_ok=['test_job0', 'test_job1', 'test_job2'], |
| 112 | out_words_no=['Uber', 'Today', 'Child']) |
| 113 | |
| 114 | |
| 115 | def test_job_list_jobs_only_user(self): |
| 116 | values = [item for item in self.values if item['owner'] == 'Cringer'] |
| 117 | self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer'], |
| 118 | rpcs=[('get_jobs_summary', {'owner': 'Cringer', |
| 119 | 'running': None}, |
| 120 | True, values)], |
| 121 | out_words_ok=['Cringer'], |
| 122 | out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer', |
| 123 | 'Spikor']) |
| 124 | |
| 125 | |
| 126 | def test_job_list_jobs_all(self): |
| 127 | self.run_cmd(argv=['atest', 'job', 'list', '--all'], |
| 128 | rpcs=[('get_jobs_summary', {'running': None}, |
| 129 | True, self.values)], |
| 130 | out_words_ok=['Fisto', 'Roboto', 'Panthor', |
| 131 | 'Icer', 'Spikor', 'Cringer'], |
| 132 | out_words_no=['Created', 'Priority']) |
| 133 | |
| 134 | |
| 135 | def test_job_list_jobs_id(self): |
| 136 | self.run_cmd(argv=['atest', 'job', 'list', '5964'], |
| 137 | rpcs=[('get_jobs_summary', {'id__in': ['5964'], |
| 138 | 'running': None}, |
| 139 | True, |
| 140 | [{u'status_counts': {u'Completed': 1}, |
| 141 | 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 testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\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)', |
| 142 | u'name': u'mytest', |
| 143 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 144 | u'run_verify': 1, |
| 145 | u'priority': u'Medium', |
| 146 | u'owner': u'user0', |
| 147 | u'created_on': u'2008-07-28 12:42:52', |
| 148 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 149 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 150 | u'id': 5964}])], |
| 151 | out_words_ok=['user0', 'Completed', '1', '5964'], |
| 152 | out_words_no=['sleeptest', 'Priority', 'Client', '2008']) |
| 153 | |
| 154 | |
| 155 | def test_job_list_jobs_id_verbose(self): |
| 156 | self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v'], |
| 157 | rpcs=[('get_jobs_summary', {'id__in': ['5964'], |
| 158 | 'running': None}, |
| 159 | True, |
| 160 | [{u'status_counts': {u'Completed': 1}, |
| 161 | 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 testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\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)', |
| 162 | u'name': u'mytest', |
| 163 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 164 | u'run_verify': 1, |
| 165 | u'priority': u'Medium', |
| 166 | u'owner': u'user0', |
| 167 | u'created_on': u'2008-07-28 12:42:52', |
| 168 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 169 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 170 | u'id': 5964}])], |
| 171 | out_words_ok=['user0', 'Completed', '1', '5964', |
| 172 | 'Client', '2008', 'Priority'], |
| 173 | out_words_no=['sleeptest']) |
| 174 | |
| 175 | |
| 176 | def test_job_list_jobs_name(self): |
| 177 | self.run_cmd(argv=['atest', 'job', 'list', 'myt*'], |
| 178 | rpcs=[('get_jobs_summary', {'name__startswith': 'myt', |
| 179 | 'running': None}, |
| 180 | True, |
| 181 | [{u'status_counts': {u'Completed': 1}, |
| 182 | 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 testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\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)', |
| 183 | u'name': u'mytest', |
| 184 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 185 | u'run_verify': 1, |
| 186 | u'priority': u'Medium', |
| 187 | u'owner': u'user0', |
| 188 | u'created_on': u'2008-07-28 12:42:52', |
| 189 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 190 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 191 | u'id': 5964}])], |
| 192 | out_words_ok=['user0', 'Completed', '1', '5964'], |
| 193 | out_words_no=['sleeptest', 'Priority', 'Client', '2008']) |
| 194 | |
| 195 | |
| 196 | def test_job_list_jobs_all_verbose(self): |
| 197 | self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose'], |
| 198 | rpcs=[('get_jobs_summary', {'running': None}, |
| 199 | True, self.values)], |
| 200 | out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority', |
| 201 | 'Created']) |
| 202 | |
| 203 | |
| 204 | def test_job_list_jobs_all_and_user(self): |
| 205 | testjob = job.job_list() |
| 206 | sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0'] |
| 207 | self.god.mock_io() |
| 208 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 209 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 210 | self.god.unmock_io() |
| 211 | |
| 212 | |
| 213 | class job_stat_unittest(job_unittest): |
| 214 | def test_job_stat_job(self): |
| 215 | results = copy.deepcopy(self.results) |
| 216 | self.run_cmd(argv=['atest', 'job', 'stat', '180'], |
| 217 | rpcs=[('get_jobs_summary', {'id__in': ['180']}, True, |
| 218 | [results[0]]), |
| 219 | ('get_host_queue_entries', {'job__in': ['180']}, |
| 220 | True, |
| 221 | [{u'status': u'Failed', |
| 222 | u'complete': 1, |
| 223 | u'host': {u'status': u'Repair Failed', |
| 224 | u'locked': 0, |
| 225 | u'hostname': u'host0', |
| 226 | u'invalid': 1, |
| 227 | u'id': 4432, |
| 228 | u'synch_id': None}, |
| 229 | u'priority': 1, |
| 230 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 231 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 232 | u'name': u'test_sleep', |
| 233 | u'control_type': u'Server', |
| 234 | u'synchronizing': 0, |
| 235 | u'priority': u'Medium', |
| 236 | u'owner': u'user0', |
| 237 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 238 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 239 | u'id': 180}, |
| 240 | u'active': 0, |
| 241 | u'id': 101084}])], |
| 242 | out_words_ok=['test_job0', 'host0', 'Failed', |
| 243 | 'Aborted']) |
| 244 | |
| 245 | |
| 246 | def test_job_stat_job_multiple_hosts(self): |
| 247 | self.run_cmd(argv=['atest', 'job', 'stat', '6761'], |
| 248 | rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True, |
| 249 | [{u'status_counts': {u'Running': 1, |
| 250 | u'Queued': 4}, |
| 251 | 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\')', |
| 252 | u'name': u'test_on_meta_hosts', |
| 253 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 254 | u'run_verify': 1, |
| 255 | u'priority': u'Medium', |
| 256 | u'owner': u'user0', |
| 257 | u'created_on': u'2008-07-30 22:15:43', |
| 258 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 259 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 260 | u'id': 6761}]), |
| 261 | ('get_host_queue_entries', {'job__in': ['6761']}, |
| 262 | True, |
| 263 | [{u'status': u'Queued', |
| 264 | u'complete': 0, |
| 265 | u'deleted': 0, |
| 266 | u'host': None, |
| 267 | u'priority': 1, |
| 268 | u'meta_host': u'Xeon', |
| 269 | 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\')', |
| 270 | u'name': u'test_on_meta_hosts', |
| 271 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 272 | u'run_verify': 1, |
| 273 | u'priority': u'Medium', |
| 274 | u'owner': u'user0', |
| 275 | u'created_on': u'2008-07-30 22:15:43', |
| 276 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 277 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 278 | u'id': 6761}, |
| 279 | u'active': 0, |
| 280 | u'id': 193166}, |
| 281 | {u'status': u'Queued', |
| 282 | u'complete': 0, |
| 283 | u'deleted': 0, |
| 284 | u'host': None, |
| 285 | u'priority': 1, |
| 286 | u'meta_host': u'Xeon', |
| 287 | 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\')', |
| 288 | u'name': u'test_on_meta_hosts', |
| 289 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 290 | u'run_verify': 1, |
| 291 | u'priority': u'Medium', |
| 292 | u'owner': u'user0', |
| 293 | u'created_on': u'2008-07-30 22:15:43', |
| 294 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 295 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 296 | u'id': 6761}, |
| 297 | u'active': 0, |
| 298 | u'id': 193167}, |
| 299 | {u'status': u'Queued', |
| 300 | u'complete': 0, |
| 301 | u'deleted': 0, |
| 302 | u'host': None, |
| 303 | u'priority': 1, |
| 304 | u'meta_host': u'Athlon', |
| 305 | 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\')', |
| 306 | u'name': u'test_on_meta_hosts', |
| 307 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 308 | u'run_verify': 1, |
| 309 | u'priority': u'Medium', |
| 310 | u'owner': u'user0', |
| 311 | u'created_on': u'2008-07-30 22:15:43', |
| 312 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 313 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 314 | u'id': 6761}, |
| 315 | u'active': 0, |
| 316 | u'id': 193168}, |
| 317 | {u'status': u'Queued', |
| 318 | u'complete': 0, |
| 319 | u'deleted': 0, |
| 320 | u'host': None, |
| 321 | u'priority': 1, |
| 322 | u'meta_host': u'x286', |
| 323 | 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\')', |
| 324 | u'name': u'test_on_meta_hosts', |
| 325 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 326 | u'run_verify': 1, |
| 327 | u'priority': u'Medium', |
| 328 | u'owner': u'user0', |
| 329 | u'created_on': u'2008-07-30 22:15:43', |
| 330 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 331 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 332 | u'id': 6761}, |
| 333 | u'active': 0, |
| 334 | u'id': 193169}, |
| 335 | {u'status': u'Running', |
| 336 | u'complete': 0, |
| 337 | u'deleted': 0, |
| 338 | u'host': {u'status': u'Running', |
| 339 | u'lock_time': None, |
| 340 | u'hostname': u'host42', |
| 341 | u'locked': 0, |
| 342 | u'locked_by': None, |
| 343 | u'invalid': 0, |
| 344 | u'id': 4833, |
| 345 | u'protection': u'Repair filesystem only', |
| 346 | u'synch_id': None}, |
| 347 | u'priority': 1, |
| 348 | u'meta_host': u'Athlon', |
| 349 | 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\')', |
| 350 | u'name': u'test_on_meta_hosts', |
| 351 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 352 | u'run_verify': 1, |
| 353 | u'priority': u'Medium', |
| 354 | u'owner': u'user0', |
| 355 | u'created_on': u'2008-07-30 22:15:43', |
| 356 | u'timeout': 144, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 357 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 358 | u'id': 6761}, |
| 359 | u'active': 1, |
| 360 | u'id': 193170} ])], |
| 361 | out_words_ok=['test_on_meta_hosts', |
| 362 | 'host42', 'Queued', 'Running'], |
| 363 | out_words_no=['Athlon', 'Xeon', 'x286']) |
| 364 | |
| 365 | |
| 366 | def test_job_stat_job_no_host_in_qes(self): |
| 367 | results = copy.deepcopy(self.results) |
| 368 | self.run_cmd(argv=['atest', 'job', 'stat', '180'], |
| 369 | rpcs=[('get_jobs_summary', {'id__in': ['180']}, True, |
| 370 | [results[0]]), |
| 371 | ('get_host_queue_entries', {'job__in': ['180']}, |
| 372 | True, |
| 373 | [{u'status': u'Failed', |
| 374 | u'complete': 1, |
| 375 | u'host': None, |
| 376 | u'priority': 1, |
| 377 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 378 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 379 | u'name': u'test_sleep', |
| 380 | u'control_type': u'Server', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 381 | u'priority': u'Medium', |
| 382 | u'owner': u'user0', |
| 383 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 384 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 385 | u'id': 180}, |
| 386 | u'active': 0, |
| 387 | u'id': 101084}])], |
| 388 | out_words_ok=['test_job0', 'Aborted']) |
| 389 | |
| 390 | |
| 391 | def test_job_stat_multi_jobs(self): |
| 392 | results = copy.deepcopy(self.results) |
| 393 | self.run_cmd(argv=['atest', 'job', 'stat', '180', '338'], |
| 394 | rpcs=[('get_jobs_summary', {'id__in': ['180', '338']}, |
| 395 | True, results), |
| 396 | ('get_host_queue_entries', |
| 397 | {'job__in': ['180', '338']}, |
| 398 | True, |
| 399 | [{u'status': u'Failed', |
| 400 | u'complete': 1, |
| 401 | u'host': {u'status': u'Repair Failed', |
| 402 | u'locked': 0, |
| 403 | u'hostname': u'host0', |
| 404 | u'invalid': 1, |
| 405 | u'id': 4432, |
| 406 | u'synch_id': None}, |
| 407 | u'priority': 1, |
| 408 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 409 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 410 | u'name': u'test_sleep', |
| 411 | u'control_type': u'Server', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 412 | u'priority': u'Medium', |
| 413 | u'owner': u'user0', |
| 414 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 415 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 416 | u'id': 180}, |
| 417 | u'active': 0, |
| 418 | u'id': 101084}, |
| 419 | {u'status': u'Failed', |
| 420 | u'complete': 1, |
| 421 | u'host': {u'status': u'Repair Failed', |
| 422 | u'locked': 0, |
| 423 | u'hostname': u'host10', |
| 424 | u'invalid': 1, |
| 425 | u'id': 4432, |
| 426 | u'synch_id': None}, |
| 427 | u'priority': 1, |
| 428 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 429 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 430 | u'name': u'test_sleep', |
| 431 | u'control_type': u'Server', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 432 | u'priority': u'Medium', |
| 433 | u'owner': u'user0', |
| 434 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 435 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 436 | u'id': 338}, |
| 437 | u'active': 0, |
| 438 | u'id': 101084}])], |
| 439 | out_words_ok=['test_job0', 'test_job1']) |
| 440 | |
| 441 | |
| 442 | def test_job_stat_multi_jobs_name_id(self): |
| 443 | self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180'], |
| 444 | rpcs=[('get_jobs_summary', {'id__in': ['180']}, |
| 445 | True, |
| 446 | [{u'status_counts': {u'Aborted': 1}, |
| 447 | u'control_file': |
| 448 | u"job.run_test('sleeptest')\n", |
| 449 | u'name': u'job0', |
| 450 | u'control_type': u'Server', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 451 | u'priority': |
| 452 | u'Medium', |
| 453 | u'owner': u'user0', |
| 454 | u'created_on': |
| 455 | u'2008-07-08 17:45:44', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 456 | u'synch_count': 2, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 457 | u'id': 180}]), |
| 458 | ('get_jobs_summary', {'name__in': ['mytest']}, |
| 459 | True, |
| 460 | [{u'status_counts': {u'Queued': 1}, |
| 461 | u'control_file': |
| 462 | u"job.run_test('sleeptest')\n", |
| 463 | u'name': u'mytest', |
| 464 | u'control_type': u'Client', |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 465 | u'priority': |
| 466 | u'High', |
| 467 | u'owner': u'user0', |
| 468 | u'created_on': u'2008-07-08 12:17:47', |
| 469 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 470 | u'id': 338}]), |
| 471 | ('get_host_queue_entries', |
| 472 | {'job__in': ['180']}, |
| 473 | True, |
| 474 | [{u'status': u'Failed', |
| 475 | u'complete': 1, |
| 476 | u'host': {u'status': u'Repair Failed', |
| 477 | u'locked': 0, |
| 478 | u'hostname': u'host0', |
| 479 | u'invalid': 1, |
| 480 | u'id': 4432, |
| 481 | u'synch_id': None}, |
| 482 | u'priority': 1, |
| 483 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 484 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 485 | u'name': u'test_sleep', |
| 486 | u'control_type': u'Server', |
| 487 | u'synchronizing': 0, |
| 488 | u'priority': u'Medium', |
| 489 | u'owner': u'user0', |
| 490 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 491 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 492 | u'id': 180}, |
| 493 | u'active': 0, |
| 494 | u'id': 101084}]), |
| 495 | ('get_host_queue_entries', |
| 496 | {'job__name__in': ['mytest']}, |
| 497 | True, |
| 498 | [{u'status': u'Failed', |
| 499 | u'complete': 1, |
| 500 | u'host': {u'status': u'Repair Failed', |
| 501 | u'locked': 0, |
| 502 | u'hostname': u'host10', |
| 503 | u'invalid': 1, |
| 504 | u'id': 4432, |
| 505 | u'synch_id': None}, |
| 506 | u'priority': 1, |
| 507 | u'meta_host': None, |
| jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 508 | 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)", |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 509 | u'name': u'test_sleep', |
| 510 | u'control_type': u'Server', |
| 511 | u'synchronizing': 0, |
| 512 | u'priority': u'Medium', |
| 513 | u'owner': u'user0', |
| 514 | u'created_on': u'2008-03-18 11:27:29', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 515 | u'synch_count': 1, |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 516 | u'id': 338}, |
| 517 | u'active': 0, |
| 518 | u'id': 101084}])], |
| 519 | out_words_ok=['job0', 'mytest', 'Aborted', 'Queued', |
| 520 | 'Failed', 'Medium', 'High']) |
| 521 | |
| 522 | |
| 523 | class job_create_unittest(cli_mock.cli_unittest): |
| 524 | 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)' |
| 525 | |
| 526 | kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'kernel\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\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)' |
| 527 | |
| 528 | data = {'priority': 'Medium', 'control_file': ctrl_file, 'hosts': ['host0'], |
| mbligh | 6fee7fd | 2008-10-10 15:44:39 +0000 | [diff] [blame] | 529 | 'name': 'test_job0', 'control_type': 'Client', 'email_list': '', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 530 | 'meta_hosts': [], 'synch_count': 1, 'dependencies': []} |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 531 | |
| 532 | |
| 533 | def test_execute_create_job(self): |
| 534 | self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest', |
| 535 | 'test_job0', '-m', 'host0'], |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 536 | rpcs=[('generate_control_file', |
| 537 | {'tests': ['sleeptest'], 'use_container': False}, |
| 538 | True, |
| 539 | {'control_file' : self.ctrl_file, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 540 | 'synch_count' : 1, |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 541 | 'is_server' : False, |
| 542 | 'dependencies' : []}), |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 543 | ('create_job', self.data, True, 180)], |
| 544 | out_words_ok=['test_job0', 'Created'], |
| 545 | out_words_no=['Uploading', 'Done']) |
| 546 | |
| 547 | |
| 548 | def test_execute_create_job_with_control(self): |
| 549 | filename = cli_mock.create_file(self.ctrl_file) |
| 550 | self.run_cmd(argv=['atest', 'job', 'create', '-f', filename, |
| 551 | 'test_job0', '-m', 'host0'], |
| 552 | rpcs=[('create_job', self.data, True, 42)], |
| 553 | out_words_ok=['test_job0', 'Created'], |
| 554 | out_words_no=['Uploading', 'Done']) |
| 555 | |
| 556 | |
| mbligh | 0a66913 | 2008-10-10 20:02:32 +0000 | [diff] [blame] | 557 | def test_execute_create_job_with_control_and_email(self): |
| 558 | data = self.data.copy() |
| 559 | data['email_list'] = 'em' |
| 560 | filename = cli_mock.create_file(self.ctrl_file) |
| 561 | self.run_cmd(argv=['atest', 'job', 'create', '-f', filename, |
| 562 | 'test_job0', '-m', 'host0', '-e', 'em'], |
| 563 | rpcs=[('create_job', data, True, 42)], |
| 564 | out_words_ok=['test_job0', 'Created'], |
| 565 | out_words_no=['Uploading', 'Done']) |
| 566 | |
| 567 | |
| mbligh | b9a8b16 | 2008-10-29 16:47:29 +0000 | [diff] [blame] | 568 | def test_execute_create_job_with_control_and_label(self): |
| mbligh | 0a66913 | 2008-10-10 20:02:32 +0000 | [diff] [blame] | 569 | data = self.data.copy() |
| 570 | data['dependencies'] = ['dep1', 'dep2'] |
| 571 | filename = cli_mock.create_file(self.ctrl_file) |
| 572 | self.run_cmd(argv=['atest', 'job', 'create', '-f', filename, |
| mbligh | b9a8b16 | 2008-10-29 16:47:29 +0000 | [diff] [blame] | 573 | 'test_job0', '-m', 'host0', '-b', 'dep1, dep2 '], |
| mbligh | 0a66913 | 2008-10-10 20:02:32 +0000 | [diff] [blame] | 574 | rpcs=[('create_job', data, True, 42)], |
| 575 | out_words_ok=['test_job0', 'Created'], |
| 576 | out_words_no=['Uploading', 'Done']) |
| 577 | |
| 578 | |
| showard | 7bce102 | 2008-11-14 22:51:05 +0000 | [diff] [blame] | 579 | def test_execute_create_job_with_synch_count(self): |
| 580 | data = self.data.copy() |
| 581 | data['synch_count'] = 2 |
| 582 | filename = cli_mock.create_file(self.ctrl_file) |
| 583 | self.run_cmd(argv=['atest', 'job', 'create', '-f', filename, |
| 584 | 'test_job0', '-m', 'host0', '-y', '2'], |
| 585 | rpcs=[('create_job', data, True, 42)], |
| 586 | out_words_ok=['test_job0', 'Created'], |
| 587 | out_words_no=['Uploading', 'Done']) |
| 588 | |
| 589 | |
| mbligh | b9a8b16 | 2008-10-29 16:47:29 +0000 | [diff] [blame] | 590 | def test_execute_create_job_with_test_and_label(self): |
| 591 | data = self.data.copy() |
| 592 | data['dependencies'] = ['dep1', 'dep2', 'dep3'] |
| 593 | self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest', |
| 594 | 'test_job0', '-m', 'host0', '-b', 'dep1, dep2 '], |
| 595 | rpcs=[('generate_control_file', |
| 596 | {'tests': ['sleeptest'], 'use_container': False}, |
| 597 | True, |
| 598 | {'control_file' : self.ctrl_file, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 599 | 'synch_count' : 1, |
| mbligh | b9a8b16 | 2008-10-29 16:47:29 +0000 | [diff] [blame] | 600 | 'is_server' : False, |
| 601 | 'dependencies' : ['dep3']}), |
| 602 | ('create_job', data, True, 42)], |
| 603 | out_words_ok=['test_job0', 'Created'], |
| 604 | out_words_no=['Uploading', 'Done']) |
| 605 | |
| 606 | |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 607 | def test_execute_create_job_with_kernel(self): |
| 608 | data = self.data.copy() |
| 609 | data['control_file'] = self.kernel_ctrl_file |
| 610 | self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest', |
| 611 | '-k', 'kernel', 'test_job0', '-m', 'host0'], |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 612 | rpcs=[('generate_control_file', |
| 613 | {'tests': ['sleeptest'], 'use_container': False, |
| 614 | 'kernel': 'kernel', 'do_push_packages': True}, |
| 615 | True, |
| 616 | {'control_file' : self.kernel_ctrl_file, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 617 | 'synch_count' : 1, |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 618 | 'is_server' : False, |
| 619 | 'dependencies' : []}), |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 620 | ('create_job', data, True, 180)], |
| 621 | out_words_ok=['test_job0', 'Created', |
| 622 | 'Uploading', 'Done']) |
| 623 | |
| 624 | |
| 625 | def test_execute_create_job_with_kernel_spaces(self): |
| 626 | data = self.data.copy() |
| 627 | data['control_file'] = self.kernel_ctrl_file |
| 628 | data['name'] = 'test job with spaces' |
| 629 | self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest', |
| 630 | '-k', 'kernel', 'test job with spaces', |
| 631 | '-m', 'host0'], |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 632 | rpcs=[('generate_control_file', |
| 633 | {'tests': ['sleeptest'], 'use_container': False, |
| 634 | 'kernel': 'kernel', 'do_push_packages': True}, |
| 635 | True, |
| 636 | {'control_file' : self.kernel_ctrl_file, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 637 | 'synch_count' : 1, |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 638 | 'is_server' : False, |
| 639 | 'dependencies' : []}), |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 640 | ('create_job', data, True, 180)], |
| 641 | # This is actually 8 spaces, |
| 642 | # the tab has been converted by print. |
| 643 | out_words_ok=['test job with spaces', 'Created', |
| 644 | 'id', '180']) |
| 645 | |
| 646 | |
| 647 | def test_execute_create_job_no_args(self): |
| 648 | testjob = job.job_create() |
| 649 | sys.argv = ['atest', 'job', 'create'] |
| 650 | self.god.mock_io() |
| 651 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 652 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 653 | self.god.unmock_io() |
| 654 | |
| 655 | |
| 656 | def test_execute_create_job_no_hosts(self): |
| 657 | testjob = job.job_create() |
| 658 | filename = cli_mock.create_file(self.ctrl_file) |
| 659 | sys.argv = ['atest', '-f', filename, 'test_job0'] |
| 660 | self.god.mock_io() |
| 661 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 662 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 663 | self.god.unmock_io() |
| 664 | |
| 665 | |
| 666 | def test_execute_create_job_cfile_and_tests(self): |
| 667 | testjob = job.job_create() |
| 668 | sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f', |
| 669 | 'control_file', 'test_job0', '-m', 'host0'] |
| 670 | self.god.mock_io() |
| 671 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 672 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 673 | self.god.unmock_io() |
| 674 | |
| 675 | |
| 676 | def test_execute_create_job_container_and_server(self): |
| 677 | testjob = job.job_create() |
| 678 | sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-s', '-c', |
| 679 | 'test_job0', '-m', 'host0'] |
| 680 | self.god.mock_io() |
| 681 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 682 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 683 | self.god.unmock_io() |
| 684 | |
| 685 | |
| 686 | def test_execute_create_job_cfile_and_kernel(self): |
| 687 | testjob = job.job_create() |
| 688 | sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-k', |
| 689 | 'kernel', 'test_job0', '-m', 'host0'] |
| 690 | self.god.mock_io() |
| 691 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 692 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 693 | self.god.unmock_io() |
| 694 | |
| 695 | |
| 696 | def test_execute_create_job_cfile_and_container(self): |
| 697 | testjob = job.job_create() |
| 698 | sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-c', |
| 699 | 'test_job0', '-m', 'host0'] |
| 700 | self.god.mock_io() |
| 701 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 702 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 703 | self.god.unmock_io() |
| 704 | |
| 705 | |
| 706 | def test_execute_create_job_bad_cfile(self): |
| 707 | testjob = job.job_create() |
| 708 | sys.argv = ['atest', 'job', 'create', '-f', 'control_file', 'test_job0', |
| 709 | '-m', 'host0'] |
| 710 | self.god.mock_io() |
| 711 | sys.exit.expect_call(1).and_raises(IOError) |
| 712 | self.assertRaises(IOError, testjob.parse) |
| 713 | self.god.unmock_io() |
| 714 | |
| 715 | |
| 716 | def test_execute_create_job_bad_priority(self): |
| 717 | testjob = job.job_create() |
| 718 | sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber', |
| 719 | '-m', 'host0', 'test_job0'] |
| 720 | self.god.mock_io() |
| 721 | sys.exit.expect_call(2).and_raises(cli_mock.ExitException) |
| 722 | self.assertRaises(cli_mock.ExitException, testjob.parse) |
| 723 | self.god.unmock_io() |
| 724 | |
| 725 | |
| 726 | def test_execute_create_job_with_mfile(self): |
| 727 | data = self.data.copy() |
| 728 | data['hosts'] = ['host3', 'host2', 'host1', 'host0'] |
| 729 | cfile = cli_mock.create_file(self.ctrl_file) |
| 730 | filename = cli_mock.create_file('host0\nhost1\nhost2\nhost3') |
| 731 | self.run_cmd(argv=['atest', 'job', 'create', '--mlist', filename, '-f', |
| 732 | cfile, 'test_job0'], |
| 733 | rpcs=[('create_job', data, True, 42)], |
| 734 | out_words_ok=['test_job0', 'Created']) |
| 735 | |
| 736 | |
| 737 | def test_execute_create_job_with_container(self): |
| 738 | data = self.data.copy() |
| 739 | self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest', |
| 740 | '-c', 'test_job0', '-m', 'host0'], |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 741 | rpcs=[('generate_control_file', |
| 742 | {'tests': ['sleeptest'], 'use_container': True}, |
| 743 | True, |
| 744 | {'control_file' : self.ctrl_file, |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 745 | 'synch_count' : 1, |
| showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 746 | 'is_server' : False, |
| 747 | 'dependencies' : []}), |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 748 | ('create_job', data, True, 42)], |
| 749 | out_words_ok=['test_job0', 'Created']) |
| 750 | |
| 751 | |
| 752 | def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]): |
| 753 | testjob = job.job_create() |
| 754 | (hosts, meta_hosts) = testjob.parse_hosts(args) |
| 755 | self.assertEqualNoOrder(hosts, exp_hosts) |
| 756 | self.assertEqualNoOrder(meta_hosts, exp_meta_hosts) |
| 757 | |
| 758 | |
| 759 | def test_parse_hosts_regular(self): |
| 760 | self._test_parse_hosts(['host0'], ['host0']) |
| 761 | |
| 762 | |
| 763 | def test_parse_hosts_regulars(self): |
| 764 | self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1']) |
| 765 | |
| 766 | |
| 767 | def test_parse_hosts_meta_one(self): |
| 768 | self._test_parse_hosts(['*meta0'], [], ['meta0']) |
| 769 | |
| 770 | |
| 771 | def test_parse_hosts_meta_five(self): |
| 772 | self._test_parse_hosts(['5*meta0'], [], ['meta0']*5) |
| 773 | |
| 774 | |
| 775 | def test_parse_hosts_metas_five(self): |
| 776 | self._test_parse_hosts(['5*meta0', '2*meta1'], [], |
| 777 | ['meta0']*5 + ['meta1']*2) |
| 778 | |
| 779 | |
| 780 | def test_parse_hosts_mix(self): |
| 781 | self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1', |
| 782 | '*meta2'], ['host0', 'host1'], |
| 783 | ['meta0']*5 + ['meta1']*2 + ['meta2']) |
| 784 | |
| 785 | |
| 786 | class job_abort_unittest(cli_mock.cli_unittest): |
| 787 | results = [{u'status_counts': {u'Aborted': 1}, u'control_file': |
| 788 | u"job.run_test('sleeptest')\n", u'name': u'test_job0', |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 789 | u'control_type': u'Server', u'priority': |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 790 | u'Medium', u'owner': u'user0', u'created_on': |
| showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 791 | u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}] |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 792 | |
| 793 | def test_execute_job_abort(self): |
| 794 | self.run_cmd(argv=['atest', 'job', 'abort', '180'], |
| mbligh | 206d50a | 2008-11-13 01:19:25 +0000 | [diff] [blame] | 795 | rpcs=[('abort_host_queue_entries', |
| 796 | {'job__id__in': ['180']}, True, None)], |
| 797 | out_words_ok=['Aborting', '180']) |
| mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 798 | |
| 799 | |
| 800 | if __name__ == '__main__': |
| 801 | unittest.main() |