From: Holger Levsen Date: Fri, 12 Oct 2012 10:37:34 +0000 (+0200) Subject: adopt to changes in db design, this time for liveboot X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=3ecfa490a1b4a24cfe8949cffd77b038071f9095;p=profitbricks%2Fjenkins-build-scripts.git adopt to changes in db design, this time for liveboot --- diff --git a/db_add.py b/db_add.py index 38f2d04..2244785 100755 --- a/db_add.py +++ b/db_add.py @@ -38,6 +38,16 @@ def db_add_build(con, db_id, number, start, end, status): logger.info("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, '%s', '%s', '%s') RETURNING id" % (db_id, number, start, end, status)) return cur.fetchone()[0] +def db_update_build(con, db_id, end, status): + cur = con.cursor() + cur.execute("SAVEPOINT a") + try: + cur.execute("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status)) + except psycopg2.DatabaseError as e: + cur.execute("ROLLBACK TO a") # have to rollback after failed command + logger.info("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status)) + return cur.fetchone()[0] + def db_add_origin(con, origin): cur = con.cursor() cur.execute("SAVEPOINT a") @@ -159,18 +169,18 @@ def get_liveboot_build_id(job_name, build_number): return False return cur.fetchone()[0] -def add_liveboot_build(job_name, build_number, request_id): +def add_liveboot_build(job_name, build_number, request_id, start): 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, db_build_id) + db_build_id = db_add_build(con, db_job_id, build_number, start, 'NULL', 'in progress') + db_add_requested_liveboot_build(con, request_id, db_build_id) con.commit() logger.info("CIDB init for liveboot OK.") return -def finish_liveboot_build(build_id, start, end): +def finish_liveboot_build(build_id, end): con = db_connect() - db_add_build_result (con, build_id, start, end, 'successful') + db_update_build(con, build_id, end, 'successful') con.commit() logger.info("CIDB update for liveboot OK.") return diff --git a/liveboot2db.py b/liveboot2db.py index 107e45d..cc5e93e 100755 --- a/liveboot2db.py +++ b/liveboot2db.py @@ -7,9 +7,9 @@ from db_add import * if __name__ == '__main__': - if len(sys.argv) != 4 and len(sys.argv) !=6: + if len(sys.argv) != 5 and len(sys.argv) !=6: # if the build was just started: - print("usage: %s $job_name $build_number $liveboot_request_id") + print("usage: %s $job_name $build_number $liveboot_request_id $start_time") print("or:") # if the build was successful print("usage: %s $job_name $build_number $liveboot_request_id $start_time $end_time") @@ -18,13 +18,13 @@ if __name__ == '__main__': job_name = sys.argv[1] build_number = sys.argv[2] request_id = sys.argv[3] + start = sys.argv[4] if len(sys.argv) != 6: - add_liveboot_build(job_name, build_number, request_id) + add_liveboot_build(job_name, build_number, request_id, start) else: - 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) + finish_liveboot_build(build_id, end) diff --git a/liveboot_build.sh b/liveboot_build.sh index 5bb40a9..24307ce 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 $REQUEST_ID +$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START # # build liveboot