From f00076f9b159d42d3554ed41bfa65cb9a1b858bc Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Oct 12 2017 22:35:26 +0000 Subject: allow policies to opt out of a list of packages --- diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml index 7253337..b7bc5bd 100644 --- a/conf/policies/fedora.yaml +++ b/conf/policies/fedora.yaml @@ -5,11 +5,29 @@ # Tasktron release-critical tasks rule # https://github.com/fedora-infra/fmn/blob/develop/fmn/rules/taskotron.py#L5 --- !Policy -id: "taskotron_release_critical_tasks" +id: "taskotron_release_critical_tasks_with_blacklist" product_versions: - fedora-26 decision_context: bodhi_update_push_stable +blacklist: + # see the excluded list for dist.abicheck + # https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/roles/taskotron/taskotron-trigger/templates/trigger_rules.yml.j2#n17 + - firefox + - thunderbird + - kernel + - kdelibs + - kdepim + - qt + - mariadb + - java-1.8.0-openjdk-libreoffice rules: - !PassingTestCaseRule {test_case_name: dist.abicheck} - - !PassingTestCaseRule {test_case_name: dist.rpmdeplint} - - !PassingTestCaseRule {test_case_name: dist.upgradepath} +--- !Policy +id: "taskotron_release_critical_tasks" +product_versions: + - fedora-26 +decision_context: bodhi_update_push_stable +blacklist: [] +rules: + - !PassingTestCaseRule {test_case_name: dist.rpmdeplint, blacklist: []} + - !PassingTestCaseRule {test_case_name: dist.upgradepath, blacklist: []} diff --git a/conf/policies/redhat.yaml b/conf/policies/redhat.yaml index 9123755..bc1cded 100644 --- a/conf/policies/redhat.yaml +++ b/conf/policies/redhat.yaml @@ -7,6 +7,7 @@ id: "1" product_versions: - rhel-7 decision_context: errata_newfile_to_qe +blacklist: [] rules: - !PassingTestCaseRule {test_case_name: dist.rpmdiff.analysis.abi_symbols} - !PassingTestCaseRule {test_case_name: dist.rpmdiff.analysis.binary_stripping} @@ -86,4 +87,5 @@ product_versions: - cdk-2 - devstudio-2 decision_context: errata_newfile_to_qe +blacklist: [] rules: [] diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py index 720e9da..1f147b7 100644 --- a/functional-tests/consumers/test_resultsdb.py +++ b/functional-tests/consumers/test_resultsdb.py @@ -85,7 +85,8 @@ def test_consume_new_result( 'type': 'koji_build' } ], - 'applicable_policies': ['taskotron_release_critical_tasks'], + 'applicable_policies': ['taskotron_release_critical_tasks_with_blacklist', + 'taskotron_release_critical_tasks'], 'previous': old_decision, } mock_fedmsg.assert_called_once_with( diff --git a/functional-tests/consumers/test_waiverdb.py b/functional-tests/consumers/test_waiverdb.py index e49c517..679a0e1 100644 --- a/functional-tests/consumers/test_waiverdb.py +++ b/functional-tests/consumers/test_waiverdb.py @@ -73,7 +73,8 @@ def test_consume_new_waiver( 'type': 'koji_build' } ], - 'applicable_policies': ['taskotron_release_critical_tasks'], + 'applicable_policies': ['taskotron_release_critical_tasks_with_blacklist', + 'taskotron_release_critical_tasks'], 'previous': old_decision, } mock_fedmsg.assert_called_once_with( diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index 2aae000..a3878ed 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -90,13 +90,16 @@ def test_inspect_policies(requests_session, greenwave_server): assert r.status_code == 200 body = r.json() policies = body['policies'] - assert len(policies) == 3 + assert len(policies) == 4 assert any(p['id'] == 'taskotron_release_critical_tasks' for p in policies) assert any(p['decision_context'] == 'bodhi_update_push_stable' for p in policies) assert any(p['product_versions'] == ['fedora-26'] for p in policies) expected_rules = [ {'rule': 'PassingTestCaseRule', 'test_case_name': 'dist.abicheck'}, + ] + assert any(p['rules'] == expected_rules for p in policies) + expected_rules = [ {'rule': 'PassingTestCaseRule', 'test_case_name': 'dist.rpmdeplint'}, {'rule': 'PassingTestCaseRule', @@ -319,7 +322,8 @@ def test_bodhi_push_update_stable_policy( assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisified'] is True - assert res_data['applicable_policies'] == ['taskotron_release_critical_tasks'] + assert 'taskotron_release_critical_tasks' in res_data['applicable_policies'] + assert 'taskotron_release_critical_tasks_with_blacklist' in res_data['applicable_policies'] expected_summary = 'all required tests passed' assert res_data['summary'] == expected_summary assert res_data['unsatisfied_requirements'] == [] @@ -356,7 +360,8 @@ def test_multiple_results_in_a_subject( res_data = r.json() # The failed result should be taken into account. assert res_data['policies_satisified'] is False - assert res_data['applicable_policies'] == ['taskotron_release_critical_tasks'] + assert 'taskotron_release_critical_tasks' in res_data['applicable_policies'] + assert 'taskotron_release_critical_tasks_with_blacklist' in res_data['applicable_policies'] assert res_data['summary'] == '1 of 3 required tests failed' expected_unsatisfied_requirements = [ { @@ -497,3 +502,30 @@ def test_cached_false_positive(requests_session, cached_greenwave_server, testda assert r.status_code == 200 res_data = r.json() assert res_data['policies_satisified'] is True + + +def test_blacklist(requests_session, greenwave_server, testdatabuilder): + """ + Test that packages on the blacklist will be excluded when applying the policy. + """ + nvr = 'firefox-1.0-1.el7' + testdatabuilder.create_result(item=nvr, + testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[0], + outcome='FAILED') + for testcase_name in TASKTRON_RELEASE_CRITICAL_TASKS[1:]: + testdatabuilder.create_result(item=nvr, + testcase_name=testcase_name, + outcome='PASSED') + data = { + 'decision_context': 'bodhi_update_push_stable', + 'product_version': 'fedora-26', + 'subject': [{'item': nvr, 'type': 'koji_build'}] + } + r = requests_session.post(greenwave_server.url + 'api/v1.0/decision', + headers={'Content-Type': 'application/json'}, + data=json.dumps(data)) + assert r.status_code == 200 + res_data = r.json() + # the failed test result of dist.abicheck should be ignored and thus the policy + # is satisfied. + assert res_data['policies_satisified'] is True diff --git a/greenwave/policies.py b/greenwave/policies.py index f3acb5d..eb02db6 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -179,6 +179,12 @@ class Policy(yaml.YAMLObject): product_version in self.product_versions) def check(self, item, results, waivers): + # If an item is about a package and it is in the blacklist, return RuleSatisfied() + for package in self.blacklist: + if (item.get('type') == 'koji_build' and + item.get('item') and + item['item'].rsplit('-', 2)[0] == package): + return [RuleSatisfied() for rule in self.rules] return [rule.check(item, results, waivers) for rule in self.rules] def __repr__(self): @@ -192,4 +198,5 @@ class Policy(yaml.YAMLObject): 'product_versions': self.product_versions, 'decision_context': self.decision_context, 'rules': [rule.to_json() for rule in self.rules], + 'blacklist': self.blacklist, }