def __init__(self, queue_entries, log_file_name): super(PostJobTask, self).__init__(log_file_name=log_file_name) self.queue_entries = queue_entries self._autoserv_monitor = pidfile_monitor.PidfileRunMonitor() self._autoserv_monitor.attach_to_existing_process( self._working_directory())
def test_sync_refresh(self): """Test drone manager sync refresh.""" mock_drone = self.create_drone('fakedrone1', 'fakehost1') self.manager._drones[mock_drone.hostname] = mock_drone # Insert some drone_utility results into the results queue, then # check that get_results returns it in the right format, and that # the rest of sync_refresh populates the right datastructures for # correct handling of agents. Also confirm that this method of # syncing is sufficient for the monitor to pick up the exit status # of the process in the same way it would in handle_agents. pidfile_path = 'results/hosts/host_id/job_id-name/.autoserv_execute' pidfiles = {pidfile_path: '123\n12\n0\n'} drone_utility_results = { 'pidfiles': pidfiles, 'autoserv_processes': {}, 'all_processes': {}, 'parse_processes': {}, 'pidfiles_second_read': pidfiles, } # Our manager instance isn't the drone manager singletone that the # pidfile_monitor will use by default, becuase setUp doesn't call # drone_manager.instance(). self.god.stub_with(drone_manager, '_the_instance', self.manager) monitor = pidfile_monitor.PidfileRunMonitor() monitor.pidfile_id = drone_manager.PidfileId(pidfile_path) self.manager.register_pidfile(monitor.pidfile_id) self.assertTrue(monitor._state.exit_status == None) self.manager._refresh_task_queue.results_queue.put( thread_lib.ThreadedTaskQueue.result(mock_drone, [drone_utility_results])) self.manager.sync_refresh() pidfiles = self.manager._pidfiles pidfile_id = pidfiles.keys()[0] pidfile_contents = pidfiles[pidfile_id] self.assertTrue( pidfile_id.path == pidfile_path and pidfile_contents.process.pid == 123 and pidfile_contents.process.hostname == mock_drone.hostname and pidfile_contents.exit_status == 12 and pidfile_contents.num_tests_failed == 0) self.assertTrue(monitor.exit_code() == 12) self.god.check_playback()
def setUp(self): self.god = mock.mock_god() self.mock_drone_manager = self.god.create_mock_class( drone_manager.DroneManager, 'drone_manager') self.god.stub_with(drone_manager, '_the_instance', self.mock_drone_manager) self.god.stub_with(pidfile_monitor, '_get_pidfile_timeout_secs', self._mock_get_pidfile_timeout_secs) self.pidfile_id = object() (self.mock_drone_manager.get_pidfile_id_from.expect_call( self.execution_tag, pidfile_name=drone_manager.AUTOSERV_PID_FILE).and_return( self.pidfile_id)) self.monitor = pidfile_monitor.PidfileRunMonitor() self.monitor.attach_to_existing_process(self.execution_tag)
def _create_monitor(self): assert not self.monitor self.monitor = pidfile_monitor.PidfileRunMonitor()