Blob Blame History Raw
From 2ad0b6548fcec8100187bcea4897d899dedcd976 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Wed, 23 Aug 2017 20:28:46 +0200
Subject: [PATCH 1/2] Create a custom FedoraAtomicCi rule

The issue is that bodhi always provides an NVR but if the package is not
being considered by the Fedora Atomic CI pipeline, its corresponding git
repository isn't being clone and its `original_spec_nvr` value not
included in the `pipeline.package.ignore` fedmsg message.
In other words, relying on `pipeline.package.ignore` messages when
querying info about a particular NVR is never going to work.

With this rule we are specifying a list of packages of interest (to be
filled) and a test_case_name.
Every package that is part of the list of interest must satisfy this
test case, all the others are considered satisfying the rule.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
---
 conf/policies/fedora.yaml                    | 14 ++++++++
 functional-tests/consumers/test_resultsdb.py |  5 +--
 functional-tests/consumers/test_waiverdb.py  |  5 +--
 functional-tests/test_api_v1.py              |  6 ++--
 greenwave/policies.py                        | 49 ++++++++++++++++++++++++++++
 greenwave/tests/test_policies.py             | 18 +++++++---
 6 files changed, 86 insertions(+), 11 deletions(-)

diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml
index b69d05a3..cc2c0a27 100644
--- a/conf/policies/fedora.yaml
+++ b/conf/policies/fedora.yaml
@@ -48,3 +48,17 @@ blacklist: []
 rules:
   - !PassingTestCaseRule {test_case_name: compose.install_no_user, scenario: scenario1}
   - !PassingTestCaseRule {test_case_name: compose.install_no_user, scenario: scenario2}
+# Fedora Atomic CI pipeline
+# http://fedoraproject.org/wiki/CI
+--- !Policy
+id: "atomic_ci_pipeline_results"
+product_versions:
+  - fedora-26
+decision_context: bodhi_update_push_stable
+blacklist: []
+rules:
+  - !FedoraAtomicCi {
+    test_case_name: org.centos.prod.ci.pipeline.complete,
+    repos: ['kernel', 'rpm-ostree'],
+    }
+
diff --git a/greenwave/policies.py b/greenwave/policies.py
index f56d60de..eb794741 100644
--- a/greenwave/policies.py
+++ b/greenwave/policies.py
@@ -182,6 +182,55 @@ class PassingTestCaseRule(Rule):
         }
 
 
+class FedoraAtomicCi(Rule):
+    """
+    This rule requires that the value of the specified field is part of a
+    specified list.
+    """
+    yaml_tag = u'!FedoraAtomicCi'
+    yaml_loader = yaml.SafeLoader
+
+    def __init__(self, test_case_name, repos):
+        self.test_case_name = test_case_name
+        self.repos = repos
+
+    def check(self, item, results, waivers):
+        """ Check that the request satisfies the requirement of the Fedora
+        Atomic CI pipeline.
+
+        If the request (item) corresponds to a request for Fedora Atomic CI
+        results request and if it is the case, check that the package for
+        which this request is, is in the allowed list.
+        If it is, then proceed as usual using the specified test_case_name.
+        If the package is not in the list, then consider this requirement
+        moot and satisfied.
+
+        """
+
+        if 'original_spec_nvr' not in item:
+            return RuleSatisfied()
+
+        nvr = item['original_spec_nvr']
+        pkg_name = nvr.rsplit('-', 2)[0]
+        if pkg_name not in self.repos:
+            return RuleSatisfied()
+
+        rule = PassingTestCaseRule()
+        rule.test_case_name = self.test_case_name
+        return rule.check(item, results, waivers)
+
+    def __repr__(self):
+        return "%s(test_case_name=%s, repos=%r)" % (
+            self.__class__.__name__, self.test_case_name, self.repos)
+
+    def to_json(self):
+        return {
+            'rule': self.__class__.__name__,
+            'test_case_name': self.test_case_name,
+            'repos': self.repos,
+        }
+
+
 class Policy(yaml.YAMLObject):
     yaml_tag = u'!Policy'
     yaml_loader = yaml.SafeLoader
diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py
index c2d8d7e6..59705284 100644
--- a/greenwave/tests/test_policies.py
+++ b/greenwave/tests/test_policies.py
@@ -6,7 +6,13 @@ import pytest
 
 from greenwave import __version__
 from greenwave.app_factory import create_app
-from greenwave.policies import summarize_answers, RuleSatisfied, TestResultMissing, TestResultFailed
+from greenwave.policies import (
+    summarize_answers,
+    RuleSatisfied,
+    TestResultMissing,
+    TestResultFailed,
+    FedoraAtomicCi,
+)
 from greenwave.utils import load_policies
 
 
@@ -28,10 +34,12 @@ def test_load_policies():
     app = create_app('greenwave.config.TestingConfig')
     assert len(app.config['policies']) > 0
     assert any(policy.id == '1' for policy in app.config['policies'])
-    assert any(policy.decision_context == 'errata_newfile_to_qe' for policy in
-               app.config['policies'])
-    assert any(rule.test_case_name == 'dist.rpmdiff.analysis.abi_symbols' for policy in
-               app.config['policies'] for rule in policy.rules)
+    assert any(policy.decision_context == 'errata_newfile_to_qe'
+               for policy in app.config['policies'])
+    assert any(getattr(rule, 'test_case_name', None) == 'dist.rpmdiff.analysis.abi_symbols'
+               for policy in app.config['policies'] for rule in policy.rules)
+    assert any(isinstance(rule, FedoraAtomicCi)
+               for policy in app.config['policies'] for rule in policy.rules)
 
 
 def test_invalid_payload():
-- 
2.13.6