def test_valid_config(): assert check_configuration({ PROJECTS_PROPERTY: { "foo": { PROXY_PROPERTY: True } }, PROXY_PROPERTY: "proxy" })
def test_valid_config_incoming(): assert check_configuration({ PROJECTS_PROPERTY: { "foo": { INCOMING_PROPERTY: True } }, INCOMING_PROPERTY: "False" })
def test_invalid_configuration_commands_exists_dictionary(): config = { COMMANDS_PROPERTY: { "git": { "command": "/usr/nonexistent/bin/git" } } } assert not check_configuration(config)
def test_configuration_commands_override(): config = { COMMANDS_PROPERTY: { "git": { "sync": ["foo", "bar"], "incoming": ["foo", "bar"] } } } assert check_configuration(config)
def test_valid_config(): assert check_configuration({PROJECTS_PROPERTY: {"foo": {PROXY_PROPERTY: True}}, PROXY_PROPERTY: "proxy"})
def test_invalid_config_option(): assert not check_configuration({"nonexistent": True})
def test_invalid_config_option(): assert not check_configuration({"nonexistent": True})
def test_configuration_commands_dir(): config = {COMMANDS_PROPERTY: {"teamware": "/usr/bin"}} assert check_configuration(config)
def test_configuration_commands_dictionary(): config = {COMMANDS_PROPERTY: {"git": {"command": "/usr/bin/git"}}} assert check_configuration(config)
def test_configuration_commands_string(): config = {COMMANDS_PROPERTY: {"git": "/usr/bin/git"}} assert check_configuration(config)
def test_configuration_commands_dictionary_invalid(): """ If the commands are overriden, they need to match certain keywords. """ config = {COMMANDS_PROPERTY: {"git": {"foo": "bar"}}} assert not check_configuration(config)
def test_invalid_configuration_commands_scm(): """ The names in the commands section should be match recognized SCMs. """ config = {COMMANDS_PROPERTY: {"foo": "bar"}} assert not check_configuration(config)
def test_invalid_configuration_commands_dict(): """ The value of the commands property has to be a dictionary. """ config = {COMMANDS_PROPERTY: "foo"} assert not check_configuration(config)
def main(): log_level = os.environ.get('OPENGROK_LOG_LEVEL') if log_level: log_level = get_log_level(log_level) else: log_level = logging.INFO logger = get_console_logger(get_class_basename(), log_level) uri, url_root = set_url_root(logger, os.environ.get('URL_ROOT')) logger.debug("URL_ROOT = {}".format(url_root)) logger.debug("URI = {}".format(uri)) sync_period = get_num_from_env(logger, 'SYNC_PERIOD_MINUTES', 10) if sync_period == 0: logger.info("periodic synchronization disabled") else: logger.info("synchronization period = {} minutes".format(sync_period)) # Note that deploy is done before Tomcat is started. deploy(logger, url_root) if url_root != '/source': setup_redirect_source(logger, url_root) env = {} extra_indexer_options = os.environ.get('INDEXER_OPT', '') if extra_indexer_options: logger.info("extra indexer options: {}".format(extra_indexer_options)) env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options if os.environ.get(NOMIRROR_ENV_NAME): env['OPENGROK_NO_MIRROR'] = os.environ.get(NOMIRROR_ENV_NAME) logger.debug('Extra environment: {}'.format(env)) use_projects = True if os.environ.get('AVOID_PROJECTS'): use_projects = False # # Create empty configuration to avoid the non existent file exception # in the web app during the first web app startup. # if not os.path.exists(OPENGROK_CONFIG_FILE) or \ os.path.getsize(OPENGROK_CONFIG_FILE) == 0: create_bare_config(logger, use_projects, extra_indexer_options.split()) # # Index check needs read-only configuration so it is placed # right after create_bare_config(). # check_index_and_wipe_out(logger) # # If there is read-only configuration file, merge it with current # configuration. # read_only_config_file = os.environ.get('READONLY_CONFIG_FILE') if read_only_config_file and os.path.exists(read_only_config_file): logger.info('Merging read-only configuration from \'{}\' with current ' 'configuration in \'{}\''.format(read_only_config_file, OPENGROK_CONFIG_FILE)) out_file = None with tempfile.NamedTemporaryFile(mode='w+', delete=False, prefix='merged_config') as tmp_out: out_file = tmp_out.name merge_config_files(read_only_config_file, OPENGROK_CONFIG_FILE, tmp_out, jar=OPENGROK_JAR, loglevel=log_level) if out_file and os.path.getsize(out_file) > 0: shutil.move(tmp_out.name, OPENGROK_CONFIG_FILE) else: logger.warning('Failed to merge read-only configuration, ' 'leaving the original in place') if out_file: os.remove(out_file) sync_enabled = True if use_projects: num_workers = get_num_from_env(logger, 'WORKERS', multiprocessing.cpu_count()) logger.info('Number of sync workers: {}'.format(num_workers)) if not os.environ.get(NOMIRROR_ENV_NAME): mirror_config = os.path.join(OPENGROK_CONFIG_DIR, "mirror.yml") if not os.path.exists(mirror_config): with open(mirror_config, 'w') as fp: fp.write("# Empty config file for opengrok-mirror\n") else: conf = read_config(logger, mirror_config) logger.info("Checking mirror configuration in '{}'".format( mirror_config)) if not check_configuration(conf): logger.error("Mirror configuration in '{}' is invalid, " "disabling sync".format(mirror_config)) sync_enabled = False worker_function = project_syncer syncer_args = (logger, log_level, uri, OPENGROK_CONFIG_FILE, num_workers, env) else: worker_function = indexer_no_projects syncer_args = (logger, uri, OPENGROK_CONFIG_FILE, extra_indexer_options) if sync_enabled: logger.debug("Starting sync thread") sync_thread = threading.Thread(target=worker_function, name="Sync thread", args=syncer_args, daemon=True) sync_thread.start() start_rest_thread(logger) if sync_period > 0: start_timeout_thread(logger, sync_period) # Start Tomcat last. It will be the foreground process. logger.info("Starting Tomcat") global tomcat_popen tomcat_popen = subprocess.Popen( [os.path.join(tomcat_root, 'bin', 'catalina.sh'), 'run']) tomcat_popen.wait()
def test_invalid_configuration_commands_value(): """ The values in the command section should be strings. """ config = {COMMANDS_PROPERTY: {"git": {"foo": "bar"}}} assert not check_configuration(config)