| |
@@ -22,33 +22,33 @@
|
| |
)
|
| |
from greenwave.resources import ResultsRetriever
|
| |
from greenwave.safe_yaml import SafeYAMLError
|
| |
+ from greenwave.subjects.generic import GenericSubject
|
| |
+ from greenwave.subjects.koji_build import KojiBuild
|
| |
+ from greenwave.subjects.redhat_module import RedHatModule
|
| |
from greenwave.waivers import waive_answers
|
| |
|
| |
|
| |
class DummyResultsRetriever(ResultsRetriever):
|
| |
- def __init__(
|
| |
- self, subject_identifier=None, testcase=None, outcome='PASSED',
|
| |
- subject_type='koji_build'):
|
| |
+ def __init__(self, subject=None, testcase=None, outcome='PASSED'):
|
| |
super(DummyResultsRetriever, self).__init__(
|
| |
ignore_ids=[],
|
| |
when='',
|
| |
timeout=0,
|
| |
verify=False,
|
| |
url='')
|
| |
- self.subject_identifier = subject_identifier
|
| |
- self.subject_type = subject_type
|
| |
+ self.subject = subject
|
| |
self.testcase = testcase
|
| |
self.outcome = outcome
|
| |
|
| |
def _retrieve_data(self, params):
|
| |
- if (params.get('item') == self.subject_identifier and
|
| |
- ('type' not in params or self.subject_type in params['type'].split(',')) and
|
| |
+ if (self.subject and params.get('item') == self.subject.identifier and
|
| |
+ ('type' not in params or self.subject.type in params['type'].split(',')) and
|
| |
params.get('testcases') == self.testcase):
|
| |
return [{
|
| |
'id': 123,
|
| |
'data': {
|
| |
- 'item': [self.subject_identifier],
|
| |
- 'type': [self.subject_type],
|
| |
+ 'item': [self.subject.identifier],
|
| |
+ 'type': [self.subject.type],
|
| |
},
|
| |
'testcase': {'name': self.testcase},
|
| |
'outcome': self.outcome,
|
| |
@@ -57,21 +57,22 @@
|
| |
|
| |
|
| |
def test_summarize_answers():
|
| |
+ subject = KojiBuild('nvr')
|
| |
assert summarize_answers([RuleSatisfied()]) == \
|
| |
'All required tests passed'
|
| |
- assert summarize_answers([TestResultFailed('koji_build', 'nvr', 'test', None, 'id'),
|
| |
+ assert summarize_answers([TestResultFailed(subject, 'test', None, 'id'),
|
| |
RuleSatisfied()]) == \
|
| |
'1 of 2 required tests failed'
|
| |
- assert summarize_answers([TestResultMissing('koji_build', 'nvr', 'test', None)]) == \
|
| |
+ assert summarize_answers([TestResultMissing(subject, 'test', None)]) == \
|
| |
'1 of 1 required test results missing'
|
| |
- assert summarize_answers([TestResultMissing('koji_build', 'nvr', 'test', None),
|
| |
- TestResultFailed('koji_build', 'nvr', 'test', None, 'id')]) == \
|
| |
+ assert summarize_answers([TestResultMissing(subject, 'test', None),
|
| |
+ TestResultFailed(subject, 'test', None, 'id')]) == \
|
| |
'1 of 2 required tests failed, 1 result missing'
|
| |
- assert summarize_answers([TestResultMissing('koji_build', 'nvr', 'testa', None),
|
| |
- TestResultMissing('koji_build', 'nvr', 'testb', None),
|
| |
- TestResultFailed('koji_build', 'nvr', 'test', None, 'id')]) == \
|
| |
+ assert summarize_answers([TestResultMissing(subject, 'testa', None),
|
| |
+ TestResultMissing(subject, 'testb', None),
|
| |
+ TestResultFailed(subject, 'test', None, 'id')]) == \
|
| |
'1 of 3 required tests failed, 2 results missing'
|
| |
- assert summarize_answers([TestResultMissing('koji_build', 'nvr', 'test', None),
|
| |
+ assert summarize_answers([TestResultMissing(subject, 'test', None),
|
| |
RuleSatisfied()]) == \
|
| |
'1 of 2 required test results missing'
|
| |
|
| |
@@ -92,10 +93,10 @@
|
| |
policy = policies[0]
|
| |
|
| |
results = DummyResultsRetriever()
|
| |
- subject_identifier = 'some_nevr'
|
| |
+ subject = KojiBuild('some_nevr')
|
| |
|
| |
# Ensure that absence of a result is failure.
|
| |
- decision = policy.check('fedora-rawhide', subject_identifier, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultMissing)
|
| |
|
| |
@@ -122,9 +123,10 @@
|
| |
policy = policies[0]
|
| |
|
| |
item = 'some_nevr'
|
| |
- results = DummyResultsRetriever(item, 'sometest', 'FAILED', 'brew-build')
|
| |
+ subject = KojiBuild(item)
|
| |
+ results = DummyResultsRetriever(subject, 'sometest', 'FAILED')
|
| |
|
| |
- decision = policy.check('fedora-rawhide', item, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultFailed)
|
| |
|
| |
@@ -136,7 +138,7 @@
|
| |
'product_version': 'fedora-rawhide',
|
| |
'waived': True,
|
| |
}]
|
| |
- decision = policy.check('fedora-rawhide', item, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
decision = waive_answers(decision, waivers)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
@@ -164,9 +166,10 @@
|
| |
policy = policies[0]
|
| |
|
| |
item = 'some_bodhi_update'
|
| |
- results = DummyResultsRetriever(item, 'sometest', 'FAILED', 'bodhi_update')
|
| |
+ subject = GenericSubject('bodhi_update', item)
|
| |
+ results = DummyResultsRetriever(subject, 'sometest', 'FAILED')
|
| |
|
| |
- decision = policy.check('fedora-rawhide', item, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultFailed)
|
| |
|
| |
@@ -178,7 +181,7 @@
|
| |
'product_version': 'fedora-rawhide',
|
| |
'waived': True,
|
| |
}]
|
| |
- decision = policy.check('fedora-rawhide', item, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
decision = waive_answers(decision, waivers)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
@@ -280,7 +283,7 @@
|
| |
""" Testing the RemoteRule with the koji interaction.
|
| |
In this case we are just mocking koji """
|
| |
|
| |
- nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
|
| |
serverside_fragment = dedent("""
|
| |
--- !Policy
|
| |
@@ -315,20 +318,20 @@
|
| |
policy = policies[0]
|
| |
|
| |
# Ensure that presence of a result is success.
|
| |
- results = DummyResultsRetriever(nvr, 'dist.upgradepath')
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject, 'dist.upgradepath')
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
|
| |
# Ensure that absence of a result is failure.
|
| |
results = DummyResultsRetriever()
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultMissing)
|
| |
|
| |
# And that a result with a failure, is a failure.
|
| |
- results = DummyResultsRetriever(nvr, 'dist.upgradepath', 'FAILED')
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject, 'dist.upgradepath', 'FAILED')
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultFailed)
|
| |
|
| |
@@ -339,6 +342,7 @@
|
| |
In this case we are just mocking koji """
|
| |
|
| |
nvr = '389-ds-1.4-820181127205924.9edba152'
|
| |
+ subject = RedHatModule(nvr)
|
| |
|
| |
serverside_fragment = dedent("""
|
| |
--- !Policy
|
| |
@@ -374,28 +378,27 @@
|
| |
policy = policies[0]
|
| |
|
| |
# Ensure that presence of a result is success.
|
| |
- results = DummyResultsRetriever(nvr, 'baseos-ci.redhat-module.tier0.functional',
|
| |
- subject_type='redhat-module')
|
| |
- decision = policy.check('rhel-8', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject, 'baseos-ci.redhat-module.tier0.functional')
|
| |
+ decision = policy.check('rhel-8', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
|
| |
# Ensure that absence of a result is failure.
|
| |
- results = DummyResultsRetriever(subject_type='redhat-module')
|
| |
- decision = policy.check('rhel-8', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject)
|
| |
+ decision = policy.check('rhel-8', subject, results)
|
| |
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', subject_type='redhat-module')
|
| |
- decision = policy.check('rhel-8', nvr, results)
|
| |
+ results = DummyResultsRetriever(
|
| |
+ subject, 'baseos-ci.redhat-module.tier0.functional', 'FAILED')
|
| |
+ decision = policy.check('rhel-8', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultFailed)
|
| |
|
| |
|
| |
def test_remote_rule_policy_optional_id(tmpdir):
|
| |
- nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
|
| |
serverside_fragment = dedent("""
|
| |
--- !Policy
|
| |
@@ -428,7 +431,7 @@
|
| |
|
| |
results = DummyResultsRetriever()
|
| |
expected_details = "Policy 'untitled': Attribute 'product_versions' is required"
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], InvalidGatingYaml)
|
| |
assert decision[0].is_satisfied is False
|
| |
@@ -438,7 +441,7 @@
|
| |
def test_remote_rule_malformed_yaml(tmpdir):
|
| |
""" Testing the RemoteRule with a malformed gating.yaml file """
|
| |
|
| |
- nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
|
| |
serverside_fragment = dedent("""
|
| |
--- !Policy
|
| |
@@ -483,7 +486,7 @@
|
| |
policy = policies[0]
|
| |
|
| |
results = DummyResultsRetriever()
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], InvalidGatingYaml)
|
| |
assert decision[0].is_satisfied is False
|
| |
@@ -493,7 +496,7 @@
|
| |
""" Testing the RemoteRule with a malformed gating.yaml file
|
| |
But this time waiving the error """
|
| |
|
| |
- nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
|
| |
serverside_fragment = dedent("""
|
| |
--- !Policy
|
| |
@@ -548,14 +551,14 @@
|
| |
'comment': 'Waiving the invalid gating.yaml file',
|
| |
'waived': True,
|
| |
}]
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
decision = waive_answers(decision, waivers)
|
| |
assert len(decision) == 0
|
| |
|
| |
|
| |
def test_remote_rule_required():
|
| |
""" Testing the RemoteRule with required flag set """
|
| |
- nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
app = create_app('greenwave.config.TestingConfig')
|
| |
with app.app_context():
|
| |
with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm:
|
| |
@@ -573,11 +576,11 @@
|
| |
"""))
|
| |
policy = policies[0]
|
| |
results = DummyResultsRetriever()
|
| |
- decision = policy.check('fedora-rawhide', nvr, results)
|
| |
+ decision = policy.check('fedora-rawhide', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], MissingGatingYaml)
|
| |
assert not decision[0].is_satisfied
|
| |
- assert decision[0].subject_identifier == nvr
|
| |
+ assert decision[0].subject.identifier == subject.identifier
|
| |
|
| |
|
| |
def test_parse_policies_missing_tag():
|
| |
@@ -653,8 +656,9 @@
|
| |
policies = load_policies(tmpdir.strpath)
|
| |
policy = policies[0]
|
| |
|
| |
- results = DummyResultsRetriever('nethack-1.2.3-1.el9000', 'sometest', 'PASSED', 'kind-of-magic')
|
| |
- decision = policy.check('rhel-9000', 'nethack-1.2.3-1.el9000', results)
|
| |
+ subject = GenericSubject('kind-of-magic', 'nethack-1.2.3-1.el9000')
|
| |
+ results = DummyResultsRetriever(subject, 'sometest', 'PASSED')
|
| |
+ decision = policy.check('rhel-9000', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultPassed)
|
| |
|
| |
@@ -681,8 +685,9 @@
|
| |
policies = load_policies(tmpdir.strpath)
|
| |
policy = policies[0]
|
| |
|
| |
- results = DummyResultsRetriever('nethack-1.2.3-1.el9000', 'sometest', 'PASSED', 'koji_build')
|
| |
- decision = policy.check('rhel-9000', 'nethack-1.2.3-1.el9000', results)
|
| |
+ subject = KojiBuild('nethack-1.2.3-1.el9000')
|
| |
+ results = DummyResultsRetriever(subject, 'sometest', 'PASSED')
|
| |
+ decision = policy.check('rhel-9000', subject, results)
|
| |
assert len(decision) == num_decisions
|
| |
if num_decisions:
|
| |
assert isinstance(decision[0], TestResultPassed)
|
| |
@@ -861,6 +866,7 @@
|
| |
|
| |
def test_policy_with_subject_type_component_version(tmpdir):
|
| |
nv = '389-ds-base-1.4.0.10'
|
| |
+ subject = GenericSubject('component-version', nv)
|
| |
p = tmpdir.join('fedora.yaml')
|
| |
p.write(dedent("""
|
| |
--- !Policy
|
| |
@@ -875,15 +881,15 @@
|
| |
"""))
|
| |
policies = load_policies(tmpdir.strpath)
|
| |
policy = policies[0]
|
| |
- results = DummyResultsRetriever(nv, 'test_for_new_type', 'PASSED',
|
| |
- 'component-version')
|
| |
- decision = policy.check('fedora-29', nv, results)
|
| |
+ results = DummyResultsRetriever(subject, 'test_for_new_type', 'PASSED')
|
| |
+ decision = policy.check('fedora-29', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
|
| |
|
| |
def test_policy_with_subject_type_redhat_module(tmpdir):
|
| |
nsvc = 'httpd:2.4:20181018085700:9edba152'
|
| |
+ subject = RedHatModule(nsvc)
|
| |
p = tmpdir.join('fedora.yaml')
|
| |
p.write(dedent("""
|
| |
--- !Policy
|
| |
@@ -898,9 +904,8 @@
|
| |
"""))
|
| |
policies = load_policies(tmpdir.strpath)
|
| |
policy = policies[0]
|
| |
- results = DummyResultsRetriever(nsvc, 'test_for_redhat_module_type', 'PASSED',
|
| |
- 'redhat-module')
|
| |
- decision = policy.check('fedora-29', nsvc, results)
|
| |
+ results = DummyResultsRetriever(subject, 'test_for_redhat_module_type', 'PASSED')
|
| |
+ decision = policy.check('fedora-29', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
|
| |
@@ -911,6 +916,7 @@
|
| |
In this case we are just mocking koji """
|
| |
|
| |
nvr = 'nethack-1.2.3-1.el9000'
|
| |
+ subject = KojiBuild(nvr)
|
| |
|
| |
serverside_json = {
|
| |
'product_version': 'fedora-26',
|
| |
@@ -943,19 +949,19 @@
|
| |
policy = OnDemandPolicy.create_from_json(serverside_json)
|
| |
|
| |
# Ensure that presence of a result is success.
|
| |
- results = DummyResultsRetriever(nvr, 'dist.upgradepath')
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject, 'dist.upgradepath')
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], RuleSatisfied)
|
| |
|
| |
# Ensure that absence of a result is failure.
|
| |
results = DummyResultsRetriever()
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultMissing)
|
| |
|
| |
# And that a result with a failure, is a failure.
|
| |
- results = DummyResultsRetriever(nvr, 'dist.upgradepath', 'FAILED')
|
| |
- decision = policy.check('fedora-26', nvr, results)
|
| |
+ results = DummyResultsRetriever(subject, 'dist.upgradepath', 'FAILED')
|
| |
+ decision = policy.check('fedora-26', subject, results)
|
| |
assert len(decision) == 1
|
| |
assert isinstance(decision[0], TestResultFailed)
|
| |
Use doublequotes to avoid escapes