Skip to content

Commit

Permalink
skip non-migrated tracker sync (OSIDB-3966) (#901)
Browse files Browse the repository at this point in the history
for the open Bugzilla trackers which project already migrated to Jira we
need to skip the eventual sync not to interrupt the update
osoukup authored Jan 31, 2025
2 parents 06ffc5c + 1a0d37f commit 2a89b5c
Showing 6 changed files with 108 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -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
}
],
@@ -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
@@ -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:
"""
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 17 additions & 2 deletions osidb/models/tracker.py
Original file line number Diff line number Diff line change
@@ -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
):
@@ -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
):
2 changes: 1 addition & 1 deletion osidb/serializer.py
Original file line number Diff line number Diff line change
@@ -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
continue

# perform the tracker update
# could be done async eventually
74 changes: 73 additions & 1 deletion osidb/tests/endpoints/flaws/test_update_trackers.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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

0 comments on commit 2a89b5c

Please sign in to comment.