From 11bcd4a4fea1e12e3a3a79fdd708cd9ddfacc5f8 Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Oct 27 2017 00:22:43 +0000 Subject: fix the resultsdb consumer to properly handle the messages https://pagure.io/greenwave/issue/102 --- diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml index 05d9917..b69d05a 100644 --- a/conf/policies/fedora.yaml +++ b/conf/policies/fedora.yaml @@ -23,6 +23,14 @@ blacklist: rules: - !PassingTestCaseRule {test_case_name: dist.abicheck} --- !Policy +id: "taskotron_release_critical_tasks_for_testing" +product_versions: + - fedora-26 +decision_context: bodhi_update_push_testing +blacklist: [] +rules: + - !PassingTestCaseRule {test_case_name: dist.rpmdeplint} +--- !Policy id: "taskotron_release_critical_tasks" product_versions: - fedora-26 diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py index b04536b..c0099ee 100644 --- a/functional-tests/consumers/test_resultsdb.py +++ b/functional-tests/consumers/test_resultsdb.py @@ -57,8 +57,9 @@ def test_consume_new_result( data=json.dumps(data)) assert r.status_code == 200 old_decision = r.json() - - msg = { + # should have two messages published as we have two decision contexts applicable to + # this subject. + first_msg = { 'policies_satisfied': False, 'decision_context': 'bodhi_update_push_stable', 'product_version': 'fedora-26', @@ -91,8 +92,35 @@ def test_consume_new_result( 'taskotron_release_critical_tasks'], 'previous': old_decision, } - mock_fedmsg.assert_called_once_with( - topic='decision.update', msg=msg) + mock_fedmsg.assert_any_call(topic='decision.update', msg=first_msg) + # get the old decision for the second policy + data = { + 'decision_context': 'bodhi_update_push_testing', + 'product_version': 'fedora-26', + 'subject': [{'item': nvr, 'type': 'koji_build'}], + 'ignore_result': [result['id']] + } + 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 + old_decision = r.json() + second_msg = { + 'policies_satisfied': True, + 'decision_context': 'bodhi_update_push_testing', + 'product_version': 'fedora-26', + 'unsatisfied_requirements': [], + 'summary': 'all required tests passed', + 'subject': [ + { + 'item': nvr, + 'type': 'koji_build' + } + ], + 'applicable_policies': ['taskotron_release_critical_tasks_for_testing'], + 'previous': old_decision, + } + mock_fedmsg.assert_any_call(topic='decision.update', msg=second_msg) @mock.patch('greenwave.consumers.resultsdb.fedmsg.config.load_config') diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index 089726f..df70b27 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -98,7 +98,7 @@ def test_inspect_policies(requests_session, greenwave_server): assert r.status_code == 200 body = r.json() policies = body['policies'] - assert len(policies) == 5 + assert len(policies) == 6 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) diff --git a/greenwave/consumers/resultsdb.py b/greenwave/consumers/resultsdb.py index 4d93dbc..625e543 100644 --- a/greenwave/consumers/resultsdb.py +++ b/greenwave/consumers/resultsdb.py @@ -128,16 +128,15 @@ class ResultsDBHandler(fedmsg.consumers.FedmsgConsumer): response.raise_for_status() old_decision = response.json() if decision != old_decision: - msg = decision decision.update({ 'subject': [task], 'decision_context': decision_context, 'product_version': product_version, 'previous': old_decision, }) - log.debug('Emitted a fedmsg, %r, on the "%s" topic', msg, + log.debug('Emitted a fedmsg, %r, on the "%s" topic', decision, 'greenwave.decision.update') - fedmsg.publish(topic='decision.update', msg=msg) + fedmsg.publish(topic='decision.update', msg=decision) def _invalidate_cache(self, message): """