From bca91f99b74e8472ca2446aacf21090a12c9e1b8 Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Sep 07 2018 14:39:37 +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 b98d3b4..2992970 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -294,8 +294,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, rev, pkg_name = 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 e57129c..c8a7094 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -44,7 +44,8 @@ def retrieve_scm_from_koji(nvr): rev = url.fragment namespace = url.path.split('/')[-2] - return namespace, rev + pkg_name = url.path.split('/')[-1] + return namespace, rev, pkg_name except Exception: error = 'Error occurred looking for the "rev" in koji.' log.exception(error) diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index b8af2ec..12f8465 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -336,7 +336,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', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', 'nethack') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -399,7 +399,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', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', 'nethack') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -455,7 +455,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', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', 'nethack') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) @@ -510,7 +510,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', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', 'nethack') with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath)