Skip to content

Commit

Permalink
Add alerts for components affected by NOTABUG flaw
Browse files Browse the repository at this point in the history
  • Loading branch information
costaconrado committed Jan 19, 2023
1 parent bb11a16 commit ca38a63
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implement Bugzilla SRT notes builder in Bugzilla Backwards Sync (OSIDB-384)
- Implement validation for flaw without affect (OSIDB-353)
- Implement validation for changes in flaws with high criticicity with open tracker (OSIDB-347)
- Implement validation for components affected by flaws closed as NOTABUG (OSIDB-363)

### Changed
- Change logging of celery and django to filesystem (OSIDB-418)
Expand Down
35 changes: 35 additions & 0 deletions osidb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,26 @@ def _validate_no_placeholder(self):
"OSIDB does not support write operations on placeholder flaws"
)

def _validate_notabug_flaw_affected(self):
"""
Alerts in case flaw is closed as NOTABUG but has affected components
"""
if (
self.state != Flaw.FlawState.CLOSED
or self.resolution != FlawResolution.NOTABUG
):
return

affected = self.affects.filter(
affectedness=Affect.AffectAffectedness.AFFECTED
).first()
if affected:
self.alert(
"notabug_affect_ps_component",
f"Module {affected.ps_module} of component "
f"{affected.ps_component} is affected by a flaw solved as NOTABUG.",
)

@property
def is_placeholder(self):
"""
Expand Down Expand Up @@ -1050,6 +1070,21 @@ def _validate_ps_module_new_flaw(self):
f"for flaw with bz_id {bz_id}."
)

def _validate_affect_in_notabug_flaw(self):
"""
Alerts in case a component is affected by a flaw closed as NOTABUG
"""
if (
self.affectedness == Affect.AffectAffectedness.AFFECTED
and self.flaw.resolution == FlawResolution.NOTABUG
and self.flaw.state == Flaw.FlawState.CLOSED
):
self.flaw.alert(
"notabug_affect_ps_component",
f"Module {self.ps_module} of component "
f"{self.ps_component} is affected by a flaw solved as NOTABUG.",
)

@property
def delegated_resolution(self):
"""affect delegated resolution based on resolutions of related trackers"""
Expand Down
75 changes: 75 additions & 0 deletions osidb/tests/test_flaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,78 @@ def test_validate_unsupported_major_incident_change(
flaw.save()

assert should_raise == bool("unsupported_impact_change" in flaw._alerts)

@pytest.mark.parametrize(
"state,resolution,affectedness,should_raise",
[
(
Flaw.FlawState.CLOSED,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.AFFECTED,
True,
),
(
Flaw.FlawState.NEW,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.AFFECTED,
False,
),
(
Flaw.FlawState.CLOSED,
FlawResolution.NEXTRELEASE,
Affect.AffectAffectedness.AFFECTED,
False,
),
(
Flaw.FlawState.CLOSED,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.NOTAFFECTED,
False,
),
],
)
def test_validate_affect_in_notabug_flaw(
self, state, resolution, affectedness, should_raise
):
flaw = FlawFactory(resolution=resolution, state=state)
AffectFactory(flaw=flaw, affectedness=affectedness)

assert should_raise == bool("notabug_affect_ps_component" in flaw._alerts)

@pytest.mark.parametrize(
"state,resolution,affectedness,should_raise",
[
(
Flaw.FlawState.CLOSED,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.AFFECTED,
True,
),
(
Flaw.FlawState.NEW,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.AFFECTED,
False,
),
(
Flaw.FlawState.CLOSED,
FlawResolution.NEXTRELEASE,
Affect.AffectAffectedness.AFFECTED,
False,
),
(
Flaw.FlawState.CLOSED,
FlawResolution.NOTABUG,
Affect.AffectAffectedness.NOTAFFECTED,
False,
),
],
)
def test_validate_notabug_flaw_affected(
self, state, resolution, affectedness, should_raise
):
affect = AffectFactory(affectedness=affectedness)
flaw = FlawFactory(resolution=resolution, state=state)
flaw.affects.add(affect)
flaw.save()
assert should_raise == bool("notabug_affect_ps_component" in flaw._alerts)

0 comments on commit ca38a63

Please sign in to comment.