From f5b5261ed67e3be1c9be5f2c4c13662a8565a8d1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 15 2018 19:37:54 +0000 Subject: Add an option to retrieve the waivers with a decision This is somewhat a middle ground between the bare decision and the verbose flag. In this case we would like to show waivers in Bodhi's UI but verbose does bring a lot of additional information that we're not using anywhere, it makes the request slower and uses more bandwith. So having this middle ground should ease a little bit this. Signed-off-by: Pierre-Yves Chibon --- diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index 495917f..62914ec 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -246,6 +246,50 @@ def test_make_a_decison_with_verbose_flag(requests_session, greenwave_server, te assert res_data['waivers'] == expected_waivers +def test_make_a_decison_with_waivers_flag(requests_session, greenwave_server, testdatabuilder): + nvr = testdatabuilder.unique_nvr() + for testcase_name in all_rpmdiff_testcase_names: + testdatabuilder.create_result(item=nvr, + testcase_name=testcase_name, + outcome='PASSED') + data = { + 'decision_context': 'errata_newfile_to_qe', + 'product_version': 'rhel-7', + 'subject': [{'item': nvr, 'type': 'koji_build'}], + 'waivers': True, + } + + r = requests_session.post(greenwave_server + 'api/v1.0/decision', + headers={'Content-Type': 'application/json'}, + data=json.dumps(data)) + assert r.status_code == 200 + res_data = r.json() + expected_result = { + u'data': { + u'item': [u'glibc-1.0-2.el7'], + u'type': [u'koji_build'] + }, + u'groups': [], + u'href': u'http://localhost:5001/api/v2.0/results/72', + u'id': 72, + u'note': None, + u'outcome': u'PASSED', + u'ref_url': None, + #u'submit_time': u'2018-01-28T12:55:54.641139', + u'testcase': { + u'href': u'http://localhost:5001/api/v2.0/testcases/dist.rpmdiff.analysis.abi_symbols', + u'name': u'dist.rpmdiff.analysis.abi_symbols', + u'ref_url': None, + } + } + + assert len(res_data['results']) == len(all_rpmdiff_testcase_names) + del res_data['results'][-1]['submit_time'] + assert res_data['results'][-1] == expected_result + expected_waivers = [] + assert res_data['waivers'] == expected_waivers + + def test_make_a_decison_on_failed_result_with_waiver( requests_session, greenwave_server, testdatabuilder): nvr = testdatabuilder.unique_nvr() diff --git a/greenwave/api_v1.py b/greenwave/api_v1.py index ed7e14b..a9df1c8 100644 --- a/greenwave/api_v1.py +++ b/greenwave/api_v1.py @@ -197,6 +197,8 @@ def make_decision(): used for querying ResultsDB. Each item contains one or more key-value pairs of 'data' key in ResultsDB API. For example, [{"type": "koji_build", "item": "xscreensaver-5.37-3.fc27"}]. :jsonparam bool verbose: A flag to return additional information. + :jsonparam bool waivers: A flag to return waivers associated with the + decisions. :jsonparam list ignore_result: A list of result ids that will be ignored when making the decision. :jsonparam list ignore_waiver: A list of waiver ids that will be ignored when making @@ -224,6 +226,9 @@ def make_decision(): verbose = data.get('verbose', False) if not isinstance(verbose, bool): raise BadRequest('Invalid verbose flag, must be a bool') + waivers = data.get('waivers', False) + if not isinstance(waivers, bool): + raise BadRequest('Invalid waivers flag, must be a bool') ignore_results = data.get('ignore_result', []) ignore_waivers = data.get('ignore_waiver', []) applicable_policies = [policy for policy in current_app.config['policies'] @@ -262,6 +267,9 @@ def make_decision(): 'results': all_results, 'waivers': all_waivers, }) + elif waivers: + res.update({'waivers': all_waivers}) + resp = jsonify(res) resp = insert_headers(resp) resp.status_code = 200