From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3B7E71382C5 for ; Wed, 3 Mar 2021 23:15:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9047BE0829; Wed, 3 Mar 2021 23:15:18 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 69A3CE0829 for ; Wed, 3 Mar 2021 23:15:18 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 29023335DA0 for ; Wed, 3 Mar 2021 23:15:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D428713B for ; Wed, 3 Mar 2021 23:15:15 +0000 (UTC) From: "Magnus Granberg" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Magnus Granberg" Message-ID: <1614813272.2b37e2f71e33f58d1ee3a3af5d6994c3dccd0357.zorry@gentoo> Subject: [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/db/, buildbot_gentoo_ci/config/, buildbot_gentoo_ci/steps/ X-VCS-Repository: proj/tinderbox-cluster X-VCS-Files: buildbot_gentoo_ci/config/buildfactorys.py buildbot_gentoo_ci/db/builds.py buildbot_gentoo_ci/db/connector.py buildbot_gentoo_ci/db/model.py buildbot_gentoo_ci/steps/builders.py X-VCS-Directories: buildbot_gentoo_ci/config/ buildbot_gentoo_ci/steps/ buildbot_gentoo_ci/db/ X-VCS-Committer: zorry X-VCS-Committer-Name: Magnus Granberg X-VCS-Revision: 2b37e2f71e33f58d1ee3a3af5d6994c3dccd0357 X-VCS-Branch: master Date: Wed, 3 Mar 2021 23:15:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: fc394511-3d1f-4758-a354-f68be3a6fc8a X-Archives-Hash: 28ff25059ce735dbd97b9965ef611ba2 commit: 2b37e2f71e33f58d1ee3a3af5d6994c3dccd0357 Author: Magnus Granberg gentoo org> AuthorDate: Wed Mar 3 23:14:32 2021 +0000 Commit: Magnus Granberg gentoo org> CommitDate: Wed Mar 3 23:14:32 2021 +0000 URL: https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=2b37e2f7 Add Project build id Signed-off-by: Magnus Granberg gentoo.org> buildbot_gentoo_ci/config/buildfactorys.py | 1 + buildbot_gentoo_ci/db/builds.py | 81 ++++++++++++++++++++++++++++++ buildbot_gentoo_ci/db/connector.py | 2 + buildbot_gentoo_ci/db/model.py | 19 +++++++ buildbot_gentoo_ci/steps/builders.py | 47 +++++++++++++++++ 5 files changed, 150 insertions(+) diff --git a/buildbot_gentoo_ci/config/buildfactorys.py b/buildbot_gentoo_ci/config/buildfactorys.py index b592541..31543f9 100644 --- a/buildbot_gentoo_ci/config/buildfactorys.py +++ b/buildbot_gentoo_ci/config/buildfactorys.py @@ -158,4 +158,5 @@ def run_build_request(): f.addStep(builders.RunEmerge(step='depclean')) f.addStep(builders.RunEmerge(step='preserved-libs')) f.addStep(builders.RunEmerge(step='depclean')) + f.addStep(builders.setBuildStatus()) return f diff --git a/buildbot_gentoo_ci/db/builds.py b/buildbot_gentoo_ci/db/builds.py new file mode 100644 index 0000000..79814b7 --- /dev/null +++ b/buildbot_gentoo_ci/db/builds.py @@ -0,0 +1,81 @@ +# This file has parts from Buildbot and is modifyed by Gentoo Authors. +# Buildbot 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 Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright Buildbot Team Members +# Origins: buildbot.db.* +# Modifyed by Gentoo Authors. +# Copyright 2021 Gentoo Authors + +import uuid +import sqlalchemy as sa + +from twisted.internet import defer + +from buildbot.db import base +from buildbot.util import epoch2datetime + +class BuildsConnectorComponent(base.DBConnectorComponent): + + #@defer.inlineCallbacks + def addBuild(self, project_build_data): + created_at = epoch2datetime(int(self.master.reactor.seconds())) + def thd(conn, no_recurse=False): + tbl = self.db.model.projects_builds + # get the highest current number + r = conn.execute(sa.select([sa.func.max(tbl.c.build_id)], + whereclause=(tbl.c.project_uuid == project_build_data['project_uuid']))) + number = r.scalar() + new_number = 1 if number is None else number + 1 + try: + q = tbl.insert() + r = conn.execute(q, dict(project_uuid=project_build_data['project_uuid'], + version_uuid=project_build_data['version_uuid'], + buildbot_build_id=project_build_data['buildbot_build_id'], + status=project_build_data['status'], + requested=project_build_data['requested'], + created_at=created_at, + build_id=new_number)) + except (sa.exc.IntegrityError, sa.exc.ProgrammingError): + id = None + new_number = None + else: + id = r.inserted_primary_key[0] + return id, new_number + return self.db.pool.do(thd) + + @defer.inlineCallbacks + def setSatusBuilds(self, build_id, project_uuid, status): + updated_at = epoch2datetime(int(self.master.reactor.seconds())) + def thd(conn, no_recurse=False): + + tbl = self.db.model.projects_builds + q = tbl.update() + q = q.where(tbl.c.build_id == build_id) + q = q.where(tbl.c.project_uuid == project_uuid) + conn.execute(q, updated_at=updated_at, + status=status) + yield self.db.pool.do(thd) + + @defer.inlineCallbacks + def setBuildbotBuildIdBuilds(self, build_id, project_uuid, buildbot_build_id): + updated_at = epoch2datetime(int(self.master.reactor.seconds())) + def thd(conn, no_recurse=False): + + tbl = self.db.model.projects_builds + q = tbl.update() + q = q.where(tbl.c.build_id == build_id) + q = q.where(tbl.c.project_uuid == project_uuid) + conn.execute(q, updated_at=updated_at, + buildbot_build_id=buildbot_build_id) + yield self.db.pool.do(thd) diff --git a/buildbot_gentoo_ci/db/connector.py b/buildbot_gentoo_ci/db/connector.py index 7d218ab..7256cab 100644 --- a/buildbot_gentoo_ci/db/connector.py +++ b/buildbot_gentoo_ci/db/connector.py @@ -37,6 +37,7 @@ from buildbot_gentoo_ci.db import packages from buildbot_gentoo_ci.db import versions from buildbot_gentoo_ci.db import keywords from buildbot_gentoo_ci.db import portages +from buildbot_gentoo_ci.db import builds upgrade_message = textwrap.dedent("""\ @@ -83,6 +84,7 @@ class DBConnector(service.ReconfigurableServiceMixin, self.versions = versions.VersionsConnectorComponent(self) self.keywords = keywords.KeywordsConnectorComponent(self) self.portages = portages.PortagesConnectorComponent(self) + self.builds = builds.BuildsConnectorComponent(self) @defer.inlineCallbacks def setup(self, config, check_version=True, verbose=True): diff --git a/buildbot_gentoo_ci/db/model.py b/buildbot_gentoo_ci/db/model.py index aa4eabc..2221ba4 100644 --- a/buildbot_gentoo_ci/db/model.py +++ b/buildbot_gentoo_ci/db/model.py @@ -198,6 +198,25 @@ class Model(base.DBConnectorComponent): sa.Column('preserved_libs', sa.Boolean, default=True), ) + projects_builds = sautils.Table( + "projects_builds", metadata, + sa.Column('id', sa.Integer, primary_key=True), + sa.Column('build_id', sa.Integer), + sa.Column('project_uuid', sa.String(36), + sa.ForeignKey('projects.uuid', ondelete='CASCADE'), + nullable=False), + sa.Column('version_uuid', sa.String(36), + sa.ForeignKey('versions.uuid', ondelete='CASCADE'), + nullable=False), + sa.Column('buildbot_build_id', sa.Integer), + sa.Column('status', sa.Enum('failed','completed','in-progress','waiting', 'warning'), nullable=False), + sa.Column('requested', sa.Boolean, default=False), + sa.Column('created_at', sa.DateTime, nullable=True), + sa.Column('updated_at', sa.DateTime, nullable=True), + sa.Column('deleted', sa.Boolean, default=False), + sa.Column('deleted_at', sa.DateTime, nullable=True), + ) + keywords = sautils.Table( "keywords", metadata, # unique uuid per keyword diff --git a/buildbot_gentoo_ci/steps/builders.py b/buildbot_gentoo_ci/steps/builders.py index 21472c7..d09c4b6 100644 --- a/buildbot_gentoo_ci/steps/builders.py +++ b/buildbot_gentoo_ci/steps/builders.py @@ -124,6 +124,7 @@ class TriggerRunBuildRequest(BuildStep): 'projectrepository_data' : self.getProperty('projectrepository_data'), 'use_data' : self.getProperty("use_data"), 'fullcheck' : self.getProperty("fullcheck"), + 'project_build_data' : None } )]) return SUCCESS @@ -194,6 +195,28 @@ class SetupPropertys(BuildStep): self.setProperty('preserved_libs', False, 'preserved-libs') self.setProperty('depclean', False, 'depclean') self.setProperty('cpv_build', False, 'cpv_build') + print(self.getProperty("buildnumber")) + if self.getProperty('project_build_data') is None: + project_build_data = {} + project_build_data['project_uuid'] = project_data['uuid'] + project_build_data['version_uuid'] = self.getProperty("version_data")['uuid'] + project_build_data['status'] = 'in-progress' + project_build_data['requested'] = False + project_build_data['buildbot_build_id'] = self.getProperty("buildnumber") + project_build_data['id'], project_build_data['build_id'] = yield self.gentooci.db.builds.addBuild( + project_build_data) + else: + project_build_data = self.getProperty('project_build_data') + yield self.gentooci.db.builds.setSatusBuilds( + project_build_data['build_id'], + project_build_data['project_uuid'], + 'in-progress') + yield self.gentooci.db.builds.setBuildbotBuildIdBuilds( + project_build_data['build_id'], + project_build_data['project_uuid'], + self.getProperty("buildnumber")) + self.setProperty('project_build_data', project_build_data, 'project_build_data') + print(self.getProperty("project_build_data")) return SUCCESS class UpdateRepos(BuildStep): @@ -546,3 +569,27 @@ class RunBuild(BuildStep): self.setProperty('preserved_libs', False, 'preserved-libs') yield self.build.addStepsAfterCurrentStep(aftersteps_list) return SUCCESS + +class setBuildStatus(BuildStep): + + name = 'setBuildStatus' + description = 'Running' + descriptionDone = 'Ran' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + @defer.inlineCallbacks + def run(self): + self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] + project_build_data = self.getProperty('project_build_data') + if project_build_data['status'] == 'in-progress': + yield self.gentooci.db.builds.setSatusBuilds( + project_build_data['build_id'], + project_build_data['project_uuid'], + 'completed') + self.setProperty('project_build_data', project_build_data, 'project_build_data') + return SUCCESS