From ee768d37e17a5945d3715047c744717b85afd96b Mon Sep 17 00:00:00 2001 From: Luiz Carvalho Date: Dec 05 2018 21:01:38 +0000 Subject: Fix RemotePolicy for redhat-module subject type RemotePolicy class was incorrectly forcing the koji_build subject type for redhat-module. Signed-off-by: Luiz Carvalho --- diff --git a/greenwave/policies.py b/greenwave/policies.py index 6996e40..d4ab83b 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -612,13 +612,12 @@ class RemotePolicy(Policy): safe_yaml_attributes = { 'id': SafeYAMLString(optional=True), 'product_versions': SafeYAMLList(str), + 'subject_type': SafeYAMLChoice('koji_build', 'redhat-module', optional=True), 'decision_context': SafeYAMLString(), 'rules': SafeYAMLList(Rule), 'blacklist': SafeYAMLList(str, optional=True), } - subject_type = 'koji_build' - def validate(self): for rule in self.rules: if isinstance(rule, RemoteRule): diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index b52dff5..8528341 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -425,6 +425,7 @@ rules: product_versions: - rhel-8 decision_context: osci_compose_gate +subject_type: redhat-module rules: - !PassingTestCaseRule {test_case_name: baseos-ci.redhat-module.tier0.functional} @@ -444,20 +445,21 @@ rules: waivers = [] # Ensure that presence of a result is success. - results = DummyResultsRetriever(nvr, 'baseos-ci.redhat-module.tier0.functional') + results = DummyResultsRetriever(nvr, 'baseos-ci.redhat-module.tier0.functional', + subject_type='redhat-module') decision = policy.check('rhel-8', nvr, results, waivers) assert len(decision) == 1 assert isinstance(decision[0], RuleSatisfied) # Ensure that absence of a result is failure. - results = DummyResultsRetriever() + results = DummyResultsRetriever(subject_type='redhat-module') decision = policy.check('rhel-8', nvr, results, waivers) assert len(decision) == 1 assert isinstance(decision[0], TestResultMissing) # And that a result with a failure, is a failure. results = DummyResultsRetriever(nvr, 'baseos-ci.redhat-module.tier0.functional', - 'FAILED') + 'FAILED', subject_type='redhat-module') decision = policy.check('rhel-8', nvr, results, waivers) assert len(decision) == 1 assert isinstance(decision[0], TestResultFailed) @@ -778,6 +780,31 @@ def test_parse_policies_remote_multiple(): assert policies[1].id == 'test2' +def test_parse_policies_remote_subject_types(): + policies = RemotePolicy.safe_load_all(dedent(""" + --- !Policy + id: test1 + product_versions: [fedora-rawhide] + decision_context: test + subject_type: koji_build + rules: + - !PassingTestCaseRule {test_case_name: test.case.name} + + --- !Policy + id: test2 + product_versions: [fedora-rawhide] + decision_context: test + subject_type: redhat-module + rules: + - !PassingTestCaseRule {test_case_name: test.case.name} + """)) + assert len(policies) == 2 + assert policies[0].id == 'test1' + assert policies[0].subject_type == 'koji_build' + assert policies[1].id == 'test2' + assert policies[1].subject_type == 'redhat-module' + + def test_parse_policies_remote_multiple_missing_tag(): expected_error = "Missing !Policy tag" with pytest.raises(SafeYAMLError, match=expected_error):