From 4e7a4c4899c545e25365991c26cc2462a1d05356 Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Mar 04 2021 14:51:17 +0000 Subject: Docs and tests for the RemoteRule with empty rules This fixes #603 JIRA: RHELWF-2189 --- diff --git a/docs/policies.rst b/docs/policies.rst index cfab7e8..65656a9 100644 --- a/docs/policies.rst +++ b/docs/policies.rst @@ -107,6 +107,10 @@ The document is a map (dictionary) with the following keys: Currently there are a few rule types, ``PassingTestCaseRule`` being one of them. See the :ref:`rule-types` section below for a full list. + List of rules can be empty if no tests are required for the specified decision + contexts. This is useful in the remote rules. See + :ref:`remoterule-configure-additional-policies` section for details. + ``packages`` (optional) A list of binary RPM package names this policy applies to. @@ -257,7 +261,7 @@ Here's an example of a RemoteRule: id: "test_remoterule" product_versions: - fedora-29 - decision_context: osci_compose_gate + decision_contexts: [osci_compose_gate] subject_type: koji_build excluded_packages: [] rules: @@ -272,6 +276,12 @@ Greenwave will check if a remote rule file exists, if it does, it pulls it down, loads it, and uses it to additionally evaluate the subject of the decision. +If a remote rule file exists it should contain a policy for each required decision +context. If no tests are required for the particular decision context, there +should be empty rules set, i.e. ``rules: []``. In this case the evaluation result +will be ``no tests are required``. If there is no decision context matching the +original policy, the result will be ``Cannot find any applicable policies``. + To be able to get remote rule file, Greenwave requires ``REMOTE_RULE_POLICIES`` option to be set. diff --git a/greenwave/tests/test_api_v1.py b/greenwave/tests/test_api_v1.py index 3147adb..3d8192d 100644 --- a/greenwave/tests/test_api_v1.py +++ b/greenwave/tests/test_api_v1.py @@ -148,6 +148,57 @@ def test_make_decision_with_no_tests_required_and_missing_gating_yaml(mock_resul mock_waivers.assert_not_called() +def test_make_decision_with_no_tests_required_and_empty_remote_rules(mock_results, mock_waivers): + mock_results.return_value = [] + mock_waivers.return_value = [] + policies = """ + --- !Policy + id: "test_policy" + product_versions: + - fedora-rawhide + decision_contexts: + - test_policies + - xyz + subject_type: koji_build + rules: + - !RemoteRule {} + """ + + remote_fragment1 = dedent(""" + --- !Policy + decision_contexts: + - test_policies + - abc + rules: [ ] + """) + + remote_fragment2 = dedent(""" + --- !Policy + decision_contexts: + - foo + - bar + rules: [ ] + """) + + with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: + scm.return_value = ('rpms', 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: + f.return_value = remote_fragment1 + response = make_decision(policies=policies) + assert 200 == response.status_code + assert 'no tests are required' == response.json['summary'] + mock_waivers.assert_not_called() + + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: + f.return_value = remote_fragment2 + response = make_decision(policies=policies) + assert 404 == response.status_code + print(response.json) + assert 'Cannot find any applicable policies for koji_build subjects at gating point ' \ + 'test_policies in fedora-rawhide' == response.json['message'] + mock_waivers.assert_not_called() + + def test_make_decision_with_missing_required_gating_yaml(mock_results, mock_waivers): mock_results.return_value = [] mock_waivers.return_value = []