commit: 2b37e2f71e33f58d1ee3a3af5d6994c3dccd0357
Author: Magnus Granberg <zorry <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 3 23:14:32 2021 +0000
Commit: Magnus Granberg <zorry <AT> gentoo <DOT> 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 <zorry <AT> 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