From 51773750bb877602be0055ddbe723df888ef120e Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Thu, 11 Oct 2012 16:52:20 +0200 Subject: [PATCH] also update liveboot_request_jenkins_build after successful build --- db_add.py | 19 +++++++++++++++---- liveboot2db.py | 17 +++++++++++------ liveboot_build.sh | 4 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/db_add.py b/db_add.py index 26ce25d..24e209f 100755 --- a/db_add.py +++ b/db_add.py @@ -129,6 +129,16 @@ def add_package_version(origin, package, version): con.commit() return db_package_instance_id +def db_add_requested_liveboot_build (con, request_id, build_id) + cur = con.cursor() + cur.execute("SAVEPOINT a") + try: + cur.execute("INSERT INTO liveboot_request_jenkins_build(liveboot_request_id, jenkins_build_id) VALUES(%s, %s) RETURNING id" % (request_id_ build_id)) + except psycopg2.DatabaseError as e: + cur.execute("ROLLBACK TO a") # have to rollback after failed command + #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 get_package_instance(origin, package, version): con = db_connect() cur = con.cursor() @@ -160,18 +170,19 @@ def get_liveboot_build_id(job_name, build_number): return False return cur.fetchone()[0] -def add_liveboot_build(job_name, build_number): +def add_liveboot_build(job_name, build_number, request_id): con = db_connect() db_job_id = db_add_job(con, job_name) db_build_id = db_add_build (con, build_number, db_job_id) + db_add_requested_liveboot_build (con, request_id, build_id) con.commit() logger.info("CIDB init for liveboot OK.") - return db_build_id + return 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') + db_add_build_result (con, build_id, start, end, 'true') con.commit() logger.info("CIDB update for liveboot OK.") - return db_build_result_id + return diff --git a/liveboot2db.py b/liveboot2db.py index ee3d393..107e45d 100755 --- a/liveboot2db.py +++ b/liveboot2db.py @@ -7,18 +7,23 @@ from db_add import * if __name__ == '__main__': - if len(sys.argv) != 3 and len(sys.argv) !=5: - print("usage: %s $packages_file $origin") + if len(sys.argv) != 4 and len(sys.argv) !=6: + # if the build was just started: + print("usage: %s $job_name $build_number $liveboot_request_id") + print("or:") + # if the build was successful + print("usage: %s $job_name $build_number $liveboot_request_id $start_time $end_time") sys.exit(1) job_name = sys.argv[1] build_number = sys.argv[2] + request_id = sys.argv[3] - if len(sys.argv) != 5: - add_liveboot_build(job_name, build_number) + if len(sys.argv) != 6: + add_liveboot_build(job_name, build_number, request_id) else: - begin = sys.argv[3] - end = sys.argv[4] + begin = sys.argv[4] + end = sys.argv[5] 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 d90e612..5bb40a9 100755 --- a/liveboot_build.sh +++ b/liveboot_build.sh @@ -43,7 +43,7 @@ EOF # add liveboot build to cidb # BUILD_START=$(date +%s) -$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER +$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID # # build liveboot @@ -55,7 +55,7 @@ rm $BUILD_SCRIPT # add liveboot build result to cidb # BUILD_END=$(date +%s) -$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $BUILD_START $BUILD_END +$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END # FIXME: too much sudo here... cd /srv/build/liveboot/builds -- 2.39.5