From: Holger Levsen Date: Fri, 12 Oct 2012 09:57:28 +0000 (+0200) Subject: adopt to changes in db design X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=5b69e8613a86a81c87b67ea6f276f20443b66b75;p=profitbricks%2Fjenkins-build-scripts.git adopt to changes in db design --- diff --git a/db_add.py b/db_add.py index 28f5a1d..fca33be 100755 --- a/db_add.py +++ b/db_add.py @@ -28,24 +28,14 @@ def db_add_job(con, name): #logger.debug("INSERT INTO jenkins_job(name) VALUES('%s')" % (name)) return cur.fetchone()[0] -def db_add_build(con, number, db_id): +def db_add_build(con, db_id, number, start, end, status): cur = con.cursor() cur.execute("SAVEPOINT a") try: - cur.execute("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id) VALUES(%s, %s) RETURNING id" % (number, db_id)) + cur.execute("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)) 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 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, 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, successful)) + 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_add_origin(con, origin): @@ -72,15 +62,15 @@ def db_add_package(con, package): #logger.debug("INSERT INTO deb_package(name) VALUES('%s') RETURNING id" % (package)) return cur.fetchone()[0] -def db_add_package_instance(con, package_id, origin_id, build_result_id, version): +def db_add_package_instance(con, package_id, origin_id, build_id, version): cur = con.cursor() cur.execute("SAVEPOINT a") try: - cur.execute("INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_result_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_result_id, version)) + cur.execute("INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_id, version)) except psycopg2.DatabaseError as e: # record already exist - this MUST NOT HAPPEN for jenkins builds cur.execute("ROLLBACK TO a") # have to rollback after failed command - logger.error("FAILED: INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_result_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_result_id, version)) + logger.error("FAILED: INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_id, version)) exit_error() return cur.fetchone()[0] @@ -92,8 +82,7 @@ def add_package_instances(origin, job_name, build_number, changes_file, version, db_job_id = db_add_job(con, job_name) 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, 'true') + db_build_id = db_add_build (con, db_job_id, build_number, start, end, 'true') logger.debug("INSERT success build number %s" % build_number) logger.debug("processing %s" %(changes_file)) cmd = ["dcmd", '--deb', changes_file] @@ -114,7 +103,7 @@ def add_package_instances(origin, job_name, build_number, changes_file, version, logger.debug('package: %s' %(package)) db_package_id = db_add_package (con, package) logger.debug("INSERT success package %s" % package) - db_package_instance_ids.append(db_add_package_instance (con, db_package_id, db_origin_id, db_build_result_id, version)) + db_package_instance_ids.append(db_add_package_instance (con, db_package_id, db_origin_id, db_build_id, version)) logger.debug("INSERT success package version %s %s" %( package,version)) #logger.debug('Cmd returned with status %d' %(cmdobj.returncode)) con.commit()