From 7ecb002f8c71496e4fa547c8f8a523b466bc7c73 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Apr 17 2018 18:53:15 +0000 Subject: Allow patterns in the repo list. Fixes #155. I'm not married to the use of fnmatch over regex or anything else. It seemed like the simplest thing to reach for. --- diff --git a/greenwave/policies.py b/greenwave/policies.py index ed80b21..cdac959 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ +import fnmatch import yaml @@ -215,13 +216,14 @@ class PackageSpecificRule(Rule): def check(self, item, results, waivers): """ Check that the item passes testcase for the given results, but only if the item is an instance of a package name configured for - this rule (specified by "repos"). + this rule, specified by "repos". Any of the repos may be a glob. Items which do not bear the "nvr_key" for this rule are considered satisfied (ignored). - Items whose package names (extracted from their NVR) do not appear - in the "repos" list of this rule are considered satisfied (ignored). + Items whose package names (extracted from their NVR) do not match + any of the globs in the "repos" list of this rule are considered + satisfied (ignored). """ if self.nvr_key not in item: @@ -229,7 +231,7 @@ class PackageSpecificRule(Rule): nvr = item[self.nvr_key] pkg_name = nvr.rsplit('-', 2)[0] - if pkg_name not in self.repos: + if not any(fnmatch.fnmatch(pkg_name, repo) for repo in self.repos): return RuleSatisfied() rule = PassingTestCaseRule() diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 8366f24..4dbec2d 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -71,7 +71,7 @@ product_versions: decision_context: compose_gate blacklist: [] rules: - - !PackageSpecificBuild {test_case_name: sometest, repos: [nethack]} + - !PackageSpecificBuild {test_case_name: sometest, repos: [nethack, python-*]} """) policies = load_policies(tmpdir.strpath) policy = policies[0] @@ -128,6 +128,35 @@ rules: assert len(decision) == 1 assert isinstance(decision[0], RuleSatisfied) # ooooh. + # Ensure that fnmatch globs work in absence + item = {'item': 'python-foobar-1.2.3-1.el9000', 'type': 'koji_build'} + results, waivers = [], [] + decision = policy.check(item, results, waivers) + assert len(decision) == 1 + assert isinstance(decision[0], TestResultMissing) + + # Ensure that fnmatch globs work in the negative. + results = [{ + 'id': 123, + 'item': 'nethack-1.2.3-1.el9000', + 'testcase': {'name': 'sometest'}, + 'outcome': 'FAILED', + }] + decision = policy.check(item, results, waivers) + assert len(decision) == 1 + assert isinstance(decision[0], TestResultFailed) + + # Ensure that fnmatch globs work in the positive. + results = [{ + 'id': 123, + 'item': 'nethack-1.2.3-1.el9000', + 'testcase': {'name': 'sometest'}, + 'outcome': 'SUCCESS', + }] + decision = policy.check(item, results, waivers) + assert len(decision) == 1 + assert isinstance(decision[0], TestResultFailed) + def test_load_policies(): app = create_app('greenwave.config.TestingConfig')