def test_dosync_check_config_invalid(): commands = ["foo"] with pytest.raises(CommandConfigurationException): do_sync(logging.INFO, commands, None, ["foo", "bar"], [], "http://localhost:8080/source", 42, check_config=True)
def project_syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env): """ Wrapper for running opengrok-sync. To be run in a thread/process in the background. """ wait_for_tomcat(logger, uri) set_config_value(logger, 'projectsEnabled', 'true', uri) while True: refresh_projects(logger, uri) if os.environ.get('OPENGROK_SYNC_YML'): # debug only config_file = os.environ.get('OPENGROK_SYNC_YML') else: config_file = os.path.join(fs_root, 'scripts', 'sync.yml') config = read_config(logger, config_file) if config is None: logger.error("Cannot read config file from {}".format(config_file)) raise Exception("no sync config") projects = list_projects(logger, uri) # # The driveon=True is needed for the initial indexing of newly # added project, otherwise the incoming check in the opengrok-mirror # program would short circuit it. # if env: logger.info('Merging commands with environment') commands = merge_commands_env(config["commands"], env) logger.debug(config['commands']) else: commands = config["commands"] logger.info("Sync starting") do_sync(loglevel, commands, config.get('cleanup'), projects, config.get("ignore_errors"), uri, numworkers, driveon=True, logger=logger, print_output=True) logger.info("Sync done") # Workaround for https://github.com/oracle/opengrok/issues/1670 Path(os.path.join(OPENGROK_DATA_ROOT, 'timestamp')).touch() save_config(logger, uri, config_path) sleep_seconds = sync_period * 60 logger.info("Sleeping for {} seconds".format(sleep_seconds)) time.sleep(sleep_seconds)
def test_dosync_check_config_empty(check_config, expected_times): commands = [] with patch(pool.Pool.map, lambda x, y, z: []): assert do_sync(logging.INFO, commands, None, ["foo", "bar"], [], "http://localhost:8080/source", 42, check_config=check_config) == SUCCESS_EXITVAL verify(pool.Pool, times=expected_times).map(ANY, ANY, ANY)