From 96d7217c9ef58b48820b56c999e874eb3daffa5b Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 7 Oct 2020 20:03:26 +0200 Subject: [PATCH] TT#96400 repoapi: download artifacts from repos jobs That will help us to figure out which is the debian package source name we will use to trigger remove-reprepro-project if necessary Change-Id: Idd9be9208d8897e6f94dd4bbce328f86cbbfe0f4 --- repoapi/conf.py | 4 ++++ repoapi/settings/test.py | 1 + repoapi/tasks.py | 3 ++- repoapi/test/test_utils.py | 14 +++++++++++++- repoapi/utils.py | 10 ++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/repoapi/conf.py b/repoapi/conf.py index 2ff6406..88990db 100644 --- a/repoapi/conf.py +++ b/repoapi/conf.py @@ -17,5 +17,9 @@ from appconf import AppConf class RepoAPIConf(AppConf): + ARTIFACT_JOB_REGEX = [ + ".*-repos$", + ] + class Meta: prefix = "repoapi" diff --git a/repoapi/settings/test.py b/repoapi/settings/test.py index a575a74..12e86da 100644 --- a/repoapi/settings/test.py +++ b/repoapi/settings/test.py @@ -103,4 +103,5 @@ JBI_BASEDIR = join(RESULTS_DIR, "jbi_files") JBI_ARTIFACT_JOBS = [ "fake-release-tools-runner", ] +REPOAPI_ARTIFACT_JOB_REGEX = [] JBI_ALLOWED_HOSTS = ["jenkins-dev.mgm.sipwise.com"] diff --git a/repoapi/tasks.py b/repoapi/tasks.py index 97175c3..bec68d8 100644 --- a/repoapi/tasks.py +++ b/repoapi/tasks.py @@ -23,6 +23,7 @@ from django.apps import apps from .celery import app from .celery import jbi_parse_hotfix from .conf import settings +from .utils import is_download_artifacts from .utils import jenkins_get_artifact from .utils import jenkins_get_build from .utils import jenkins_get_console @@ -43,7 +44,7 @@ def get_jbi_files(jbi_id, jobname, buildnumber): jenkins_get_console(jobname, buildnumber) path_envVars = jenkins_get_env(jobname, buildnumber) path_build = jenkins_get_build(jobname, buildnumber) - if jobname in settings.JBI_ARTIFACT_JOBS: + if is_download_artifacts(jobname): with open(path_build) as data_file: data = json.load(data_file) logger.debug("job_info:%s", data) diff --git a/repoapi/test/test_utils.py b/repoapi/test/test_utils.py index 7efc4a8..94ab486 100644 --- a/repoapi/test/test_utils.py +++ b/repoapi/test/test_utils.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 The Sipwise Team - http://sipwise.com +# Copyright (C) 2017-2020 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,6 +12,7 @@ # # You should have received a copy of the GNU General Public License along # with this program. If not, see . +from django.test import override_settings from mock import patch from repoapi import utils @@ -42,3 +43,14 @@ class UtilsTestCase(BaseTest): ear.return_value = [0, "\n", ""] val = utils.get_next_release("mr5.4") self.assertEqual(val, None) + + @override_settings( + REPOAPI_ARTIFACT_JOB_REGEX=[".*-repos$"], + JBI_ARTIFACT_JOBS=["fake-release-tools-runner"], + ) + def test__is_download_artifacts(self): + self.assertFalse(utils.is_download_artifacts("whatever-binaries")) + self.assertTrue( + utils.is_download_artifacts("fake-release-tools-runner") + ) + self.assertTrue(utils.is_download_artifacts("whatever-repos")) diff --git a/repoapi/utils.py b/repoapi/utils.py index 4e0e83f..3385251 100644 --- a/repoapi/utils.py +++ b/repoapi/utils.py @@ -14,6 +14,7 @@ # with this program. If not, see . import logging import os +import re import shutil import subprocess import urllib.request @@ -167,3 +168,12 @@ def workfront_set_release_target(_id, release): logger.error("can't set release target. %s. %s", res[1], res[2]) return False return True + + +def is_download_artifacts(jobname): + if jobname in settings.JBI_ARTIFACT_JOBS: + return True + for check in settings.REPOAPI_ARTIFACT_JOB_REGEX: + if re.search(check, jobname) is not None: + return True + return False