def main(): """Run a cycle of heartbeat checks to ensure Android device is running.""" logs.configure('android_heartbeat') dates.initialize_timezone_from_environment() environment.set_bot_environment() monitor.initialize() if environment.is_android_cuttlefish(): android.adb.set_cuttlefish_device_serial() device_serial = environment.get_value('ANDROID_SERIAL') while True: state = android.adb.get_device_state() if state == android.adb.DEVICE_NOT_FOUND_STRING.format( serial=device_serial): android.adb.connect_to_cuttlefish_device() state = android.adb.get_device_state() logs.log('Android device %s state: %s' % (device_serial, state)) monitoring_metrics.ANDROID_UPTIME.increment_by( int(state == 'device'), { 'serial': device_serial or '', 'platform': environment.get_platform_group() or '', }) time.sleep(data_types.ANDROID_HEARTBEAT_WAIT_INTERVAL) if data_handler.bot_run_timed_out(): break
def main(): """Prepare the configuration options and start requesting tasks.""" logs.configure('run_bot') root_directory = environment.get_value('ROOT_DIR') if not root_directory: print('Please set ROOT_DIR environment variable to the root of the source ' 'checkout before running. Exiting.') print('For an example, check init.bash in the local directory.') return dates.initialize_timezone_from_environment() environment.set_bot_environment() monitor.initialize() if not profiler.start_if_needed('python_profiler_bot'): sys.exit(-1) fuzzers_init.run() if environment.is_trusted_host(ensure_connected=False): from clusterfuzz._internal.bot.untrusted_runner import host host.init() if environment.is_untrusted_worker(): # Track revision since we won't go into the task_loop. update_task.track_revision() from clusterfuzz._internal.bot.untrusted_runner import \ untrusted as untrusted_worker untrusted_worker.start_server() assert False, 'Unreachable code' while True: # task_loop should be an infinite loop, # unless we run into an exception. error_stacktrace, clean_exit, task_payload = task_loop() # Print the error trace to the console. if not clean_exit: print('Exception occurred while running "%s".' % task_payload) print('-' * 80) print(error_stacktrace) print('-' * 80) should_terminate = ( clean_exit or errors.error_in_list(error_stacktrace, errors.BOT_ERROR_TERMINATION_LIST)) if should_terminate: return logs.log_error( 'Task exited with exception (payload="%s").' % task_payload, error_stacktrace=error_stacktrace) should_hang = errors.error_in_list(error_stacktrace, errors.BOT_ERROR_HANG_LIST) if should_hang: logs.log('Start hanging forever.') while True: # Sleep to avoid consuming 100% of CPU. time.sleep(60) # See if our run timed out, if yes bail out. if data_handler.bot_run_timed_out(): return
def test_initialize(self): """Tests initialization.""" monitor.initialize() self.assertEqual(1, self.mock.start.call_count)
def test_error(self): """Tests error.""" self.mock.check_module_loaded.return_value = False monitor.initialize() self.assertEqual(0, self.mock.start.call_count)
def test_disabled(self): """Tests no initialization when monitoring is disabled in config.""" self.mock.get.return_value = False monitor.initialize() self.assertEqual(0, self.mock.start.call_count)
def test_local(self): """Tests no initialization on local development.""" os.environ['LOCAL_DEVELOPMENT'] = '1' monitor.initialize() self.assertEqual(0, self.mock.start.call_count)