def setUpClass(cls): logs.configure_for_tests() os.environ['HOST_INSTANCE_NAME'] = 'host' os.environ['HOST_INSTANCE_NUM'] = '0' os.environ['BOT_NAME'] = 'host-0' os.environ['LOCAL_DEVELOPMENT'] = 'True' os.environ['SOURCE_VERSION_OVERRIDE'] = 'VERSION' os.environ['CONFIG_DIR_OVERRIDE'] = os.path.abspath( os.path.join(os.environ['ROOT_DIR'], 'configs', 'test')) cert_location = os.path.join(TEST_LIBS_DATA_DIR, 'untrusted_cert.pem') key_location = os.path.join(TEST_LIBS_DATA_DIR, 'untrusted_key.pem') os.environ['UNTRUSTED_TLS_CERT_FOR_TESTING'] = cert_location os.environ['UNTRUSTED_TLS_KEY_FOR_TESTING'] = key_location cls.bot_proc, bot_root_dir = _create_test_bot() os.environ['TRUSTED_HOST'] = 'True' os.environ['WORKER_ROOT_DIR'] = bot_root_dir os.environ['WORKER_BOT_TMPDIR'] = os.path.join(bot_root_dir, 'bot_tmpdir') # Explicitly patch datastore.ndb here, as otherwise we patch # google.appengine.ext.ndb which is not what is imported everywhere. ndb_patcher.patch_ndb(ndb) environment.set_default_vars() data_types.HostWorkerAssignment(host_name='host', instance_num=0, worker_name='localhost', project_name='project', id='host-0').put() with open(cert_location) as f: cert_contents = f.read() with open(key_location) as f: key_contents = f.read() data_types.WorkerTlsCert(project_name='project', cert_contents=cert_contents, key_contents=key_contents, id='project').put() host.init()
def setUpClass(cls): cls.saved_env = os.environ.copy() os.environ['HOST_INSTANCE_NAME'] = 'host' os.environ['HOST_INSTANCE_NUM'] = '0' os.environ['BOT_NAME'] = 'host-0' os.environ['LOCAL_DEVELOPMENT'] = 'True' os.environ['SOURCE_VERSION_OVERRIDE'] = 'VERSION' os.environ['CONFIG_DIR_OVERRIDE'] = os.path.abspath( os.path.join(os.environ['ROOT_DIR'], 'configs', 'test')) cert_location = os.path.join(TEST_LIBS_DATA_DIR, 'untrusted_cert.pem') key_location = os.path.join(TEST_LIBS_DATA_DIR, 'untrusted_key.pem') os.environ['UNTRUSTED_TLS_CERT_FOR_TESTING'] = cert_location os.environ['UNTRUSTED_TLS_KEY_FOR_TESTING'] = key_location cls.bot_proc, bot_root_dir = _create_test_bot() os.environ['TRUSTED_HOST'] = 'True' os.environ['WORKER_ROOT_DIR'] = bot_root_dir os.environ['WORKER_BOT_TMPDIR'] = os.path.join(bot_root_dir, 'bot_tmpdir') environment.set_default_vars() data_types.HostWorkerAssignment(host_name='host', instance_num=0, worker_name='localhost', project_name='project', id='host-0').put() with open(cert_location, 'rb') as f: cert_contents = f.read() with open(key_location, 'rb') as f: key_contents = f.read() data_types.WorkerTlsCert(project_name='project', cert_contents=cert_contents, key_contents=key_contents, id='project').put() host.init()
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) if environment.is_trusted_host(ensure_connected=False): from 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 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.', error_stacktrace=error_stacktrace, task_payload=task_payload) 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 # Clear the current exception. sys.exc_clear()