blob: 5ee0fee82fb1f7f41dae6bb721e5297d84426b8b [file] [log] [blame]
showard34ab0992009-10-05 22:47:57 +00001#!/usr/bin/python
2
showard4a604792009-10-20 23:49:10 +00003import logging, os, unittest
showard34ab0992009-10-05 22:47:57 +00004import common
showard7b2d7cb2009-10-28 19:53:03 +00005from autotest_lib.client.common_lib import enum, global_config, host_protections
showard34ab0992009-10-05 22:47:57 +00006from autotest_lib.database import database_connection
7from autotest_lib.frontend import setup_django_environment
showardb8900452009-10-12 20:31:01 +00008from autotest_lib.frontend.afe import frontend_test_utils, models
showard34ab0992009-10-05 22:47:57 +00009from autotest_lib.scheduler import drone_manager, email_manager, monitor_db
10
11# translations necessary for scheduler queries to work with SQLite
12_re_translator = database_connection.TranslatingDatabase.make_regexp_translator
13_DB_TRANSLATORS = (
14 _re_translator(r'NOW\(\)', 'time("now")'),
showardd1195652009-12-08 22:21:02 +000015 _re_translator(r'LAST_INSERT_ID\(\)', 'LAST_INSERT_ROWID()'),
showard34ab0992009-10-05 22:47:57 +000016 # older SQLite doesn't support group_concat, so just don't bother until
17 # it arises in an important query
18 _re_translator(r'GROUP_CONCAT\((.*?)\)', r'\1'),
19)
20
showard4a604792009-10-20 23:49:10 +000021HqeStatus = models.HostQueueEntry.Status
22HostStatus = models.Host.Status
23
showard34ab0992009-10-05 22:47:57 +000024class NullMethodObject(object):
25 _NULL_METHODS = ()
26
27 def __init__(self):
28 def null_method(*args, **kwargs):
29 pass
30
31 for method_name in self._NULL_METHODS:
32 setattr(self, method_name, null_method)
33
34class MockGlobalConfig(object):
35 def __init__(self):
36 self._config_info = {}
37
38
39 def set_config_value(self, section, key, value):
40 self._config_info[(section, key)] = value
41
42
43 def get_config_value(self, section, key, type=str,
44 default=None, allow_blank=False):
45 identifier = (section, key)
46 if identifier not in self._config_info:
47 raise RuntimeError('Unset global config value: %s' % (identifier,))
48 return self._config_info[identifier]
49
50
showardf85a0b72009-10-07 20:48:45 +000051# the SpecialTask names here must match the suffixes used on the SpecialTask
52# results directories
53_PidfileType = enum.Enum('verify', 'cleanup', 'repair', 'job', 'gather',
showard2b38f672009-12-23 00:08:44 +000054 'parse', 'archive')
showardf85a0b72009-10-07 20:48:45 +000055
56
showardd1195652009-12-08 22:21:02 +000057_PIDFILE_TO_PIDFILE_TYPE = {
58 monitor_db._AUTOSERV_PID_FILE: _PidfileType.JOB,
59 monitor_db._CRASHINFO_PID_FILE: _PidfileType.GATHER,
60 monitor_db._PARSER_PID_FILE: _PidfileType.PARSE,
showard2b38f672009-12-23 00:08:44 +000061 monitor_db._ARCHIVER_PID_FILE: _PidfileType.ARCHIVE,
showardd1195652009-12-08 22:21:02 +000062 }
63
64
65_PIDFILE_TYPE_TO_PIDFILE = dict((value, key) for key, value
66 in _PIDFILE_TO_PIDFILE_TYPE.iteritems())
67
68
showard34ab0992009-10-05 22:47:57 +000069class MockDroneManager(NullMethodObject):
showard65db3932009-10-28 19:54:35 +000070 """
71 Public attributes:
72 max_runnable_processes_value: value returned by max_runnable_processes().
73 tests can change this to activate throttling.
74 """
showard4a604792009-10-20 23:49:10 +000075 _NULL_METHODS = ('reinitialize_drones', 'copy_to_results_repository',
76 'copy_results_on_drone')
77
78 class _DummyPidfileId(object):
79 """
80 Object to represent pidfile IDs that is opaque to the scheduler code but
81 still debugging-friendly for us.
82 """
showardd1195652009-12-08 22:21:02 +000083 def __init__(self, working_directory, pidfile_name, num_processes=None):
84 self._working_directory = working_directory
85 self._pidfile_name = pidfile_name
showard418785b2009-11-23 20:19:59 +000086 self._num_processes = num_processes
showardd1195652009-12-08 22:21:02 +000087 self._paired_with_pidfile = None
88
89
90 def key(self):
91 """Key for MockDroneManager._pidfile_index"""
92 return (self._working_directory, self._pidfile_name)
showard4a604792009-10-20 23:49:10 +000093
94
95 def __str__(self):
showardd1195652009-12-08 22:21:02 +000096 return os.path.join(self._working_directory, self._pidfile_name)
showard4a604792009-10-20 23:49:10 +000097
showard34ab0992009-10-05 22:47:57 +000098
showard418785b2009-11-23 20:19:59 +000099 def __repr__(self):
100 return '<_DummyPidfileId: %s>' % str(self)
101
102
showard34ab0992009-10-05 22:47:57 +0000103 def __init__(self):
104 super(MockDroneManager, self).__init__()
showard418785b2009-11-23 20:19:59 +0000105 self.process_capacity = 100
showard65db3932009-10-28 19:54:35 +0000106
showard34ab0992009-10-05 22:47:57 +0000107 # maps result_dir to set of tuples (file_path, file_contents)
108 self._attached_files = {}
109 # maps pidfile IDs to PidfileContents
110 self._pidfiles = {}
111 # pidfile IDs that haven't been created yet
112 self._future_pidfiles = []
showardf85a0b72009-10-07 20:48:45 +0000113 # maps _PidfileType to the most recently created pidfile ID of that type
114 self._last_pidfile_id = {}
showard34ab0992009-10-05 22:47:57 +0000115 # maps (working_directory, pidfile_name) to pidfile IDs
116 self._pidfile_index = {}
showardf85a0b72009-10-07 20:48:45 +0000117 # maps process to pidfile IDs
118 self._process_index = {}
119 # tracks pidfiles of processes that have been killed
120 self._killed_pidfiles = set()
showard4a604792009-10-20 23:49:10 +0000121 # pidfile IDs that have just been unregistered (so will disappear on the
122 # next cycle)
123 self._unregistered_pidfiles = set()
showard34ab0992009-10-05 22:47:57 +0000124
125
126 # utility APIs for use by the test
127
showardf85a0b72009-10-07 20:48:45 +0000128 def finish_process(self, pidfile_type, exit_status=0):
129 pidfile_id = self._last_pidfile_id[pidfile_type]
130 self._set_pidfile_exit_status(pidfile_id, exit_status)
showard34ab0992009-10-05 22:47:57 +0000131
132
showard65db3932009-10-28 19:54:35 +0000133 def finish_specific_process(self, working_directory, pidfile_name):
showardd1195652009-12-08 22:21:02 +0000134 pidfile_id = self.pidfile_from_path(working_directory, pidfile_name)
showard65db3932009-10-28 19:54:35 +0000135 self._set_pidfile_exit_status(pidfile_id, 0)
136
137
showard34ab0992009-10-05 22:47:57 +0000138 def _set_pidfile_exit_status(self, pidfile_id, exit_status):
showardf85a0b72009-10-07 20:48:45 +0000139 assert pidfile_id is not None
showard34ab0992009-10-05 22:47:57 +0000140 contents = self._pidfiles[pidfile_id]
141 contents.exit_status = exit_status
142 contents.num_tests_failed = 0
143
144
showardf85a0b72009-10-07 20:48:45 +0000145 def was_last_process_killed(self, pidfile_type):
146 pidfile_id = self._last_pidfile_id[pidfile_type]
147 return pidfile_id in self._killed_pidfiles
148
149
showard418785b2009-11-23 20:19:59 +0000150 def nonfinished_pidfile_ids(self):
151 return [pidfile_id for pidfile_id, pidfile_contents
showard4a604792009-10-20 23:49:10 +0000152 in self._pidfiles.iteritems()
showard418785b2009-11-23 20:19:59 +0000153 if pidfile_contents.exit_status is None]
154
155
156 def running_pidfile_ids(self):
157 return [pidfile_id for pidfile_id in self.nonfinished_pidfile_ids()
158 if self._pidfiles[pidfile_id].process is not None]
showard4a604792009-10-20 23:49:10 +0000159
160
showardd1195652009-12-08 22:21:02 +0000161 def pidfile_from_path(self, working_directory, pidfile_name):
162 return self._pidfile_index[(working_directory, pidfile_name)]
163
164
showard493beaa2009-12-18 22:44:45 +0000165 def attached_files(self, working_directory):
166 """
167 Return dict mapping path to contents for attached files with specified
168 paths.
169 """
170 return dict((path, contents) for path, contents
171 in self._attached_files.get(working_directory, [])
172 if path is not None)
173
174
showard34ab0992009-10-05 22:47:57 +0000175 # DroneManager emulation APIs for use by monitor_db
176
177 def get_orphaned_autoserv_processes(self):
178 return set()
179
180
181 def total_running_processes(self):
showard418785b2009-11-23 20:19:59 +0000182 return sum(pidfile_id._num_processes
183 for pidfile_id in self.nonfinished_pidfile_ids())
showard34ab0992009-10-05 22:47:57 +0000184
185
showard9bb960b2009-11-19 01:02:11 +0000186 def max_runnable_processes(self, username):
showard418785b2009-11-23 20:19:59 +0000187 return self.process_capacity - self.total_running_processes()
showard34ab0992009-10-05 22:47:57 +0000188
189
showard4a604792009-10-20 23:49:10 +0000190 def refresh(self):
191 for pidfile_id in self._unregistered_pidfiles:
192 # intentionally handle non-registered pidfiles silently
193 self._pidfiles.pop(pidfile_id, None)
194 self._unregistered_pidfiles = set()
195
196
showard34ab0992009-10-05 22:47:57 +0000197 def execute_actions(self):
198 # executing an "execute_command" causes a pidfile to be created
199 for pidfile_id in self._future_pidfiles:
200 # Process objects are opaque to monitor_db
showardf85a0b72009-10-07 20:48:45 +0000201 process = object()
202 self._pidfiles[pidfile_id].process = process
203 self._process_index[process] = pidfile_id
showard34ab0992009-10-05 22:47:57 +0000204 self._future_pidfiles = []
205
206
207 def attach_file_to_execution(self, result_dir, file_contents,
208 file_path=None):
209 self._attached_files.setdefault(result_dir, set()).add((file_path,
210 file_contents))
211 return 'attach_path'
212
213
showardf85a0b72009-10-07 20:48:45 +0000214 def _initialize_pidfile(self, pidfile_id):
215 if pidfile_id not in self._pidfiles:
showardd1195652009-12-08 22:21:02 +0000216 assert pidfile_id.key() not in self._pidfile_index
showardf85a0b72009-10-07 20:48:45 +0000217 self._pidfiles[pidfile_id] = drone_manager.PidfileContents()
showardd1195652009-12-08 22:21:02 +0000218 self._pidfile_index[pidfile_id.key()] = pidfile_id
showardf85a0b72009-10-07 20:48:45 +0000219
220
221 def _set_last_pidfile(self, pidfile_id, working_directory, pidfile_name):
222 if working_directory.startswith('hosts/'):
223 # such paths look like hosts/host1/1-verify, we'll grab the end
224 type_string = working_directory.rsplit('-', 1)[1]
225 pidfile_type = _PidfileType.get_value(type_string)
226 else:
showardd1195652009-12-08 22:21:02 +0000227 pidfile_type = _PIDFILE_TO_PIDFILE_TYPE[pidfile_name]
showardf85a0b72009-10-07 20:48:45 +0000228 self._last_pidfile_id[pidfile_type] = pidfile_id
229
230
showard34ab0992009-10-05 22:47:57 +0000231 def execute_command(self, command, working_directory, pidfile_name,
showard418785b2009-11-23 20:19:59 +0000232 num_processes, log_file=None, paired_with_pidfile=None,
showard9bb960b2009-11-19 01:02:11 +0000233 username=None):
showarda9545c02009-12-18 22:44:26 +0000234 logging.debug('Executing %s in %s', command, working_directory)
showardd1195652009-12-08 22:21:02 +0000235 pidfile_id = self._DummyPidfileId(working_directory, pidfile_name)
236 if pidfile_id.key() in self._pidfile_index:
237 pidfile_id = self._pidfile_index[pidfile_id.key()]
238 pidfile_id._num_processes = num_processes
239 pidfile_id._paired_with_pidfile = paired_with_pidfile
240
showard34ab0992009-10-05 22:47:57 +0000241 self._future_pidfiles.append(pidfile_id)
showardf85a0b72009-10-07 20:48:45 +0000242 self._initialize_pidfile(pidfile_id)
showard34ab0992009-10-05 22:47:57 +0000243 self._pidfile_index[(working_directory, pidfile_name)] = pidfile_id
showardf85a0b72009-10-07 20:48:45 +0000244 self._set_last_pidfile(pidfile_id, working_directory, pidfile_name)
showard34ab0992009-10-05 22:47:57 +0000245 return pidfile_id
246
247
248 def get_pidfile_contents(self, pidfile_id, use_second_read=False):
showard4a604792009-10-20 23:49:10 +0000249 if pidfile_id not in self._pidfiles:
showarda9545c02009-12-18 22:44:26 +0000250 logging.debug('Request for nonexistent pidfile %s' % pidfile_id)
showard4a604792009-10-20 23:49:10 +0000251 return self._pidfiles.get(pidfile_id, drone_manager.PidfileContents())
showard34ab0992009-10-05 22:47:57 +0000252
253
254 def is_process_running(self, process):
255 return True
256
257
258 def register_pidfile(self, pidfile_id):
showardf85a0b72009-10-07 20:48:45 +0000259 self._initialize_pidfile(pidfile_id)
260
261
262 def unregister_pidfile(self, pidfile_id):
showard4a604792009-10-20 23:49:10 +0000263 self._unregistered_pidfiles.add(pidfile_id)
showard34ab0992009-10-05 22:47:57 +0000264
265
showardd1195652009-12-08 22:21:02 +0000266 def declare_process_count(self, pidfile_id, num_processes):
267 pidfile_id.num_processes = num_processes
268
269
showard34ab0992009-10-05 22:47:57 +0000270 def absolute_path(self, path):
271 return 'absolute/' + path
272
273
274 def write_lines_to_file(self, file_path, lines, paired_with_process=None):
275 # TODO: record this
276 pass
277
278
279 def get_pidfile_id_from(self, execution_tag, pidfile_name):
showardd1195652009-12-08 22:21:02 +0000280 default_pidfile = self._DummyPidfileId(execution_tag, pidfile_name,
281 num_processes=0)
showard4a604792009-10-20 23:49:10 +0000282 return self._pidfile_index.get((execution_tag, pidfile_name),
showardd1195652009-12-08 22:21:02 +0000283 default_pidfile)
showard34ab0992009-10-05 22:47:57 +0000284
285
showardf85a0b72009-10-07 20:48:45 +0000286 def kill_process(self, process):
287 pidfile_id = self._process_index[process]
288 self._killed_pidfiles.add(pidfile_id)
289 self._set_pidfile_exit_status(pidfile_id, 271)
290
291
showard34ab0992009-10-05 22:47:57 +0000292class MockEmailManager(NullMethodObject):
293 _NULL_METHODS = ('send_queued_emails', 'send_email')
294
showardf85a0b72009-10-07 20:48:45 +0000295 def enqueue_notify_email(self, subject, message):
296 logging.warn('enqueue_notify_email: %s', subject)
297 logging.warn(message)
298
showard34ab0992009-10-05 22:47:57 +0000299
300class SchedulerFunctionalTest(unittest.TestCase,
301 frontend_test_utils.FrontendTestMixin):
302 # some number of ticks after which the scheduler is presumed to have
303 # stabilized, given no external changes
304 _A_LOT_OF_TICKS = 10
305
306 def setUp(self):
307 self._frontend_common_setup()
308 self._set_stubs()
309 self._set_global_config_values()
showardd1195652009-12-08 22:21:02 +0000310 self._create_dispatcher()
showard34ab0992009-10-05 22:47:57 +0000311
312 logging.basicConfig(level=logging.DEBUG)
313
314
showardd1195652009-12-08 22:21:02 +0000315 def _create_dispatcher(self):
316 self.dispatcher = monitor_db.Dispatcher()
317
318
showard34ab0992009-10-05 22:47:57 +0000319 def tearDown(self):
showard78f5b012009-12-23 00:05:59 +0000320 self._database.disconnect()
showard34ab0992009-10-05 22:47:57 +0000321 self._frontend_common_teardown()
322
323
324 def _set_stubs(self):
325 self.mock_config = MockGlobalConfig()
326 self.god.stub_with(global_config, 'global_config', self.mock_config)
327
328 self.mock_drone_manager = MockDroneManager()
329 self.god.stub_with(monitor_db, '_drone_manager',
330 self.mock_drone_manager)
331
332 self.mock_email_manager = MockEmailManager()
333 self.god.stub_with(email_manager, 'manager', self.mock_email_manager)
334
335 self._database = (
336 database_connection.TranslatingDatabase.get_test_database(
showard34ab0992009-10-05 22:47:57 +0000337 translators=_DB_TRANSLATORS))
338 self._database.connect(db_type='django')
339 self.god.stub_with(monitor_db, '_db', self._database)
340
341
342 def _set_global_config_values(self):
343 self.mock_config.set_config_value('SCHEDULER', 'pidfile_timeout_mins',
344 1)
showard2b38f672009-12-23 00:08:44 +0000345 self.mock_config.set_config_value('SCHEDULER', 'gc_stats_interval_mins',
346 999999)
showard34ab0992009-10-05 22:47:57 +0000347
348
349 def _initialize_test(self):
350 self.dispatcher.initialize()
351
352
353 def _run_dispatcher(self):
354 for _ in xrange(self._A_LOT_OF_TICKS):
355 self.dispatcher.tick()
356
357
358 def test_idle(self):
showardb8900452009-10-12 20:31:01 +0000359 self._initialize_test()
showard34ab0992009-10-05 22:47:57 +0000360 self._run_dispatcher()
361
362
showardb8900452009-10-12 20:31:01 +0000363 def _assert_process_executed(self, working_directory, pidfile_name):
364 process_was_executed = self.mock_drone_manager.was_process_executed(
365 'hosts/host1/1-verify', monitor_db._AUTOSERV_PID_FILE)
366 self.assert_(process_was_executed,
367 '%s/%s not executed' % (working_directory, pidfile_name))
368
369
showardd1195652009-12-08 22:21:02 +0000370 def _update_instance(self, model_instance):
371 return type(model_instance).objects.get(pk=model_instance.pk)
372
373
showard418785b2009-11-23 20:19:59 +0000374 def _check_statuses(self, queue_entry, queue_entry_status,
375 host_status=None):
showarda9545c02009-12-18 22:44:26 +0000376 self._check_entry_status(queue_entry, queue_entry_status)
377 if host_status:
378 self._check_host_status(queue_entry.host, host_status)
379
380
381 def _check_entry_status(self, queue_entry, status):
showard4a604792009-10-20 23:49:10 +0000382 # update from DB
showardd1195652009-12-08 22:21:02 +0000383 queue_entry = self._update_instance(queue_entry)
showarda9545c02009-12-18 22:44:26 +0000384 self.assertEquals(queue_entry.status, status)
showard4a604792009-10-20 23:49:10 +0000385
386
showard7b2d7cb2009-10-28 19:53:03 +0000387 def _check_host_status(self, host, status):
388 # update from DB
showarda9545c02009-12-18 22:44:26 +0000389 host = self._update_instance(host)
showard7b2d7cb2009-10-28 19:53:03 +0000390 self.assertEquals(host.status, status)
391
392
showard4a604792009-10-20 23:49:10 +0000393 def _run_pre_job_verify(self, queue_entry):
394 self._run_dispatcher() # launches verify
395 self._check_statuses(queue_entry, HqeStatus.VERIFYING,
396 HostStatus.VERIFYING)
397 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
398
399
showard34ab0992009-10-05 22:47:57 +0000400 def test_simple_job(self):
showardb8900452009-10-12 20:31:01 +0000401 self._initialize_test()
402 job, queue_entry = self._make_job_and_queue_entry()
showard4a604792009-10-20 23:49:10 +0000403 self._run_pre_job_verify(queue_entry)
showard34ab0992009-10-05 22:47:57 +0000404 self._run_dispatcher() # launches job
showard4a604792009-10-20 23:49:10 +0000405 self._check_statuses(queue_entry, HqeStatus.RUNNING, HostStatus.RUNNING)
406 self._finish_job(queue_entry)
407 self._check_statuses(queue_entry, HqeStatus.COMPLETED, HostStatus.READY)
408 self._assert_nothing_is_running()
showardb8900452009-10-12 20:31:01 +0000409
410
showard4a604792009-10-20 23:49:10 +0000411 def _setup_for_pre_job_cleanup(self):
412 self._initialize_test()
413 job, queue_entry = self._make_job_and_queue_entry()
414 job.reboot_before = models.RebootBefore.ALWAYS
415 job.save()
416 return queue_entry
417
418
419 def _run_pre_job_cleanup_job(self, queue_entry):
420 self._run_dispatcher() # cleanup
421 self._check_statuses(queue_entry, HqeStatus.VERIFYING,
422 HostStatus.CLEANING)
423 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP)
424 self._run_dispatcher() # verify
425 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
426 self._run_dispatcher() # job
427 self._finish_job(queue_entry)
428
429
430 def test_pre_job_cleanup(self):
431 queue_entry = self._setup_for_pre_job_cleanup()
432 self._run_pre_job_cleanup_job(queue_entry)
433
434
435 def _run_pre_job_cleanup_one_failure(self):
436 queue_entry = self._setup_for_pre_job_cleanup()
437 self._run_dispatcher() # cleanup
438 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP,
439 exit_status=256)
440 self._run_dispatcher() # repair
441 self._check_statuses(queue_entry, HqeStatus.QUEUED,
442 HostStatus.REPAIRING)
443 self.mock_drone_manager.finish_process(_PidfileType.REPAIR)
444 return queue_entry
445
446
447 def test_pre_job_cleanup_failure(self):
448 queue_entry = self._run_pre_job_cleanup_one_failure()
449 # from here the job should run as normal
450 self._run_pre_job_cleanup_job(queue_entry)
451
452
453 def test_pre_job_cleanup_double_failure(self):
454 # TODO (showard): this test isn't perfect. in reality, when the second
455 # cleanup fails, it copies its results over to the job directory using
456 # copy_results_on_drone() and then parses them. since we don't handle
457 # that, there appear to be no results at the job directory. the
458 # scheduler handles this gracefully, parsing gets effectively skipped,
459 # and this test passes as is. but we ought to properly test that
460 # behavior.
461 queue_entry = self._run_pre_job_cleanup_one_failure()
462 self._run_dispatcher() # second cleanup
463 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP,
464 exit_status=256)
465 self._run_dispatcher()
466 self._check_statuses(queue_entry, HqeStatus.FAILED,
467 HostStatus.REPAIR_FAILED)
468 # nothing else should run
469 self._assert_nothing_is_running()
470
471
472 def _assert_nothing_is_running(self):
473 self.assertEquals(self.mock_drone_manager.running_pidfile_ids(), [])
474
475
showard7b2d7cb2009-10-28 19:53:03 +0000476 def _setup_for_post_job_cleanup(self):
showard4a604792009-10-20 23:49:10 +0000477 self._initialize_test()
478 job, queue_entry = self._make_job_and_queue_entry()
479 job.reboot_after = models.RebootAfter.ALWAYS
480 job.save()
showard7b2d7cb2009-10-28 19:53:03 +0000481 return queue_entry
showard4a604792009-10-20 23:49:10 +0000482
showard7b2d7cb2009-10-28 19:53:03 +0000483
484 def _run_post_job_cleanup_failure_up_to_repair(self, queue_entry,
485 include_verify=True):
486 if include_verify:
487 self._run_pre_job_verify(queue_entry)
showard4a604792009-10-20 23:49:10 +0000488 self._run_dispatcher() # job
489 self.mock_drone_manager.finish_process(_PidfileType.JOB)
490 self._run_dispatcher() # parsing + cleanup
491 self.mock_drone_manager.finish_process(_PidfileType.PARSE)
492 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP,
493 exit_status=256)
494 self._run_dispatcher() # repair, HQE unaffected
mbligh4608b002010-01-05 18:22:35 +0000495 self.mock_drone_manager.finish_process(_PidfileType.ARCHIVE)
496 self._run_dispatcher()
showard4a604792009-10-20 23:49:10 +0000497 return queue_entry
498
499
500 def test_post_job_cleanup_failure(self):
showard7b2d7cb2009-10-28 19:53:03 +0000501 queue_entry = self._setup_for_post_job_cleanup()
502 self._run_post_job_cleanup_failure_up_to_repair(queue_entry)
503 self._check_statuses(queue_entry, HqeStatus.COMPLETED,
504 HostStatus.REPAIRING)
showard4a604792009-10-20 23:49:10 +0000505 self.mock_drone_manager.finish_process(_PidfileType.REPAIR)
506 self._run_dispatcher()
507 self._check_statuses(queue_entry, HqeStatus.COMPLETED, HostStatus.READY)
508
509
510 def test_post_job_cleanup_failure_repair_failure(self):
showard7b2d7cb2009-10-28 19:53:03 +0000511 queue_entry = self._setup_for_post_job_cleanup()
512 self._run_post_job_cleanup_failure_up_to_repair(queue_entry)
showard4a604792009-10-20 23:49:10 +0000513 self.mock_drone_manager.finish_process(_PidfileType.REPAIR,
514 exit_status=256)
515 self._run_dispatcher()
516 self._check_statuses(queue_entry, HqeStatus.COMPLETED,
517 HostStatus.REPAIR_FAILED)
518
519
showardd1195652009-12-08 22:21:02 +0000520 def _ensure_post_job_process_is_paired(self, queue_entry, pidfile_type):
521 pidfile_name = _PIDFILE_TYPE_TO_PIDFILE[pidfile_type]
522 queue_entry = self._update_instance(queue_entry)
523 pidfile_id = self.mock_drone_manager.pidfile_from_path(
524 queue_entry.execution_path(), pidfile_name)
525 self.assert_(pidfile_id._paired_with_pidfile)
526
527
showard4a604792009-10-20 23:49:10 +0000528 def _finish_job(self, queue_entry):
showardf85a0b72009-10-07 20:48:45 +0000529 self.mock_drone_manager.finish_process(_PidfileType.JOB)
showard34ab0992009-10-05 22:47:57 +0000530 self._run_dispatcher() # launches parsing + cleanup
showard4a604792009-10-20 23:49:10 +0000531 self._check_statuses(queue_entry, HqeStatus.PARSING,
532 HostStatus.CLEANING)
showardd1195652009-12-08 22:21:02 +0000533 self._ensure_post_job_process_is_paired(queue_entry, _PidfileType.PARSE)
showard2b38f672009-12-23 00:08:44 +0000534 self._finish_parsing_and_cleanup(queue_entry)
showardf85a0b72009-10-07 20:48:45 +0000535
536
showard2b38f672009-12-23 00:08:44 +0000537 def _finish_parsing_and_cleanup(self, queue_entry):
showardf85a0b72009-10-07 20:48:45 +0000538 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP)
539 self.mock_drone_manager.finish_process(_PidfileType.PARSE)
showard34ab0992009-10-05 22:47:57 +0000540 self._run_dispatcher()
541
mbligh4608b002010-01-05 18:22:35 +0000542 self._check_entry_status(queue_entry, HqeStatus.ARCHIVING)
showard2b38f672009-12-23 00:08:44 +0000543 self.mock_drone_manager.finish_process(_PidfileType.ARCHIVE)
544 self._run_dispatcher()
545
showard34ab0992009-10-05 22:47:57 +0000546
showard7b2d7cb2009-10-28 19:53:03 +0000547 def _create_reverify_request(self):
548 host = self.hosts[0]
549 models.SpecialTask.objects.create(host=host,
showard9bb960b2009-11-19 01:02:11 +0000550 task=models.SpecialTask.Task.VERIFY,
551 requested_by=self.user)
showard7b2d7cb2009-10-28 19:53:03 +0000552 return host
553
554
555 def test_requested_reverify(self):
556 host = self._create_reverify_request()
557 self._run_dispatcher()
558 self._check_host_status(host, HostStatus.VERIFYING)
559 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
560 self._run_dispatcher()
561 self._check_host_status(host, HostStatus.READY)
562
563
564 def test_requested_reverify_failure(self):
565 host = self._create_reverify_request()
566 self._run_dispatcher()
567 self.mock_drone_manager.finish_process(_PidfileType.VERIFY,
568 exit_status=256)
569 self._run_dispatcher() # repair
570 self._check_host_status(host, HostStatus.REPAIRING)
571 self.mock_drone_manager.finish_process(_PidfileType.REPAIR)
572 self._run_dispatcher()
573 self._check_host_status(host, HostStatus.READY)
574
575
576 def _setup_for_do_not_verify(self):
577 self._initialize_test()
578 job, queue_entry = self._make_job_and_queue_entry()
579 queue_entry.host.protection = host_protections.Protection.DO_NOT_VERIFY
580 queue_entry.host.save()
581 return queue_entry
582
583
584 def test_do_not_verify_job(self):
585 queue_entry = self._setup_for_do_not_verify()
586 self._run_dispatcher() # runs job directly
587 self._finish_job(queue_entry)
588
589
590 def test_do_not_verify_job_with_cleanup(self):
591 queue_entry = self._setup_for_do_not_verify()
592 queue_entry.job.reboot_before = models.RebootBefore.ALWAYS
593 queue_entry.job.save()
594
595 self._run_dispatcher() # cleanup
596 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP)
597 self._run_dispatcher() # job
598 self._finish_job(queue_entry)
599
600
601 def test_do_not_verify_pre_job_cleanup_failure(self):
602 queue_entry = self._setup_for_do_not_verify()
603 queue_entry.job.reboot_before = models.RebootBefore.ALWAYS
604 queue_entry.job.save()
605
606 self._run_dispatcher() # cleanup
607 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP,
608 exit_status=256)
609 self._run_dispatcher() # failure ignored; job runs
610 self._finish_job(queue_entry)
611
612
613 def test_do_not_verify_post_job_cleanup_failure(self):
614 queue_entry = self._setup_for_do_not_verify()
615
616 self._run_post_job_cleanup_failure_up_to_repair(queue_entry,
617 include_verify=False)
618 # failure ignored, host still set to Ready
619 self._check_statuses(queue_entry, HqeStatus.COMPLETED, HostStatus.READY)
620 self._run_dispatcher() # nothing else runs
621 self._assert_nothing_is_running()
622
623
624 def test_do_not_verify_requested_reverify_failure(self):
625 host = self._create_reverify_request()
626 host.protection = host_protections.Protection.DO_NOT_VERIFY
627 host.save()
628
629 self._run_dispatcher()
630 self.mock_drone_manager.finish_process(_PidfileType.VERIFY,
631 exit_status=256)
632 self._run_dispatcher()
633 self._check_host_status(host, HostStatus.READY) # ignore failure
634 self._assert_nothing_is_running()
635
636
showardf85a0b72009-10-07 20:48:45 +0000637 def test_job_abort_in_verify(self):
showardb8900452009-10-12 20:31:01 +0000638 self._initialize_test()
showardf85a0b72009-10-07 20:48:45 +0000639 job = self._create_job(hosts=[1])
640 self._run_dispatcher() # launches verify
641 job.hostqueueentry_set.update(aborted=True)
642 self._run_dispatcher() # kills verify, launches cleanup
643 self.assert_(self.mock_drone_manager.was_last_process_killed(
644 _PidfileType.VERIFY))
645 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP)
646 self._run_dispatcher()
647
648
649 def test_job_abort(self):
showardb8900452009-10-12 20:31:01 +0000650 self._initialize_test()
showardf85a0b72009-10-07 20:48:45 +0000651 job = self._create_job(hosts=[1])
652 job.run_verify = False
653 job.save()
654
655 self._run_dispatcher() # launches job
656 job.hostqueueentry_set.update(aborted=True)
657 self._run_dispatcher() # kills job, launches gathering
658 self.assert_(self.mock_drone_manager.was_last_process_killed(
659 _PidfileType.JOB))
660 self.mock_drone_manager.finish_process(_PidfileType.GATHER)
661 self._run_dispatcher() # launches parsing + cleanup
showard2b38f672009-12-23 00:08:44 +0000662 queue_entry = job.hostqueueentry_set.all()[0]
663 self._finish_parsing_and_cleanup(queue_entry)
showardf85a0b72009-10-07 20:48:45 +0000664
665
666 def test_no_pidfile_leaking(self):
showardb8900452009-10-12 20:31:01 +0000667 self._initialize_test()
showardf85a0b72009-10-07 20:48:45 +0000668 self.test_simple_job()
669 self.assertEquals(self.mock_drone_manager._pidfiles, {})
670
671 self.test_job_abort_in_verify()
672 self.assertEquals(self.mock_drone_manager._pidfiles, {})
673
674 self.test_job_abort()
675 self.assertEquals(self.mock_drone_manager._pidfiles, {})
676
677
showardb8900452009-10-12 20:31:01 +0000678 def _make_job_and_queue_entry(self):
679 job = self._create_job(hosts=[1])
680 queue_entry = job.hostqueueentry_set.all()[0]
681 return job, queue_entry
682
683
684 def test_recover_running_no_process(self):
685 # recovery should re-execute a Running HQE if no process is found
686 _, queue_entry = self._make_job_and_queue_entry()
showard4a604792009-10-20 23:49:10 +0000687 queue_entry.status = HqeStatus.RUNNING
showardb8900452009-10-12 20:31:01 +0000688 queue_entry.execution_subdir = '1-myuser/host1'
689 queue_entry.save()
showard4a604792009-10-20 23:49:10 +0000690 queue_entry.host.status = HostStatus.RUNNING
showardb8900452009-10-12 20:31:01 +0000691 queue_entry.host.save()
692
693 self._initialize_test()
694 self._run_dispatcher()
showard4a604792009-10-20 23:49:10 +0000695 self._finish_job(queue_entry)
showardb8900452009-10-12 20:31:01 +0000696
697
698 def test_recover_verifying_hqe_no_special_task(self):
699 # recovery should fail on a Verifing HQE with no corresponding
700 # Verify or Cleanup SpecialTask
701 _, queue_entry = self._make_job_and_queue_entry()
showard4a604792009-10-20 23:49:10 +0000702 queue_entry.status = HqeStatus.VERIFYING
showardb8900452009-10-12 20:31:01 +0000703 queue_entry.save()
704
705 # make some dummy SpecialTasks that shouldn't count
706 models.SpecialTask.objects.create(host=queue_entry.host,
707 task=models.SpecialTask.Task.VERIFY)
708 models.SpecialTask.objects.create(host=queue_entry.host,
709 task=models.SpecialTask.Task.CLEANUP,
710 queue_entry=queue_entry,
711 is_complete=True)
712
713 self.assertRaises(monitor_db.SchedulerError, self._initialize_test)
714
715
716 def _test_recover_verifying_hqe_helper(self, task, pidfile_type):
717 _, queue_entry = self._make_job_and_queue_entry()
showard4a604792009-10-20 23:49:10 +0000718 queue_entry.status = HqeStatus.VERIFYING
showardb8900452009-10-12 20:31:01 +0000719 queue_entry.save()
720
721 special_task = models.SpecialTask.objects.create(
722 host=queue_entry.host, task=task, queue_entry=queue_entry)
723
724 self._initialize_test()
725 self._run_dispatcher()
726 self.mock_drone_manager.finish_process(pidfile_type)
727 self._run_dispatcher()
728 # don't bother checking the rest of the job execution, as long as the
729 # SpecialTask ran
730
731
732 def test_recover_verifying_hqe_with_cleanup(self):
733 # recover an HQE that was in pre-job cleanup
734 self._test_recover_verifying_hqe_helper(models.SpecialTask.Task.CLEANUP,
735 _PidfileType.CLEANUP)
736
737
738 def test_recover_verifying_hqe_with_verify(self):
739 # recover an HQE that was in pre-job verify
740 self._test_recover_verifying_hqe_helper(models.SpecialTask.Task.VERIFY,
741 _PidfileType.VERIFY)
742
743
showarda21b9492009-11-04 20:43:18 +0000744 def test_recover_pending_hqes_with_group(self):
745 # recover a group of HQEs that are in Pending, in the same group (e.g.,
746 # in a job with atomic hosts)
747 job = self._create_job(hosts=[1,2], atomic_group=1)
748 job.save()
749
750 job.hostqueueentry_set.all().update(status=HqeStatus.PENDING)
751
752 self._initialize_test()
753 for queue_entry in job.hostqueueentry_set.all():
754 self.assertEquals(queue_entry.status, HqeStatus.STARTING)
755
756
showardd1195652009-12-08 22:21:02 +0000757 def test_recover_parsing(self):
758 self._initialize_test()
759 job, queue_entry = self._make_job_and_queue_entry()
760 job.run_verify = False
761 job.reboot_after = models.RebootAfter.NEVER
762 job.save()
763
764 self._run_dispatcher() # launches job
765 self.mock_drone_manager.finish_process(_PidfileType.JOB)
766 self._run_dispatcher() # launches parsing
767
768 # now "restart" the scheduler
769 self._create_dispatcher()
770 self._initialize_test()
771 self._run_dispatcher()
772 self.mock_drone_manager.finish_process(_PidfileType.PARSE)
773 self._run_dispatcher()
774
775
776 def test_recover_parsing__no_process_already_aborted(self):
777 _, queue_entry = self._make_job_and_queue_entry()
778 queue_entry.execution_subdir = 'host1'
779 queue_entry.status = HqeStatus.PARSING
780 queue_entry.aborted = True
781 queue_entry.save()
782
783 self._initialize_test()
784 self._run_dispatcher()
785
786
showard65db3932009-10-28 19:54:35 +0000787 def test_job_scheduled_just_after_abort(self):
788 # test a pretty obscure corner case where a job is aborted while queued,
789 # another job is ready to run, and throttling is active. the post-abort
790 # cleanup must not be pre-empted by the second job.
791 job1, queue_entry1 = self._make_job_and_queue_entry()
792 job2, queue_entry2 = self._make_job_and_queue_entry()
793
showard418785b2009-11-23 20:19:59 +0000794 self.mock_drone_manager.process_capacity = 0
showard65db3932009-10-28 19:54:35 +0000795 self._run_dispatcher() # schedule job1, but won't start verify
796 job1.hostqueueentry_set.update(aborted=True)
showard418785b2009-11-23 20:19:59 +0000797 self.mock_drone_manager.process_capacity = 100
showard65db3932009-10-28 19:54:35 +0000798 self._run_dispatcher() # cleanup must run here, not verify for job2
799 self._check_statuses(queue_entry1, HqeStatus.ABORTED,
800 HostStatus.CLEANING)
801 self.mock_drone_manager.finish_process(_PidfileType.CLEANUP)
802 self._run_dispatcher() # now verify starts for job2
803 self._check_statuses(queue_entry2, HqeStatus.VERIFYING,
804 HostStatus.VERIFYING)
805
806
showard65db3932009-10-28 19:54:35 +0000807 def test_reverify_interrupting_pre_job(self):
808 # ensure things behave sanely if a reverify is scheduled in the middle
809 # of pre-job actions
810 _, queue_entry = self._make_job_and_queue_entry()
811
812 self._run_dispatcher() # pre-job verify
813 self._create_reverify_request()
814 self.mock_drone_manager.finish_process(_PidfileType.VERIFY,
815 exit_status=256)
816 self._run_dispatcher() # repair
817 self.mock_drone_manager.finish_process(_PidfileType.REPAIR)
818 self._run_dispatcher() # reverify runs now
819 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
820 self._run_dispatcher() # pre-job verify
821 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
822 self._run_dispatcher() # and job runs...
823 self._check_statuses(queue_entry, HqeStatus.RUNNING, HostStatus.RUNNING)
824 self._finish_job(queue_entry) # reverify has been deleted
825 self._check_statuses(queue_entry, HqeStatus.COMPLETED,
826 HostStatus.READY)
827 self._assert_nothing_is_running()
828
829
830 def test_reverify_while_job_running(self):
831 # once a job is running, a reverify must not be allowed to preempt
832 # Gathering
833 _, queue_entry = self._make_job_and_queue_entry()
834 self._run_pre_job_verify(queue_entry)
835 self._run_dispatcher() # job runs
836 self._create_reverify_request()
837 # make job end with a signal, so gathering will run
838 self.mock_drone_manager.finish_process(_PidfileType.JOB,
839 exit_status=271)
840 self._run_dispatcher() # gathering must start
841 self.mock_drone_manager.finish_process(_PidfileType.GATHER)
842 self._run_dispatcher() # parsing and cleanup
showard2b38f672009-12-23 00:08:44 +0000843 self._finish_parsing_and_cleanup(queue_entry)
showard65db3932009-10-28 19:54:35 +0000844 self._run_dispatcher() # now reverify runs
845 self._check_statuses(queue_entry, HqeStatus.FAILED,
846 HostStatus.VERIFYING)
847 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
848 self._run_dispatcher()
849 self._check_host_status(queue_entry.host, HostStatus.READY)
850
851
852 def test_reverify_while_host_pending(self):
853 # ensure that if a reverify is scheduled while a host is in Pending, it
854 # won't run until the host is actually free
855 job = self._create_job(hosts=[1,2])
856 queue_entry = job.hostqueueentry_set.get(host__hostname='host1')
857 job.synch_count = 2
858 job.save()
859
860 host2 = self.hosts[1]
861 host2.locked = True
862 host2.save()
863
864 self._run_dispatcher() # verify host1
865 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
866 self._run_dispatcher() # host1 Pending
867 self._check_statuses(queue_entry, HqeStatus.PENDING, HostStatus.PENDING)
868 self._create_reverify_request()
869 self._run_dispatcher() # nothing should happen here
870 self._check_statuses(queue_entry, HqeStatus.PENDING, HostStatus.PENDING)
871
872 # now let the job run
873 host2.locked = False
874 host2.save()
875 self._run_dispatcher() # verify host2
876 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
877 self._run_dispatcher() # run job
878 self._finish_job(queue_entry)
879 # need to explicitly finish host1's post-job cleanup
880 self.mock_drone_manager.finish_specific_process(
881 'hosts/host1/4-cleanup', monitor_db._AUTOSERV_PID_FILE)
882 self._run_dispatcher()
883 # the reverify should now be running
884 self._check_statuses(queue_entry, HqeStatus.COMPLETED,
885 HostStatus.VERIFYING)
886 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
887 self._run_dispatcher()
888 self._check_host_status(queue_entry.host, HostStatus.READY)
889
890
showard418785b2009-11-23 20:19:59 +0000891 def test_throttling(self):
892 job = self._create_job(hosts=[1,2,3])
893 job.synch_count = 3
894 job.save()
895
896 queue_entries = list(job.hostqueueentry_set.all())
897 def _check_hqe_statuses(*statuses):
898 for queue_entry, status in zip(queue_entries, statuses):
899 self._check_statuses(queue_entry, status)
900
901 self.mock_drone_manager.process_capacity = 2
902 self._run_dispatcher() # verify runs on 1 and 2
903 _check_hqe_statuses(HqeStatus.VERIFYING, HqeStatus.VERIFYING,
904 HqeStatus.VERIFYING)
905 self.assertEquals(len(self.mock_drone_manager.running_pidfile_ids()), 2)
906
907 self.mock_drone_manager.finish_specific_process(
908 'hosts/host1/1-verify', monitor_db._AUTOSERV_PID_FILE)
909 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
910 self._run_dispatcher() # verify runs on 3
911 _check_hqe_statuses(HqeStatus.PENDING, HqeStatus.PENDING,
912 HqeStatus.VERIFYING)
913
914 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
915 self._run_dispatcher() # job won't run due to throttling
916 _check_hqe_statuses(HqeStatus.STARTING, HqeStatus.STARTING,
917 HqeStatus.STARTING)
918 self._assert_nothing_is_running()
919
920 self.mock_drone_manager.process_capacity = 3
921 self._run_dispatcher() # now job runs
922 _check_hqe_statuses(HqeStatus.RUNNING, HqeStatus.RUNNING,
923 HqeStatus.RUNNING)
924
925 self.mock_drone_manager.process_capacity = 2
926 self.mock_drone_manager.finish_process(_PidfileType.JOB,
927 exit_status=271)
928 self._run_dispatcher() # gathering won't run due to throttling
929 _check_hqe_statuses(HqeStatus.GATHERING, HqeStatus.GATHERING,
930 HqeStatus.GATHERING)
931 self._assert_nothing_is_running()
932
933 self.mock_drone_manager.process_capacity = 3
934 self._run_dispatcher() # now gathering runs
935
936 self.mock_drone_manager.process_capacity = 0
937 self.mock_drone_manager.finish_process(_PidfileType.GATHER)
938 self._run_dispatcher() # parsing runs despite throttling
939 _check_hqe_statuses(HqeStatus.PARSING, HqeStatus.PARSING,
940 HqeStatus.PARSING)
941
942
showard2b38f672009-12-23 00:08:44 +0000943 def test_abort_starting_while_throttling(self):
944 self._initialize_test()
945 job = self._create_job(hosts=[1,2], synchronous=True)
946 queue_entry = job.hostqueueentry_set.all()[0]
947 job.run_verify = False
948 job.reboot_after = models.RebootAfter.NEVER
949 job.save()
950
951 self.mock_drone_manager.process_capacity = 0
952 self._run_dispatcher() # go to starting, but don't start job
953 self._check_statuses(queue_entry, HqeStatus.STARTING,
954 HostStatus.PENDING)
955
956 job.hostqueueentry_set.update(aborted=True)
957 self._run_dispatcher()
958
959
showardd1195652009-12-08 22:21:02 +0000960 def test_simple_atomic_group_job(self):
961 job = self._create_job(atomic_group=1)
962 self._run_dispatcher() # expand + verify
963 queue_entries = job.hostqueueentry_set.all()
964 self.assertEquals(len(queue_entries), 2)
965 self.assertEquals(queue_entries[0].host.hostname, 'host5')
966 self.assertEquals(queue_entries[1].host.hostname, 'host6')
967
968 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
969 self._run_dispatcher() # delay task started waiting
970
971 self.mock_drone_manager.finish_specific_process(
972 'hosts/host5/1-verify', monitor_db._AUTOSERV_PID_FILE)
973 self._run_dispatcher() # job starts now
974 for entry in queue_entries:
975 self._check_statuses(entry, HqeStatus.RUNNING, HostStatus.RUNNING)
976
977 # rest of job proceeds normally
978
979
showard2ca64c92009-12-10 21:41:02 +0000980 def test_simple_metahost_assignment(self):
981 job = self._create_job(metahosts=[1])
982 self._run_dispatcher()
983 entry = job.hostqueueentry_set.all()[0]
984 self.assertEquals(entry.host.hostname, 'host1')
985 self._check_statuses(entry, HqeStatus.VERIFYING, HostStatus.VERIFYING)
986 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
987 self._run_dispatcher()
988 self._check_statuses(entry, HqeStatus.RUNNING, HostStatus.RUNNING)
989 # rest of job proceeds normally
990
991
992 def test_metahost_fail_verify(self):
993 self.hosts[1].labels.add(self.labels[0]) # put label1 also on host2
994 job = self._create_job(metahosts=[1])
995 self._run_dispatcher() # assigned to host1
996 self.mock_drone_manager.finish_process(_PidfileType.VERIFY,
997 exit_status=256)
998 self._run_dispatcher() # host1 failed, gets reassigned to host2
999 entry = job.hostqueueentry_set.all()[0]
1000 self.assertEquals(entry.host.hostname, 'host2')
1001 self._check_statuses(entry, HqeStatus.VERIFYING, HostStatus.VERIFYING)
1002 self._check_host_status(self.hosts[0], HostStatus.REPAIRING)
1003
1004 self.mock_drone_manager.finish_process(_PidfileType.VERIFY)
1005 self._run_dispatcher()
1006 self._check_statuses(entry, HqeStatus.RUNNING, HostStatus.RUNNING)
1007
1008
showarda9545c02009-12-18 22:44:26 +00001009 def test_hostless_job(self):
1010 job = self._create_job(hostless=True)
1011 entry = job.hostqueueentry_set.all()[0]
1012
1013 self._run_dispatcher()
1014 self._check_entry_status(entry, HqeStatus.RUNNING)
1015
1016 self.mock_drone_manager.finish_process(_PidfileType.JOB)
1017 self._run_dispatcher()
1018 self._check_entry_status(entry, HqeStatus.COMPLETED)
1019
1020
showard493beaa2009-12-18 22:44:45 +00001021 def test_pre_job_keyvals(self):
1022 self.test_simple_job()
1023 attached_files = self.mock_drone_manager.attached_files(
1024 '1-my_user/host1')
1025 job_keyval_path = '1-my_user/host1/keyval'
1026 self.assert_(job_keyval_path in attached_files, attached_files)
1027 keyval_contents = attached_files[job_keyval_path]
1028 keyval_dict = dict(line.strip().split('=', 1)
1029 for line in keyval_contents.splitlines())
1030 self.assert_('job_queued' in keyval_dict, keyval_dict)
1031
1032
showard34ab0992009-10-05 22:47:57 +00001033if __name__ == '__main__':
1034 unittest.main()