From a708a35979414cb196205bf46551a6fdf6bbf5eb Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Jun 14 2018 13:09:08 +0000 Subject: [PATCH 1/2] Make id in remote policy optional --- diff --git a/docs/policies.rst b/docs/policies.rst index dd031c0..793d181 100644 --- a/docs/policies.rst +++ b/docs/policies.rst @@ -48,6 +48,8 @@ The document is a map (dictionary) with the following keys: responses so that you can map it back to the configuration where it is defined. + This is optional in ``gating.yaml`` files (see :ref:`remote-rule`). + ``decision_context`` This is an arbitrary string identifying the "context" of the decisions where this policy is applicable. In other words, if Greenwave is making diff --git a/greenwave/policies.py b/greenwave/policies.py index 014dfed..517efcf 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -283,6 +283,10 @@ class RemoteRule(Rule): # policies in dist-git are always about a package for policy in policies: policy.subject_type = 'koji_build' + # Attribute 'id' in remote policy is optional. + policy_id = getattr(policy, 'id', 'untitled') + # Prefix the id for better error reporting. + policy.id = 'dist-git-gating-policy-{}-{}'.format(policy_id, pkg_name) validate_policies(policies, [RemoteRule]) answers = [] for policy in policies: diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index b299896..6882fd5 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -306,3 +306,43 @@ rules: decision = policy.check(nvr, results, waivers) assert len(decision) == 1 assert isinstance(decision[0], TestResultFailed) + + +def test_remote_rule_policy_optional_id(tmpdir): + nvr = 'nethack-1.2.3-1.el9000' + + serverside_fragment = """ +--- !Policy +id: "taskotron_release_critical_tasks_with_remoterule" +product_versions: + - fedora-26 +decision_context: bodhi_update_push_stable_with_remoterule +subject_type: koji_build +rules: + - !RemoteRule {} + """ + + remote_fragment = """ +--- !Policy +decision_context: bodhi_update_push_stable_with_remoterule +rules: + - !PassingTestCaseRule {test_case_name: dist.upgradepath} + """ + + p = tmpdir.join('gating.yaml') + p.write(serverside_fragment) + app = create_app('greenwave.config.TestingConfig') + with app.app_context(): + with mock.patch('greenwave.resources.retrieve_rev_from_koji'): + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: + f.return_value = remote_fragment + policies = load_policies(tmpdir.strpath) + policy = policies[0] + + results, waivers = [], [] + expected_error = ( + 'policy dist-git-gating-policy-untitled-nethack' + ' is missing attribute product_versions' + ) + with pytest.raises(RuntimeError, match=expected_error): + policy.check(nvr, results, waivers) From 774521a9a4db109d10f1a12ac5c8aa1a331f890e Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Jun 14 2018 13:13:38 +0000 Subject: [PATCH 2/2] docs: Make it clear to omit subject_type in gating.yaml --- diff --git a/docs/policies.rst b/docs/policies.rst index 793d181..68cd072 100644 --- a/docs/policies.rst +++ b/docs/policies.rst @@ -71,6 +71,9 @@ The document is a map (dictionary) with the following keys: The subject type must be one of the fixed set of types known to Greenwave. See the :ref:`subject-types` section below for a list of possible types. + This shouldn't be defined in ``gating.yaml`` files (see :ref:`remote-rule`) + - the value there is always ``koji_build``. + ``product_versions`` A policy applies to one or more "product versions". When you ask Greenwave for a decision, you must tell it which product version you are working