Skip to content

Commit

Permalink
Include waiver ID in waived requirements (#151)
Browse files Browse the repository at this point in the history
JIRA: RHELWF-9058
  • Loading branch information
hluk committed Apr 28, 2023
1 parent df803c0 commit 6f252e3
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 28 deletions.
3 changes: 3 additions & 0 deletions docs/decision_requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Waived failed test result
"subject_type": "koji-build",
"subject_identifier": "nethack-1.2.3-1.rawhide",
"result_id": 1002,
"waiver_id": 123,
"scenario": null
}
Expand All @@ -204,6 +205,7 @@ Waived missing test result
"testcase": "example.test.case",
"subject_type": "koji-build",
"subject_identifier": "nethack-1.2.3-1.rawhide",
"waiver_id": 123,
"scenario": null
}
Expand All @@ -218,6 +220,7 @@ Waived errored test result
"subject_type": "koji-build",
"subject_identifier": "nethack-1.2.3-1.rawhide",
"result_id": 1003,
"waiver_id": 123,
"error_reason": "CI system out of memory",
"scenario": null
}
Expand Down
1 change: 1 addition & 0 deletions functional-tests/consumers/test_waiverdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_consume_new_waiver(
'subject_type': 'koji_build',
'subject_identifier': nvr,
'result_id': result['id'],
'waiver_id': waiver['id'],
'testcase': failing_test,
'type': 'test-result-failed-waived',
'scenario': None,
Expand Down
3 changes: 2 additions & 1 deletion functional-tests/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ def test_make_a_decision_all_scenarios_waived(
for scenario in scenarios
]

testdatabuilder.create_waiver(
waiver = testdatabuilder.create_waiver(
nvr=nvr,
product_version='fedora-26',
testcase_name='test1',
Expand All @@ -1755,6 +1755,7 @@ def test_make_a_decision_all_scenarios_waived(
'subject_identifier': nvr,
'subject_type': 'koji_build',
'result_id': result['id'],
'waiver_id': waiver['id'],
'testcase': 'test1',
'scenario': result['data']['scenario'][0],
'system_architecture': None,
Expand Down
1 change: 1 addition & 0 deletions greenwave/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def make_decision():
{
"scenario": null,
"subject_identifier": "bodhi-5.1.1-1.fc32",
"waiver_id": 256,
"subject_type": "koji_build",
"testcase": "dist.rpmdeplint",
"type": "test-result-missing-waived"
Expand Down
28 changes: 15 additions & 13 deletions greenwave/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RuleNotSatisfied(Answer):
def to_json(self):
raise NotImplementedError()

def to_waived(self):
def to_waived(self, waiver_id):
"""
Transform unsatisfied answer to waived one.
"""
Expand Down Expand Up @@ -176,8 +176,8 @@ def to_json(self):
'item': self.subject.to_dict()
}

def to_waived(self):
return TestResultWaived(self)
def to_waived(self, waiver_id):
return TestResultWaived(self, waiver_id)


class TestResultIncomplete(RuleNotSatisfied):
Expand Down Expand Up @@ -213,8 +213,8 @@ def to_json(self):
data.update(self.data)
return data

def to_waived(self):
return TestResultWaived(self)
def to_waived(self, waiver_id):
return TestResultWaived(self, waiver_id)


class TestResultWaived(RuleSatisfied):
Expand All @@ -224,12 +224,14 @@ class TestResultWaived(RuleSatisfied):
Contains same data as unsatisfied rule except the type has "-waived"
suffix. Also, the deprecated "item" field is dropped.
"""
def __init__(self, unsatisfied_rule):
def __init__(self, unsatisfied_rule, waiver_id):
self.unsatisfied_rule = unsatisfied_rule
self.waiver_id = waiver_id

def to_json(self):
satisfied_rule = self.unsatisfied_rule.to_json()
satisfied_rule['type'] += '-waived'
satisfied_rule['waiver_id'] = self.waiver_id

if 'item' in satisfied_rule:
del satisfied_rule['item']
Expand Down Expand Up @@ -271,8 +273,8 @@ def to_json(self):
data.update(self.data)
return data

def to_waived(self):
return TestResultWaived(self)
def to_waived(self, waiver_id):
return TestResultWaived(self, waiver_id)


class TestResultErrored(RuleNotSatisfied):
Expand Down Expand Up @@ -319,8 +321,8 @@ def to_json(self):
data.update(self.data)
return data

def to_waived(self):
return TestResultWaived(self)
def to_waived(self, waiver_id):
return TestResultWaived(self, waiver_id)


class InvalidRemoteRuleYaml(RuleNotSatisfied):
Expand All @@ -347,7 +349,7 @@ def to_json(self):
'details': self.details
}

def to_waived(self):
def to_waived(self, waiver_id):
return None


Expand All @@ -373,7 +375,7 @@ def to_json(self):
'sources': self.sources,
}

def to_waived(self):
def to_waived(self, waiver_id):
return None


Expand Down Expand Up @@ -402,7 +404,7 @@ def to_json(self):
'error': self.error,
}

def to_waived(self):
def to_waived(self, waiver_id):
return None


Expand Down
4 changes: 2 additions & 2 deletions greenwave/tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_summary_missing():

def test_summary_missing_waived():
answers = [
TestResultWaived(testResultMissing),
TestResultWaived(testResultMissing, 123),
]
assert summarize_answers(answers) == 'All required tests passed'

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_summary_one_passed_one_missing():
def test_summary_one_passed_one_missing_waived():
answers = [
testResultPassed,
TestResultWaived(testResultMissing),
TestResultWaived(testResultMissing, 123),
]
assert summarize_answers(answers) == 'All required tests passed'

Expand Down
15 changes: 15 additions & 0 deletions greenwave/tests/test_waive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_waive_failed_result():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -44,6 +45,7 @@ def test_waive_failed_result():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
)
Expand All @@ -66,6 +68,7 @@ def test_waive_missing_result():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -78,6 +81,7 @@ def test_waive_missing_result():
testcase='test1',
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
)
Expand All @@ -101,6 +105,7 @@ def test_waive_incomplete_result():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -114,6 +119,7 @@ def test_waive_incomplete_result():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
)
Expand All @@ -138,6 +144,7 @@ def test_waive_errored_result():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -151,6 +158,7 @@ def test_waive_errored_result():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
error_reason='Failed',
Expand All @@ -174,6 +182,7 @@ def test_waive_invalid_gatin_yaml():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -197,6 +206,7 @@ def test_waive_scenario():

waivers = [
dict(
id=8,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -209,6 +219,7 @@ def test_waive_scenario():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -223,6 +234,7 @@ def test_waive_scenario():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
)
Expand Down Expand Up @@ -250,6 +262,7 @@ def test_waive_scenarios_all():

waivers = [
dict(
id=9,
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
product_version='rawhide',
Expand All @@ -265,6 +278,7 @@ def test_waive_scenarios_all():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=98,
waiver_id=9,
scenario='scenario1',
source='https://greenwave_tests.example.com',
),
Expand All @@ -274,6 +288,7 @@ def test_waive_scenarios_all():
subject_type='koji_build',
subject_identifier='nethack-1.2.3-1.rawhide',
result_id=99,
waiver_id=9,
scenario='scenario2',
source='https://greenwave_tests.example.com',
),
Expand Down
26 changes: 15 additions & 11 deletions greenwave/waivers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# SPDX-License-Identifier: GPL-2.0+


def _is_waived(answer, waivers):
def _find_waived_id(answer, waivers):
"""
Returns true only if there is a matching waiver for given answer.
Returns waiver ID of a matching waiver for given answer otherwise None.
"""
return any(
waiver['subject_type'] == answer.subject.type and
waiver['subject_identifier'] == answer.subject.identifier and
waiver['testcase'] == answer.test_case_name and
(not waiver.get('scenario') or waiver['scenario'] == answer.scenario)
for waiver in waivers
)
for waiver in waivers:
if (
waiver["subject_type"] == answer.subject.type
and waiver["subject_identifier"] == answer.subject.identifier
and waiver["testcase"] == answer.test_case_name
and (not waiver.get("scenario") or waiver["scenario"] == answer.scenario)
):
return waiver["id"]
return None


def _maybe_waive(answer, waivers):
"""
Returns waived answer if it's unsatisfied there is a matching waiver,
otherwise returns unchanged answer.
"""
if not answer.is_satisfied and _is_waived(answer, waivers):
return answer.to_waived()
if not answer.is_satisfied:
waiver_id = _find_waived_id(answer, waivers)
if waiver_id is not None:
return answer.to_waived(waiver_id)
return answer


Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ show-source = True
max-line-length = 100
exclude = .git,.tox,dist,*egg,docs,.env,.venv,docker
# E265 block comment should start with '# '
# W503 line break before binary operator
# W504 line break after binary operator
ignore = E265,W504
ignore = E265,W503,W504

0 comments on commit 6f252e3

Please sign in to comment.