diff --git a/greenwave/policies.py b/greenwave/policies.py index 0962bbde..d852487d 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -657,23 +657,7 @@ def check(self, policy, rule_context): return answers def matches(self, policy, **attributes): - subject = attributes.get('subject') - if not subject: - return True - - sub_policies = [] - sub_policies, answers = self._get_sub_policies(policy, subject) - - # Include policy if remote rule file is missing. - if not answers: - return True - - # Include any failure fetching/parsing remote rule file in the - # decision. - if any(not answer.is_satisfied for answer in answers): - return True - - return any(sub_policy.matches(**attributes) for sub_policy in sub_policies) + return True def to_json(self): return { diff --git a/greenwave/tests/test_api_v1.py b/greenwave/tests/test_api_v1.py index b290bc04..9d162a8c 100644 --- a/greenwave/tests/test_api_v1.py +++ b/greenwave/tests/test_api_v1.py @@ -156,8 +156,27 @@ def test_make_decision_with_no_tests_required_and_missing_gating_yaml( mock_waivers.assert_not_called() +@pytest.mark.parametrize( + "remote_gating_yaml", + ( + dedent(""" + --- !Policy + decision_contexts: + - test_policies + - abc + rules: [ ] + """), + dedent(""" + --- !Policy + decision_contexts: + - foo + - bar + rules: [ ] + """), + ) +) def test_make_decision_with_no_tests_required_and_empty_remote_rules( - mock_results, mock_waivers, make_decision): + mock_results, mock_waivers, make_decision, remote_gating_yaml): mock_results.return_value = [] mock_waivers.return_value = [] policies = """ @@ -173,39 +192,15 @@ def test_make_decision_with_no_tests_required_and_empty_remote_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 + f.return_value = remote_gating_yaml 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 - assert 'Found no applicable policies for koji_build subjects at gating ' \ - 'point(s) 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, make_decision): mock_results.return_value = [] diff --git a/greenwave/tests/test_listeners.py b/greenwave/tests/test_listeners.py index 8daa262c..3dc27a5e 100644 --- a/greenwave/tests/test_listeners.py +++ b/greenwave/tests/test_listeners.py @@ -539,6 +539,7 @@ def test_remote_rule_decision_change( def test_remote_rule_decision_change_not_matching( + mock_retrieve_decision, mock_retrieve_yaml_remote_rule, mock_retrieve_scm_from_koji, mock_retrieve_results, @@ -546,9 +547,19 @@ def test_remote_rule_decision_change_not_matching( koji_proxy, ): """ - Test publishing decision change message for test cases mentioned in + Test not publishing decision change message for test cases not mentioned in gating.yaml. """ + def retrieve_decision(data, _config): + return { + "policies_satisfied": True, + "summary": "no tests are required", + "satisfied_requirements": [], + "unsatisfied_requirements": [], + } + + mock_retrieve_decision.side_effect = retrieve_decision + gating_yaml = dedent( """ --- !Policy diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 94f189a6..0aa895b5 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -400,7 +400,7 @@ def test_remote_rule_policy_old_config(tmpdir): 'http://localhost.localdomain/nethack/' 'c3c47a08a66451cb9686c49f040776ed35a0d1bb/gating.yaml' ) - assert f.mock_calls == [call, call] + assert f.mock_calls == [call] finally: Config.REMOTE_RULE_POLICIES = config_remote_rules_backup @@ -740,9 +740,7 @@ def test_get_sub_policies_multiple_urls(tmpdir): *scm.return_value ) ) - assert session.request.mock_calls == [ - expected_call1, expected_call2, - expected_call1, expected_call2] + assert session.request.mock_calls == [expected_call1, expected_call2] assert answer_types(decision.answers) == ['missing-gating-yaml'] assert not decision.answers[0].is_satisfied assert decision.answers[0].subject.identifier == subject.identifier @@ -1432,7 +1430,6 @@ def test_on_demand_policy_match(two_rules, koji_proxy): policy_matches = policy.matches(subject=subject) - koji_proxy.getBuild.assert_called_once() assert policy_matches results = DummyResultsRetriever( @@ -1443,6 +1440,8 @@ def test_on_demand_policy_match(two_rules, koji_proxy): if two_rules: assert answer_types(decision.answers) == ['test-result-passed'] + koji_proxy.getBuild.assert_called_once() + def test_remote_rule_policy_on_demand_policy_required(): """ Testing the RemoteRule with the koji interaction when on_demand policy is given. diff --git a/greenwave/tests/test_rules.py b/greenwave/tests/test_rules.py index dbbeb052..e00b4758 100644 --- a/greenwave/tests/test_rules.py +++ b/greenwave/tests/test_rules.py @@ -71,7 +71,7 @@ def test_match_remote_rule(mock_retrieve_scm_from_koji, mock_retrieve_yaml_remot 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') + assert rule.matches(policy, subject=subject, testcase='other_test_case') @mock.patch('greenwave.resources.retrieve_yaml_remote_rule')