From 946027136c0dc15ac0df15dbbea5303369b787b6 Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Feb 05 2020 14:27:06 +0000 Subject: Revive DIST_GIT_BASE_URL JIRA: FACTORY-5869 Signed-off-by: Valerij Maljulin --- diff --git a/greenwave/app_factory.py b/greenwave/app_factory.py index fff5b51..d253689 100644 --- a/greenwave/app_factory.py +++ b/greenwave/app_factory.py @@ -57,6 +57,11 @@ def create_app(config_obj=None): log.debug("config: Loading subject types from %r", subject_types_dir) app.config['subject_types'] = load_subject_types(subject_types_dir) + if app.config.get('DIST_GIT_URL_TEMPLATE') and app.config.get('DIST_GIT_BASE_URL'): + app.config['DIST_GIT_URL_TEMPLATE'] = app.config['DIST_GIT_URL_TEMPLATE'].replace( + '{DIST_GIT_BASE_URL}', app.config['DIST_GIT_BASE_URL'] + ) + if not _can_use_remote_rule(app.config) and _has_remote_rule(app.config['policies']): raise RuntimeError( 'If you want to apply a RemoteRule, you must have "KOJI_BASE_URL" and ' diff --git a/greenwave/tests/test_app_factory.py b/greenwave/tests/test_app_factory.py index 9c176b9..621cc1a 100644 --- a/greenwave/tests/test_app_factory.py +++ b/greenwave/tests/test_app_factory.py @@ -38,6 +38,36 @@ def test_remote_rules_misconfigured(mock_load_policies): create_app(config) +@mock.patch('greenwave.policies.load_policies') +def test_remote_rules_base_url(mock_load_policies): + """ + The application shouldn't start if RemoteRule is in policy configuration + but if cannot be used because dist-git or koji URL is not configured. + """ + + policies = Policy.safe_load_all(dedent(""" + --- !Policy + id: test_policy + product_versions: [fedora-rawhide] + decision_context: another_test_context + subject_type: koji_build + rules: + - !RemoteRule {} + """)) + mock_load_policies.return_value = policies + + config = TestingConfig() + config.DIST_GIT_BASE_URL = 'http://localhost.localdomain/' + config.DIST_GIT_URL_TEMPLATE = '{DIST_GIT_BASE_URL}{other_params}/blablabla/gating.yaml' + config.REMOTE_RULE_POLICIES = {} + + app = create_app(config) + + assert app.config['DIST_GIT_URL_TEMPLATE'] == ( + 'http://localhost.localdomain/{other_params}/blablabla/gating.yaml' + ) + + def test_can_use_remote_rule_http_fallback(): """ Test that _can_use_remote_rule verifies the configuration properly if HTTP is used. """ config = {