MT#33006 repoapi: define Tracker setting

* allows to switch between different services
* set NONE for now to disable WF
* TestBase: fire again ready() to get override values

Change-Id: I9cd8b9d7e5ea7a0db5ea9b2d4fe3f577cb1cc97f
pull/9/head
Victor Seva 3 years ago
parent cc47f0acac
commit 3e038304f6

@ -1,4 +1,4 @@
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
# Copyright (C) 2020-2022 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@ -20,12 +20,12 @@ class RepoAPIConfig(AppConfig):
name = "repoapi"
def ready(self):
from .conf import settings
from .conf import settings, Tracker
# Implicitly connect a signal handlers decorated with @receiver.
from . import signals
if settings.WORKFRONT_NOTE:
if settings.REPOAPI_TRACKER == Tracker.WORKFRONT:
post_save.connect(
signals.workfront_note_manage,
sender="repoapi.JenkinsBuildInfo",

@ -1,4 +1,4 @@
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
# Copyright (C) 2020-2022 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@ -12,14 +12,23 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from enum import Enum, unique
from django.conf import settings # noqa
from appconf import AppConf
@unique
class Tracker(Enum):
NONE = "None"
MANTIS = "Mantis"
WORKFRONT = "WorkFront"
class RepoAPIConf(AppConf):
ARTIFACT_JOB_REGEX = [
".*-repos$",
]
TRACKER = Tracker.NONE
class Meta:
prefix = "repoapi"

@ -133,7 +133,6 @@ STATICFILES_STORAGE = (
)
GITWEB_URL = "https://git.mgm.sipwise.com/gitweb/?p={}.git;a=commit;h={}"
WORKFRONT_CREDENTIALS = BASE_DIR / "/etc/jenkins_jobs/workfront.ini"
WORKFRONT_NOTE = True
# build app
BUILD_REPOS_SCRIPTS_CONFIG_DIR = Path(

@ -57,7 +57,6 @@ GERRIT_REST_HTTP_USER = "jenkins"
GERRIT_REST_HTTP_PASSWD = "verysecrethttppasswd"
GITWEB_URL = "https://git.local/gitweb/?p={}.git;a=commit;h={}"
WORKFRONT_CREDENTIALS = BASE_DIR / ".workfront.ini"
WORKFRONT_NOTE = True
DOCKER_REGISTRY_URL = "https://localhost:5000/v2/{}"
# fake info
DOCKER_REGISTRY = """

@ -22,6 +22,7 @@ from django.apps import apps
from .celery import jbi_parse_hotfix
from .celery import process_result
from .conf import settings
from .conf import Tracker
from .utils import is_download_artifacts
from .utils import jenkins_get_artifact
from .utils import jenkins_get_build
@ -53,8 +54,15 @@ def jenkins_remove_project(self, jbi_id):
@shared_task(ignore_result=True)
def jbi_get_artifact(jbi_id, jobname, buildnumber, artifact_info):
log = logger.bind(
jbi_id=jbi_id,
jobname=jobname,
)
path = jenkins_get_artifact(jobname, buildnumber, artifact_info)
if path.name == settings.HOTFIX_ARTIFACT:
if settings.REPOAPI_TRACKER == Tracker.NONE:
log.info("no tracker defined, skip hotfix management")
return
jbi_parse_hotfix.delay(jbi_id, str(path))

@ -17,6 +17,7 @@ import shutil
from pathlib import Path
from tempfile import mkdtemp
from django.apps import apps
from django.test import override_settings
from django.test import TestCase
from rest_framework.test import APITestCase
@ -34,6 +35,8 @@ class BaseTest(TestCase):
cls.path = Path(settings.JBI_BASEDIR)
def setUp(self, *args, **kwargs):
RepoAPIConfig = apps.get_app_config("repoapi")
RepoAPIConfig.ready()
super(BaseTest, self).setUp()
self.path.mkdir(parents=True, exist_ok=True)

@ -15,12 +15,15 @@
from unittest.mock import patch
from django.conf import settings
from django.test import override_settings
from repoapi.conf import Tracker
from repoapi.models import JenkinsBuildInfo
from repoapi.models import WorkfrontNoteInfo
from repoapi.test.base import BaseTest
@override_settings(REPOAPI_TRACKER=Tracker.WORKFRONT)
class WorkfrontNoteTestCase(BaseTest):
def test_getID(self):
res = WorkfrontNoteInfo.getIds("jojo TT#0891 whatever")

Loading…
Cancel
Save