From 4851ff3928f09f33692836301a3ab1dc58a69fb2 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Thu, 11 Oct 2012 12:52:38 +0200 Subject: [PATCH] add liveboot to cidb --- db_add.py | 38 ++++++++++++++++++++++++++++++++++---- liveboot2db.py | 25 +++++++++++++++++++++++++ liveboot_build.sh | 16 ++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100755 liveboot2db.py diff --git a/db_add.py b/db_add.py index 6176a2d..26ce25d 100755 --- a/db_add.py +++ b/db_add.py @@ -38,14 +38,14 @@ def db_add_build(con, number, db_id): #logger.debug("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id) VALUES(%s, %s) RETURNING id" % (number, db_id)) return cur.fetchone()[0] -def db_add_build_result(con, build_id, start, end): +def db_add_build_result(con, build_id, start, end, successful): cur = con.cursor() cur.execute("SAVEPOINT a") try: - cur.execute("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, 'true')) + cur.execute("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, to_timestamp('%s'), to_timestamp('%s'), %s) RETURNING id" % (build_id, start, end, successful)) except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command - #logger.debug("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, 'true')) + logger.debug("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, successful)) return cur.fetchone()[0] def db_add_origin(con, origin): @@ -93,7 +93,7 @@ def add_package_instances(origin, job_name, build_number, changes_file, version, logger.debug("INSERT success job %s" % job_name) # maybe FIXME: we could add the build already once its started, but for package builds we dont wanna add failures to the db at all db_build_id = db_add_build (con, build_number, db_job_id) - db_build_result_id = db_add_build_result (con, db_build_id, start, end) + db_build_result_id = db_add_build_result (con, db_build_id, start, end, 'true') logger.debug("INSERT success build number %s" % build_number) logger.debug("processing %s" %(changes_file)) cmd = ["dcmd", '--deb', changes_file] @@ -145,3 +145,33 @@ def get_package_instance(origin, package, version): return False if cur.fetchone(): return True + +def get_liveboot_build_id(job_name, build_number): + con = db_connect() + cur = con.cursor() + try: + cur.execute("SELECT jenkins_build.id FROM jenkins_build" + " JOIN jenkins_job ON (jenkins_job.id = jenkins_build.jenkins_job_id)" + " WHERE jenkins_job.name = '%s' AND jenkins_build.jenkins_build_number = '%s'" % (job_name, build_number)) + except psycopg2.DatabaseError as e: + logger.debug("SELECT jenkins_build.id FROM jenkins_build" + " JOIN jenkins_job ON (jenkins_job.id = jenkins_build.jenkins_job_id)" + " WHERE jenkins_job.name = '%s' AND jenkins_build.jenkins_build_number = '%s'" % (job_name, build_number)) + return False + return cur.fetchone()[0] + +def add_liveboot_build(job_name, build_number): + con = db_connect() + db_job_id = db_add_job(con, job_name) + db_build_id = db_add_build (con, build_number, db_job_id) + con.commit() + logger.info("CIDB init for liveboot OK.") + return db_build_id + +def finish_liveboot_build(build_id, start, end): + con = db_connect() + db_build_result_id = db_add_build_result (con, build_id, start, end, 'true') + con.commit() + logger.info("CIDB update for liveboot OK.") + return db_build_result_id + diff --git a/liveboot2db.py b/liveboot2db.py new file mode 100755 index 0000000..ee3d393 --- /dev/null +++ b/liveboot2db.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +from common_code import * +from db_add import * + + +if __name__ == '__main__': + if len(sys.argv) != 3 and len(sys.argv) !=5: + print("usage: %s $packages_file $origin") + sys.exit(1) + + job_name = sys.argv[1] + build_number = sys.argv[2] + + if len(sys.argv) != 5: + add_liveboot_build(job_name, build_number) + else: + begin = sys.argv[3] + end = sys.argv[4] + build_id = get_liveboot_build_id(job_name, build_number) + finish_liveboot_build(build_id, begin, end) + + diff --git a/liveboot_build.sh b/liveboot_build.sh index fb4f838..4ef4cfb 100755 --- a/liveboot_build.sh +++ b/liveboot_build.sh @@ -36,9 +36,25 @@ git checkout $GIT_BRANCH [ -d /srv/build/cache ] && mv /srv/build/cache . ./build.sh $BUILD_NUMBER $GIT_BRANCH $REQUEST_ID EOF + +# +# add liveboot build to cidb +# +BUILD_START = $(date +%s) +./liveboot2db.py $JOB_NAME $BUILD_NUMBER + +# +# build liveboot +# sudo pbuilder --execute --bindmounts /srv/build/ -- $BUILD_SCRIPT rm $BUILD_SCRIPT +# +# add liveboot build result to cidb +# +BUILD_END = $(date +%s) +./liveboot2db.py $JOB_NAME $BUILD_NUMBER $BUILD_START $BUILD_END + # FIXME: too much sudo here... cd /srv/build/liveboot/builds sudo mv *-* /srv/mirror/liveboot -- 2.39.5