]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
bugfix: add_package_instances() needs to return an array
authorHolger Levsen <holger@layer-acht.org>
Thu, 27 Sep 2012 14:59:13 +0000 (16:59 +0200)
committerHolger Levsen <holger@layer-acht.org>
Thu, 27 Sep 2012 14:59:13 +0000 (16:59 +0200)
db_add.py
debian_build.py
debian_packages2db.py

index cec82558e4a1eecfa0d2dc463223b9c632defd4c..bb40fc8d657643fa3ed46c73a0d01172ef97f7b7 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -46,6 +46,18 @@ def db_add_build_result(con, build_id, start, end):
         #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'))
     return cur.fetchone()[0]
 
+def db_add_origin(con, origin):
+    cur = con.cursor()
+    cur.execute("SAVEPOINT a")
+    try:
+        cur.execute("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
+    except psycopg2.DatabaseError as e:
+    # record already exist
+        cur.execute("ROLLBACK TO a")  # have to rollback after failed command
+        cur.execute("SELECT id FROM deb_package_origin WHERE origin='%s'" % (origin))
+        #logger.debug("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
+    return cur.fetchone()[0]
+
 def db_add_package(con, package):
     cur = con.cursor()
     cur.execute("SAVEPOINT a")
@@ -64,25 +76,13 @@ def db_add_package_instance(con, package_id, origin_id, build_result_id, version
     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)) 
     except psycopg2.DatabaseError as e:
-    # record already exist - this MUST NOT HAPPEN
+    # 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))
         exit_error()
     return cur.fetchone()[0]
 
-def db_add_origin(con, origin):
-    cur = con.cursor()
-    cur.execute("SAVEPOINT a")
-    try:
-        cur.execute("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
-    except psycopg2.DatabaseError as e:
-    # record already exist
-        cur.execute("ROLLBACK TO a")  # have to rollback after failed command
-        cur.execute("SELECT id FROM deb_package_origin WHERE origin='%s'" % (origin))
-        #logger.debug("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
-    return cur.fetchone()[0]
-
-def add_package_instance(origin, job_name, build_number, changes_file, version, start, end):
+def add_package_instances(origin, job_name, build_number, changes_file, version, start, end):
     con = db_connect()
     #logger.debug("save %s to database" %(job_name))
     db_origin_id = db_add_origin(con, origin) 
@@ -106,17 +106,18 @@ def add_package_instance(origin, job_name, build_number, changes_file, version,
     )
     #logger.debug('Calling "%s":' %(' '.join(cmd)))
     ret = cmdobj.wait()
+    db_package_instance_ids=[]
     for line in cmdobj.stdout.readlines():
         package = os.path.basename(line.strip()).split('_')[0]
         #logger.debug('package: %s' %(package))
         db_package_id = db_add_package (con, package)
         #logger.debug("INSERT success package %s" % package)
-        db_package_instance_id = 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_result_id, version))
         logger.debug("INSERT success package version %s %s" %( package,version))
     #logger.debug('Cmd returned with status %d' %(cmdobj.returncode))
     con.commit()
     logger.info("CIDB update OK.")
-    return db_package_instance_id
+    return db_package_instance_ids
 
 def add_package_version(origin, package, version):
     logger = logger_init()
@@ -125,8 +126,6 @@ def add_package_version(origin, package, version):
     db_origin_id = db_add_origin(con, origin) 
     db_package_id = db_add_package (con, package)
     db_package_instance_id = db_add_package_instance (con, db_package_id, db_origin_id, 'NULL', version)
-    logger.debug("INSERT success package version %s %s" %( package,version))
-    #logger.debug('Cmd returned with status %d' %(cmdobj.returncode))
     con.commit()
     return db_package_instance_id
 
index f599a78754cde529f5469523dc3b10e86e528356..33b7e0d995a04930778bd4e189ed07e4469416bc 100755 (executable)
@@ -573,9 +573,8 @@ if __name__ == '__main__':
     # FIXME: must not add development builds... or maybe?
     # cidb wise, we only care about builds from master, hotfix + develop
     if GIT_BRANCH_NAME == 'master' or GIT_BRANCH_NAME == 'develop' or GIT_BRANCH_NAME.startswith('hotfix/'):
-        package_instances=[]
         try:
-            package_instances.append(add_package_instance("profitbricks", BUILD_JOBNAME, BUILD_NUMBER, changes_file, version, BUILD_START, BUILD_END))
+            package_instances = add_package_instance("profitbricks", BUILD_JOBNAME, BUILD_NUMBER, changes_file, version, BUILD_START, BUILD_END)
         except Exception, error:
             cmd = ['figlet-figlet', '-t', 'package instance not added to DB']
             subprocess.check_call(cmd)
index a32ad7e3121781ffd5c518f86eac9c15f7f03268..0a12d123a2dce2e42b422780b1cb7ba64d0d2b3a 100755 (executable)
@@ -47,7 +47,7 @@ if __name__ == '__main__':
         pkg_name = pkg_name.strip().split()[1]
         version = tmp.readline()
         version = version.strip().split()[1]
-        print 'would add %s %s %s' % (pkg_name,version,origin)
+        print 'adding %s %s from %s' % (pkg_name,version,origin)
         add_package_version(origin, pkg_name, version)
 
     os.remove(tmp.name)