From 5afdef8c24d3609a5b2b07e1021a8f74cc583282 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Jul 04 2018 14:20:04 +0000 Subject: Fix bodhi_update request for nonexistent Bodhi update This is needed for backwards compatibility. --- diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index d9c561d..3abcf17 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -475,6 +475,32 @@ def test_bodhi_push_update_stable_policy( assert res_data['unsatisfied_requirements'] == [] +def test_bodhi_nonexistent_bodhi_update( + requests_session, greenwave_server, testdatabuilder): + nvr = testdatabuilder.unique_nvr() + for testcase_name in TASKTRON_RELEASE_CRITICAL_TASKS: + testdatabuilder.create_result(item=nvr, + testcase_name=testcase_name, + outcome='PASSED') + data = { + 'decision_context': 'bodhi_update_push_stable', + 'product_version': 'fedora-26', + 'subject_type': 'bodhi_update', + 'subject_identifier': 'FEDORA-2000-deadbeaf', + } + 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() + assert res_data['policies_satisfied'] is True + 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'] == 'no tests are required' + assert res_data['unsatisfied_requirements'] == [] + + def test_multiple_results_in_a_subject( requests_session, greenwave_server, testdatabuilder): """ diff --git a/greenwave/resources.py b/greenwave/resources.py index 58db8c0..f3e4e2a 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -101,7 +101,14 @@ def retrieve_builds_in_update(update_id): response = requests_session.get(update_info_url, headers={'Accept': 'application/json'}, timeout=timeout, verify=verify) - response.raise_for_status() + + # Ignore failures to retrieve Bodhi update. + if not response.ok: + log.warning( + 'Making a decision about Bodhi update %s failed: %r', + update_id, response) + return [] + return [build['nvr'] for build in response.json()['update']['builds']] @@ -168,6 +175,9 @@ def retrieve_results(subject_type, subject_identifier): # NOTE - not cached, for now. @greenwave.utils.retry(wait_on=urllib3.exceptions.NewConnectionError) def retrieve_waivers(product_version, subject_type, subject_identifiers): + if not subject_identifiers: + return [] + timeout = current_app.config['REQUESTS_TIMEOUT'] verify = current_app.config['REQUESTS_VERIFY'] filters = [{