def test_remote_rule_exclude_no_source(mock_retrieve_scm_from_koji): policy_yaml = dedent(""" --- !Policy id: "some_policy" product_versions: [rhel-9000] decision_context: bodhi_update_push_stable subject_type: koji_build rules: - !RemoteRule {} """) nvr = 'nethack-1.2.3-1.el9000' app = create_app('greenwave.config.TestingConfig') with app.app_context(): subject = create_subject('koji_build', nvr) policies = Policy.safe_load_all(policy_yaml) assert len(policies) == 1 policy = policies[0] assert len(policy.rules) == 1 rule = policy.rules[0] mock_retrieve_scm_from_koji.side_effect = NoSourceException assert rule.matches(policy, subject=subject) assert rule.matches(policy, subject=subject, testcase='some_test_case') assert rule.matches(policy, subject=subject, testcase='other_test_case') decision = Decision('bodhi_update_push_stable', 'rhel-9000') decision.check(subject, policies, results_retriever=None) assert decision.answers == []
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 make_decision(policies=DEFAULT_DECISION_POLICIES, **kwargs): app = create_app('greenwave.config.TestingConfig') app.config['policies'] = Policy.safe_load_all(dedent(policies)) client = app.test_client() data = DEFAULT_DECISION_DATA.copy() data.update(kwargs) return client.post('/api/v1.0/decision', json=data)
def announcement_subject(message): cls = greenwave.consumers.resultsdb.ResultsDBHandler app = create_app() with app.app_context(): subject = cls.announcement_subject(message) if subject: return subject.to_dict()
def test_retrieve_scm_from_koji_build_not_found(koji_proxy): nvr = 'foo-1.2.3-1.fc29' app = create_app('greenwave.config.TestingConfig') with app.app_context(): expected_error = '404 Not Found: Failed to find Koji build for "{}" at "{}"'.format( nvr, app.config['KOJI_BASE_URL'] ) koji_proxy.getBuild.return_value = {} with pytest.raises(NotFound, match=expected_error): retrieve_scm_from_koji(nvr)
def test_remote_rule_include_failures(mock_retrieve_scm_from_koji, mock_retrieve_yaml_remote_rule): policy_yaml = dedent(""" --- !Policy id: "some_policy" product_versions: [rhel-9000] decision_context: bodhi_update_push_stable subject_type: koji_build rules: - !RemoteRule {} """) nvr = 'nethack-1.2.3-1.el9000' mock_retrieve_scm_from_koji.return_value = ('rpms', nvr, '123') app = create_app('greenwave.config.TestingConfig') with app.app_context(): subject = create_subject('koji_build', nvr) policies = Policy.safe_load_all(policy_yaml) assert len(policies) == 1 policy = policies[0] assert len(policy.rules) == 1 rule = policy.rules[0] # Include any failure fetching/parsing remote rule file in the # decision. mock_retrieve_yaml_remote_rule.return_value = "--- !Policy" assert rule.matches(policy, subject=subject, testcase='other_test_case') decision = Decision('bodhi_update_push_stable', 'rhel-9000') decision.check(subject, policies, results_retriever=None) assert len(decision.answers) == 2 assert decision.answers[1].test_case_name == 'invalid-gating-yaml' # Reload rules to clear cache. policies = Policy.safe_load_all(policy_yaml) mock_retrieve_scm_from_koji.side_effect = NotFound assert rule.matches(policy, subject=subject, testcase='other_test_case') decision = Decision('bodhi_update_push_stable', 'rhel-9000') decision.check(subject, policies, results_retriever=None) assert [x.to_json()['type'] for x in decision.answers] == ['failed-fetch-gating-yaml'] assert decision.answers[ 0].error == f'Koji build not found for {subject}'
def test_invalid_nvr_iden(mock_retrieve_scm_from_koji, mock_retrieve_yaml_remote_rule): policy_yaml = dedent(""" --- !Policy id: "some_policy" product_versions: [rhel-9000] decision_context: bodhi_update_push_stable subject_type: koji_build rules: - !RemoteRule {} """) nvr = 'nieco' mock_retrieve_scm_from_koji.side_effect = xmlrpc.client.Fault(1000, nvr) app = create_app('greenwave.config.TestingConfig') with app.app_context(): subject = create_subject('koji_build', nvr) policies = Policy.safe_load_all(policy_yaml) policy = policies[0] assert 'Koji XMLRPC fault' in str( RemoteRule._get_sub_policies(None, policy, subject)[1][0])
def test_match_remote_rule(mock_retrieve_scm_from_koji, mock_retrieve_yaml_remote_rule): policy_yaml = dedent(""" --- !Policy id: "some_policy" product_versions: [rhel-9000] decision_context: bodhi_update_push_stable subject_type: koji_build rules: - !RemoteRule {} """) mock_retrieve_yaml_remote_rule.return_value = dedent(""" --- !Policy product_versions: [rhel-*] decision_context: bodhi_update_push_stable rules: - !PassingTestCaseRule {test_case_name: some_test_case} """) nvr = 'nethack-1.2.3-1.el9000' mock_retrieve_scm_from_koji.return_value = ('rpms', nvr, '123') app = create_app('greenwave.config.TestingConfig') with app.app_context(): subject = create_subject('koji_build', nvr) policies = Policy.safe_load_all(policy_yaml) assert len(policies) == 1 policy = policies[0] assert len(policy.rules) == 1 rule = policy.rules[0] assert rule.matches(policy) assert rule.matches(policy, subject=subject) assert rule.matches(policy, subject=subject, testcase='some_test_case') assert not rule.matches( policy, subject=subject, testcase='other_test_case')
#!/usr/bin/python # SPDX-License-Identifier: GPL-2.0+ import logging from greenwave.app_factory import create_app from greenwave.logger import init_logging, log_to_stdout if __name__ == '__main__': app = create_app('greenwave.config.DevelopmentConfig') init_logging() log_to_stdout(level=logging.DEBUG) app.run( host=app.config['HOST'], port=app.config['PORT'], debug=app.config['DEBUG'], )
def app(): app = create_app(config_obj='greenwave.config.TestingConfig') with app.app_context(): yield app
def test_guess_product_version_failure(nvr): app = create_app() with app.app_context(): subject = create_subject('koji_build', nvr) product_version = subject_product_version(subject) assert product_version is None
# SPDX-License-Identifier: GPL-2.0+ import logging from greenwave.logger import init_logging, log_to_stdout from greenwave.app_factory import create_app init_logging() log_to_stdout(logging.DEBUG) app = create_app()