From e7103418202f3831945d1b187189813f748d7d20 Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Sep 07 2018 15:31:46 +0000 Subject: Fix wrong retrieving of gating.yaml file For the RemoteRule feature the retrieving of the gating.yaml file was wrong: Greenwave was using the subject_identifier (nvr) to guess the pkg/container name to get the repo url for the gating.yaml file. But this is not always right, we should use the source link in the build received from koji/brew. --- diff --git a/greenwave/policies.py b/greenwave/policies.py index a1dd46b..3f02e34 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -296,8 +296,8 @@ class RemoteRule(Rule): if subject_type != 'koji_build': return [] - pkg_name = subject_identifier.rsplit('-', 2)[0] - pkg_namespace, rev = greenwave.resources.retrieve_scm_from_koji(subject_identifier) + pkg_namespace, pkg_name, rev = greenwave.resources.retrieve_scm_from_koji( + subject_identifier) # if the element is actually a container and not a pkg there will be a "-container" # string at the end of the "pkg_name" and it will not match with the one in the # gating.yaml URL diff --git a/greenwave/resources.py b/greenwave/resources.py index ee1534d..df77baa 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -7,6 +7,7 @@ waiverdb, etc..). """ import logging +import re import json import requests import urllib3.exceptions @@ -177,7 +178,9 @@ def retrieve_scm_from_koji_build(nvr, build, koji_url): '(missing URL fragment with SCM revision information)' .format(source, nvr, koji_url)) - return namespace, rev + pkg_name = url.path.split('/')[-1] + pkg_name = re.sub(r'\.git$', '', pkg_name) + return namespace, pkg_name, rev @cached diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 5362b6e..d321490 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -369,7 +369,7 @@ rules: app = create_app('greenwave.config.TestingConfig') with app.app_context(): with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: - scm.return_value = ('rpms', 'nethack') + scm.return_value = ('rpms', 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -422,7 +422,7 @@ rules: app = create_app('greenwave.config.TestingConfig') with app.app_context(): with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: - scm.return_value = ('rpms', 'nethack') + scm.return_value = ('rpms', 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -478,7 +478,7 @@ rules: app = create_app('greenwave.config.TestingConfig') with app.app_context(): with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: - scm.return_value = ('rpms', 'nethack') + scm.return_value = ('rpms', 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -533,7 +533,7 @@ rules: app = create_app('greenwave.config.TestingConfig') with app.app_context(): with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: - scm.return_value = ('rpms', 'nethack') + scm.return_value = ('rpms', 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) diff --git a/greenwave/tests/test_retrieve_gating_yaml.py b/greenwave/tests/test_retrieve_gating_yaml.py index 25d6e1b..b4f5c22 100644 --- a/greenwave/tests/test_retrieve_gating_yaml.py +++ b/greenwave/tests/test_retrieve_gating_yaml.py @@ -15,9 +15,10 @@ def test_retrieve_scm_from_rpm_build(): 'nvr': nvr, 'source': 'git+https://src.fedoraproject.org/rpms/nethack.git#0c1a84e0e8a152897003bd7e27b3f407ff6ba040' # noqa } - namespace, rev = retrieve_scm_from_koji_build(nvr, build, KOJI_URL) + namespace, pkg_name, rev = retrieve_scm_from_koji_build(nvr, build, KOJI_URL) assert namespace == 'rpms' assert rev == '0c1a84e0e8a152897003bd7e27b3f407ff6ba040' + assert pkg_name == 'nethack' def test_retrieve_scm_from_container_build(): @@ -26,9 +27,10 @@ def test_retrieve_scm_from_container_build(): 'nvr': nvr, 'source': 'git://pkgs.devel.redhat.com/containers/golang-github-openshift-prometheus-alert-buffer#46af2f8efbfb0a4e7e7d5676f4efb997f72d4b8c' # noqa } - namespace, rev = retrieve_scm_from_koji_build(nvr, build, KOJI_URL) + namespace, pkg_name, rev = retrieve_scm_from_koji_build(nvr, build, KOJI_URL) assert namespace == 'containers' assert rev == '46af2f8efbfb0a4e7e7d5676f4efb997f72d4b8c' + assert pkg_name == 'golang-github-openshift-prometheus-alert-buffer' def test_retrieve_scm_from_nonexistent_build():