From bdf23bea0c8384b6426ac57f152f22a4702d412b Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: May 19 2020 14:04:17 +0000 Subject: Change logging when Koji build not found JIRA: RHELWF-418 Signed-off-by: Valerij Maljulin --- diff --git a/greenwave/policies.py b/greenwave/policies.py index 726e52f..2243b21 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -6,7 +6,7 @@ import logging import os import re import greenwave.resources -from werkzeug.exceptions import BadRequest +from werkzeug.exceptions import BadRequest, NotFound from flask import current_app from greenwave.utils import remove_duplicates, to_hashable from greenwave.safe_yaml import ( @@ -544,6 +544,8 @@ class RemoteRule(Rule): sub_policies = self._get_sub_policies(policy, subject) except SafeYAMLError: logging.exception('Failed to parse policies for %r', subject) + except NotFound: + logging.error('Koji build not found for %r', subject) except Exception: logging.exception('Failed to retrieve policies for %r', subject) diff --git a/greenwave/tests/test_retrieve_gating_yaml.py b/greenwave/tests/test_retrieve_gating_yaml.py index 73d4475..c18528c 100644 --- a/greenwave/tests/test_retrieve_gating_yaml.py +++ b/greenwave/tests/test_retrieve_gating_yaml.py @@ -12,6 +12,7 @@ from greenwave.resources import ( retrieve_scm_from_koji_build, retrieve_scm_from_koji, retrieve_yaml_remote_rule, NoSourceException ) +from greenwave.app_factory import create_app KOJI_URL = 'https://koji.fedoraproject.org/kojihub' @@ -96,6 +97,21 @@ def test_retrieve_scm_from_build_without_namespace(): assert pkg_name == 'foo' +def test_retrieve_scm_from_koji_build_not_found(): + nvr = 'foo-1.2.3-1.fc29' + app = create_app('greenwave.config.TestingConfig') + with app.app_context(): + expected_error = '404 Not Found: Failed to find Koji build for "{}" at "{}"'.format( + nvr, app.config['KOJI_BASE_URL'] + ) + with mock.patch('xmlrpc.client.ServerProxy') as koji_server: + proxy = mock.MagicMock() + proxy.getBuild.return_value = {} + koji_server.return_value = proxy + with pytest.raises(NotFound, match=expected_error): + retrieve_scm_from_koji(nvr) + + def test_retrieve_scm_from_build_with_missing_rev(): nvr = 'foo-1.2.3-1.fc29' build = {