Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip non-migrated tracker sync (OSIDB-3966) #901

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"filename": "osidb/tests/endpoints/flaws/test_update_trackers.py",
"hashed_secret": "3c3b274d119ff5a5ec6c1e215c1cb794d9973ac1",
"is_verified": false,
"line_number": 87,
"line_number": 89,
"is_secret": false
}
],
Expand Down Expand Up @@ -475,5 +475,5 @@
}
]
},
"generated_at": "2025-01-23T19:49:54Z"
"generated_at": "2025-01-31T12:34:45Z"
}
12 changes: 12 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ def enable_bz_async_sync(enable_bz_sync, monkeypatch) -> None:
monkeypatch.setattr(flaw_module, "SYNC_FLAWS_TO_BZ_ASYNCHRONOUSLY", True)


@pytest.fixture
def enable_bz_tracker_sync(monkeypatch) -> None:
"""
enable the sync of trackers to Bugzilla
"""
import apps.bbsync.mixins as mixins
import osidb.models.tracker as tracker

monkeypatch.setattr(mixins, "SYNC_TO_BZ", True)
monkeypatch.setattr(tracker, "SYNC_TRACKERS_TO_BZ", True)


@pytest.fixture
def enable_jira_task_sync(monkeypatch) -> None:
"""
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
- Skip non-migrated Bugzilla tracker sync (OSIDB-3966)

## [4.7.1] - 2025-01-30
### Fixed
- Filter out empty events from history API resutls (OSIDB-3942)
Expand Down
19 changes: 17 additions & 2 deletions osidb/models/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,27 @@ def save(self, *args, bz_api_key=None, jira_token=None, **kwargs):
if raise_validation_error:
self.validate(dry_run=kwargs.get("no_alerts", False))

# TODO the following condition can be removed when we fully leave Buzilla
#
# there may still exist open trackers in Bugzilla at the time when the
# project their supposed to belong to migrated to Jira already which
# breaks the integration and as it is not simple to address but only
# temporary we agreed on a workaround of skiping the tracker sync
skip_sync = False
if affect := self.affects.first():
if ps_module := PsModule.objects.filter(name=affect.ps_module).first():
# tracker type and BTS mismatch
if self.TYPE2BTS[self.type] != ps_module.bts_name:
skip_sync = True

# the validations were already run
kwargs["raise_validation_error"] = False
kwargs["no_alerts"] = True

# check Bugzilla conditions are met
if (
SYNC_TRACKERS_TO_BZ
not skip_sync
and SYNC_TRACKERS_TO_BZ
and bz_api_key is not None
and self.type == self.TrackerType.BUGZILLA
):
Expand All @@ -184,7 +198,8 @@ def save(self, *args, bz_api_key=None, jira_token=None, **kwargs):

# check Jira conditions are met
elif (
SYNC_TO_JIRA
not skip_sync
and SYNC_TO_JIRA
and jira_token is not None
and self.type == self.TrackerType.JIRA
):
Expand Down
2 changes: 1 addition & 1 deletion osidb/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ def mi_differ(flaw1, flaw2):
# If the non-components attributes are unchanged, a tracker update is
# necessary only for Vulnerability issuetype Jira trackers because only
# those contain components. And this tracker is not Vuln. issuetype.
return
osoukup marked this conversation as resolved.
Show resolved Hide resolved
continue

# perform the tracker update
# could be done async eventually
Expand Down
74 changes: 73 additions & 1 deletion osidb/tests/endpoints/flaws/test_update_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import pytest
from rest_framework import status

from osidb.models import Affect, Tracker
from apps.bbsync.save import BugzillaSaver
from osidb.models import Affect, Impact, Tracker
from osidb.sync_manager import BZTrackerDownloadManager
from osidb.tests.factories import (
AffectFactory,
FlawFactory,
Expand Down Expand Up @@ -226,3 +228,73 @@ def test_trigger(
)
assert response.status_code == status.HTTP_200_OK
assert mock_save.called == (triggered or triggered_2)

def test_skip_non_migrated_trackers(
self,
auth_client,
enable_bz_tracker_sync,
monkeypatch,
test_api_uri,
):
"""
test that a Bugzilla tracker which product was migrated
to Jira project is skipped during a tracker sync
"""
flaw = FlawFactory(impact="IMPORTANT")
ps_module1 = PsModuleFactory(bts_name="bugzilla")
affect1 = AffectFactory(
flaw=flaw,
impact=Impact.NOVALUE,
affectedness=Affect.AffectAffectedness.AFFECTED,
resolution=Affect.AffectResolution.DELEGATED,
ps_module=ps_module1.name,
)
ps_update_stream1 = PsUpdateStreamFactory(ps_module=ps_module1)
tracker1 = TrackerFactory(
affects=[affect1],
embargoed=flaw.embargoed,
ps_update_stream=ps_update_stream1.name,
status="NEW",
type=Tracker.BTS2TYPE[ps_module1.bts_name],
)
ps_module2 = PsModuleFactory(bts_name="jboss")
affect2 = AffectFactory(
flaw=flaw,
impact=Impact.NOVALUE,
affectedness=Affect.AffectAffectedness.AFFECTED,
resolution=Affect.AffectResolution.DELEGATED,
ps_module=ps_module2.name,
)
ps_update_stream2 = PsUpdateStreamFactory(ps_module=ps_module2)
tracker2 = TrackerFactory.build(
embargoed=flaw.embargoed,
ps_update_stream=ps_update_stream2.name,
status="NEW",
type="BUGZILLA", # tracker typy and BTS mismatch
)
tracker2.save(raise_validation_error=False)
tracker2.affects.add(affect2)

flaw_data = {
"comment_zero": flaw.comment_zero,
"embargoed": flaw.embargoed,
"impact": "MODERATE", # tracker update trigger
"title": flaw.title,
"updated_dt": flaw.updated_dt,
}

monkeypatch.setattr(BZTrackerDownloadManager, "schedule", lambda x: None)
# enable autospec to get self as part of the method call args
with patch.object(BugzillaSaver, "save", autospec=True) as mock_save:
response = auth_client().put(
f"{test_api_uri}/flaws/{flaw.uuid}",
flaw_data,
format="json",
HTTP_BUGZILLA_API_KEY="SECRET",
HTTP_JIRA_API_KEY="SECRET",
)
assert response.status_code == status.HTTP_200_OK
assert (
mock_save.call_count == 1
) # no mismatched trackers attempted to be saved
assert tracker1.uuid == mock_save.call_args_list[0][0][0].tracker.uuid
Loading