From 9383016f3d2ab9cbefb3f0b74b049c4c43a246a3 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 1 Mar 2023 16:09:40 +0100 Subject: [PATCH] MT#56231 remove ppa for scenario mrX.X.X review merged mrX.X.X merges will not trigger a build, so -repos job will never happen with eventtype 'change-merged' now -gerrit job sends the proper values of branch and ppa so we can detect the scenario and clean the ppa * move common regex definitions to repoapi.utils Change-Id: I2b6afd0a7dea0fe07f47ba76bd6f9c2fa88e85ce --- build/models.py | 9 ++++----- repoapi/models/wni.py | 3 +-- repoapi/signals.py | 16 +++++++++++++--- repoapi/test/test_tasks.py | 20 +++++++++++++++++++- repoapi/utils.py | 6 +++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/build/models.py b/build/models.py index 0830544..83be375 100644 --- a/build/models.py +++ b/build/models.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2017-2023 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 @@ -13,7 +13,6 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . import datetime -import re import structlog from django.db import models @@ -28,12 +27,12 @@ from .utils import get_simple_release from .utils import ReleaseConfig from .utils import remove_from_textlist from repoapi.models import JenkinsBuildInfo +from repoapi.utils import regex_mrXX +from repoapi.utils import regex_mrXX_up +from repoapi.utils import regex_mrXXX logger = structlog.get_logger(__name__) -regex_mrXXX = re.compile(r"^mr[0-9]+\.[0-9]+\.[0-9]+$") -regex_mrXX = re.compile(r"^mr[0-9]+\.[0-9]+$") -regex_mrXX_up = re.compile(r"^release-mr[0-9]+\.[0-9]+-update$") build_release_jobs = ",".join(settings.BUILD_RELEASE_JOBS) release_jobs_len = len(build_release_jobs) + 1 diff --git a/repoapi/models/wni.py b/repoapi/models/wni.py index ecd7b8e..5932aa5 100644 --- a/repoapi/models/wni.py +++ b/repoapi/models/wni.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2015-2023 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 @@ -23,7 +23,6 @@ from tracker.models import MantisInfo from tracker.models import TrackerInfo from tracker.models import WorkfrontInfo -re_branch = re.compile(r"^mr[0-9]+\.[0-9]+\.[0-9]+$") commit_re = re.compile(r"^(\w{7}) ") diff --git a/repoapi/signals.py b/repoapi/signals.py index 2272eae..cfcbda3 100644 --- a/repoapi/signals.py +++ b/repoapi/signals.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2022-2023 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 @@ -19,9 +19,9 @@ from django.dispatch import receiver from . import utils from .models.wni import NoteInfo -from .models.wni import re_branch from .tasks import get_jbi_files from .tasks import jenkins_remove_project +from .utils import regex_mrXXX from release_dashboard.utils.build import is_ngcp_project logger = structlog.get_logger(__name__) @@ -64,6 +64,7 @@ def gerrit_repo_del(instance): return structlog.contextvars.bind_contextvars( instance=str(instance), + branch=instance.param_branch, ppa=instance.param_ppa, gerrit_change=instance.gerrit_change, ) @@ -104,6 +105,7 @@ def gerrit_repo_manage(sender, **kwargs): instance = kwargs["instance"] structlog.contextvars.bind_contextvars( instance=str(instance), + branch=instance.param_branch, ppa=instance.param_ppa, ) if instance.param_ppa == "$ppa": @@ -125,6 +127,14 @@ def gerrit_repo_manage(sender, **kwargs): ): logger.info("we need to count this") gerrit_repo_del(instance) + elif ( + instance.jobname.endswith("-gerrit") + and instance.result == "SUCCESS" + and instance.gerrit_eventtype == "change-merged" + and regex_mrXXX.match(instance.param_branch) + ): + logger.info("we need to count this") + gerrit_repo_del(instance) def tracker_release_target(instance, note: NoteInfo): @@ -134,7 +144,7 @@ def tracker_release_target(instance, note: NoteInfo): ) return branch = instance.param_branch - if re_branch.search(branch): + if regex_mrXXX.search(branch): release = branch else: release = utils.get_next_release(branch) diff --git a/repoapi/test/test_tasks.py b/repoapi/test/test_tasks.py index 65d86a6..9f98e10 100644 --- a/repoapi/test/test_tasks.py +++ b/repoapi/test/test_tasks.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2017-2023 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 @@ -192,3 +192,21 @@ class TaskGerritRepoTest(BaseTest): self.assertEqual(ppa.count(), 1) rp.assert_called_once_with("gerrit_vseva_95650", "lua-ngcp-kamailio") rppa.assert_not_called() + + def test_ppa_merged_mrXXX(self, rppa, rp): + self.params["param_branch"] = "mr9.5.1" + self.params["gerrit_change"] = "54" + self.params["gerrit_patchset"] = "54" + JenkinsBuildInfo.objects.create(**self.params) + ppa = GerritRepoInfo.objects.filter(param_ppa=self.params["param_ppa"]) + self.assertEqual(ppa.count(), 1) + + self.params["jobname"] = "lua-ngcp-kamailio-gerrit" + ppa = GerritRepoInfo.objects.filter(param_ppa=self.params["param_ppa"]) + self.assertEqual(ppa.count(), 1) + + self.params["gerrit_eventtype"] = "change-merged" + JenkinsBuildInfo.objects.create(**self.params) + self.assertEqual(ppa.count(), 0) + rp.assert_not_called() + rppa.assert_called_with("gerrit_vseva_95650") diff --git a/repoapi/utils.py b/repoapi/utils.py index 3d34830..1a84033 100644 --- a/repoapi/utils.py +++ b/repoapi/utils.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2015-2023 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 @@ -24,6 +24,10 @@ from .conf import settings logger = structlog.get_logger(__name__) +regex_mrXXX = re.compile(r"^mr[0-9]+\.[0-9]+\.[0-9]+$") +regex_mrXX = re.compile(r"^mr[0-9]+\.[0-9]+$") +regex_mrXX_up = re.compile(r"^release-mr[0-9]+\.[0-9]+-update$") + JBI_CONSOLE_URL = "{}/job/{}/{}/consoleText" JBI_BUILD_URL = "{}/job/{}/{}/api/json" JBI_ARTIFACT_URL = "{}/job/{}/{}/artifact/{}"