import tempfile
import shutil
-import runner
-import utils
-import git
-from envparas import *
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common.envparas import *
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
def end(rc = 0):
shutil.rmtree(tmpdir)
try:
if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
print 'use local repo as reference to clone: Failed.'
shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
- if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+ if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
end(1)
mygit = git.Git(prjdir)
- mygit.fetch('%s/%s' % (giturl, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
+ mygit.fetch('%s/%s' % (GIT_URL, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
mygit.checkout('FETCH_HEAD')
patch = mygit.format_patch('-n1 -o %s' % tmpdir)[0]
basecommit = mygit.get_base_commit(GERRIT_PATCHSET_REVISION)
if line:
msg.append(line)
if msg:
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, 'aiaiai check result:\n- '+'\n'.join(msg)))
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, 'aiaiai check result:\n- '+'\n'.join(msg)))
end()
import glob
import shutil
import time
-import runner
-import utils
-import git
import gzip
-import obspkg
-from envparas import *
+# internal
+from common import obspkg
+from common import utils
+from common import git
+from common import runner
+from common.envparas import *
+from common import buildservice
+from common.send_mail import sendmail
import gbp.rpm
import gbp
-import buildservice
-from send_mail import sendmail
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['JENKINS_HOME',
+ 'WORKSPACE',
+ 'GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME',
+ 'GERRIT_PROJECT',
+ 'GERRIT_CHANGE_NUMBER',
+ 'GERRIT_REFSPEC',
+ 'GERRIT_PATCHSET_NUMBER',
+ 'GERRIT_BRANCH',
+ 'BUILD_NUMBER',
+ 'OBS_USERNAME',
+ 'OBS_API_URL',
+ 'OBS_OSCRC_PATH']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
def end(rc = 0):
shutil.rmtree(tmpdir)
prjdir = os.path.join(tmpdir, GERRIT_PROJECT)
prjpath, prj = os.path.split(GERRIT_PROJECT)
- if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
- if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+ if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+ if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
end(1)
# update local git tree from remote
try:
if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
print 'use local repo as reference to clone: Failed.'
shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
- if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+ if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
end(1)
mygit = git.Git(prjdir)
- mygit.fetch('%s/%s' % (giturl, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
+ mygit.fetch('%s/%s' % (GIT_URL, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
mygit.checkout('FETCH_HEAD')
packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
- mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+ mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
print "Project Mapping info: %s" %mapping
print 'The log file %s is deleted' %(buildlog_gz)
os.remove(buildlog_gz)
if not status:
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator"))
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator"))
end(1)
print 'The project %s is deleted on OBS' %(buildcheck_project)
bs.deleteProject(buildcheck_project)
print msg
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, msg))
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, msg))
end()
for element in envargs:
if element in os.environ.keys():
local_env[element]=os.getenv(element)
- print element
+ print element, local_env[element]
else:
print "WARN: %s doesn't exist" %(element)
local_env[element]=''
return local_env
-
+
+MAPPING_PRJ = 'scm/git-obs-mapping'
+RPMLINT_PRJ = 'scm/rpmlint-configi'
+OBS_URL = 'https://tz-testing-obs.bj.intel.com'
+FROM_EMAIL = 'no-replay@tz-testing-jenkins.bj.intel.com'
#envargs = [# General parameters
# 'OBS_DEST_PROJECT',
# 'OBS_STAGING_PROJECT',
def get_commit_info(self, commit):
"""Given a commit name, return a dictionary of its components,
including id, author, email, subject, and body."""
- out = self._exec_git('log',
+ ret, outs = self._exec_git('log',
['--pretty=format:%h%n%an%n%ae%n%s%n%b%n',
- '-n1', commit])[1].split('\n')
- return {'id' : out[0].strip(),
- 'author' : out[1].strip(),
- 'email' : out[2].strip(),
- 'subject' : out[3].rstrip(),
- 'body' : [line.rstrip() for line in out[4:]]}
+ '-n1', commit])
+ if ret:
+ return None
+ else:
+ out = outs.splitlines()
+ return {'id' : out[0].strip(),
+ 'author' : out[1].strip(),
+ 'email' : out[2].strip(),
+ 'subject' : out[3].rstrip(),
+ 'body' : [line.rstrip() for line in out[4:]]}
def get_tagger(self, tag):
ret, outs = self._exec_git('show',
oscrc: optional, the path of customized oscrc
if not specified, ~/.oscrc will be used
"""
-
+ print "Init obs package %s %s %s %s %s" % (basedir, prj, pkg, apiurl, oscrc)
if oscrc:
self._oscrc = oscrc
else:
with Workdir(self._bdir):
shutil.rmtree(prj, ignore_errors = True)
- if self._bs.isNewPackage(prj, pkg):
+ if self.is_new_pkg():
# to init new package in local dir
self._mkpac()
else:
self._checkout_latest()
def _mkpac(self):
+ print "mkpac %s %s" % (self._prj, self._pkg)
with Workdir(self._bdir):
self._bs.mkPac(self._prj, self._pkg)
def _checkout_latest(self):
""" checkout the 'latest' revision of package with link expanded
"""
-
+ print "checkout latest %s %s" % (self._prj, self._pkg)
with Workdir(self._bdir):
try:
self._bs.checkout(self._prj, self._pkg)
def is_new_pkg(self):
"""Check whether this is new package in obs
"""
- return self._bs.isNewPackage(self._prj, self._pkg)
+ print "%s package list:" % self._prj, self._bs.getPackageList(self._prj)
+ if self._pkg in self._bs.getPackageList(self._prj):
+ print "%s is NOT new package in %s" % (self._pkg, self._prj)
+ return False
+ else:
+ print "%s is new package in %s" % (self._pkg, self._prj)
+ return True
def get_workdir(self):
return self._pkgpath
import errors
import msger
import runner
-from envparas import *
+from envparas import export
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
class Workdir(object):
def __init__(self, path):
return msg
def get_gerrit_info(prj, cmitid):
- ret, outs = runner.runtool('%s query --current-patch-set project: %s commit: %s' % (gerritcmd, prj, cmitid))
+ ret, outs = runner.runtool('%s query --current-patch-set project: %s commit: %s' % (GERRIT_CMD, prj, cmitid))
print '\n-----------------------\nquery gerrit change info for commit %s' % cmitid
- print '%s query --current-patch-set project: %s commit: %s' % (gerritcmd, prj, cmitid)
+ print '%s query --current-patch-set project: %s commit: %s' % (GERRIT_CMD, prj, cmitid)
gerritinfo = {}
for line in outs.splitlines():
if line.startswith(' number: '):
import glob
import shutil
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
import gbp.rpm
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['JENKINS_HOME',
+ 'GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME',
+ 'GERRIT_PROJECT',
+ 'GERRIT_BRANCH',
+ 'GERRIT_REFSPEC',
+ 'GERRIT_PATCHSET_NUMBER',
+ 'GERRIT_CHANGE_NUMBER',
+ 'WORKSPACE']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
def end(rc = 0):
shutil.rmtree(tmpdir)
prjpath, prj = os.path.split(GERRIT_PROJECT)
# check whether exist git-obs-mapping.xml in local
- if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
- print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
- if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+ if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+ print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+ if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
end(1)
# update local git tree from remote
try:
if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
print 'use local repo as reference to clone: Failed.'
shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
- if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+ if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
end(1)
mygit = git.Git(prjdir)
print('submitted to obs: %s' % needsr)
'''
- mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+ mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
print 'git-obs-mapping:', mapping
obstarget = []
print('\n-------------------------------\ncheck obs target result:\n%s' % checkobsmsg)
if checkobsmsg:
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
print('\n-------------------------------\ncheck specfile result:\n%s' % checkspecmsg)
if checkspecmsg:
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
end()
+++ /dev/null
-#!/usr/bin/env python
-
-import sys, os
-import tempfile, locale
-
-sys.path.insert(1, '/usr/share/rpmlint')
-
-from Filter import setRawOut, printed_messages, badnessThreshold, _badness_score
-import SpecCheck
-import Config
-import Pkg
-import Filter
-
-def __print(s):
- pass
-
-def _print(msgtype, pkg, reason, details):
- global _badness_score
-
- threshold = badnessThreshold()
-
- badness = 0
- if threshold >= 0:
- badness = Config.badness(reason)
- # anything with badness is an error
- if badness:
- msgtype = 'E'
- # errors without badness become warnings
- elif msgtype == 'E':
- msgtype = 'W'
-
- ln = ""
- if pkg.current_linenum is not None:
- ln = "%s:" % pkg.current_linenum
- arch = ""
- if pkg.arch is not None:
- arch = ".%s" % pkg.arch
- s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, msgtype, reason)
- if badness:
- s = s + " (Badness: %d)" % badness
- for d in details:
- s = s + " %s" % d
- else:
- if not Config.isFiltered(s):
- outputs.append(s)
- printed_messages[msgtype] += 1
- _badness_score += badness
- if threshold >= 0:
- _diagnostic.append(s + "\n")
- else:
- __print(s)
- if Config.info:
- printDescriptions(reason)
- return True
-
- return False
-
-
-Filter._print=_print
-spec_file=sys.argv[1]
-
-# the tempfile is designed for python policycheck.py, bash script doesn't use it
-
-try:
- execfile(os.path.expanduser('~/.config/rpmlint'))
-except IOError:
- pass
-
-
-outputs = []
-
-pkg = Pkg.FakePkg(spec_file)
-check = SpecCheck.SpecCheck()
-check.check_spec(pkg, spec_file)
-pkg.cleanup()
-
-print "rpmlint checked %s: %d errors, %s warnings." % (spec_file, printed_messages["E"], printed_messages["W"])
-for line in outputs:
- line = line.strip().lstrip(spec_file+':').strip()
- if not line.startswith('W:') and not line.startswith('E:'):
- line = 'line '+line
- print '- '+line
import glob
import shutil
import re
-
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
-import errors
-import mysql
-from send_mail import sendmail
+from time import sleep
+
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
+from common import errors
+from common import mysql
+from common.send_mail import sendmail
import gbp.rpm
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_EVENT_TYPE',
+ 'GERRIT_PROJECT',
+ 'GERRIT_BRANCH',
+ 'GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME',
+ 'GERRIT_CHANGE_NUMBER',
+ 'GERRIT_PATCHSET_NUMBER',
+ 'GERRIT_PATCHSET_REVISION',
+ 'GERRIT_OLDREV',
+ 'GERRIT_NEWREV',
+ 'GERRIT_REFNAME',
+ 'WORKSPACE',
+ 'JENKINS_HOME',
+ 'OBS_API_URL',
+ 'OBS_OSCRC_PATH',
+ 'MYSQL_HOSTNAME',
+ 'MYSQL_USERNAME',
+ 'MYSQL_PASSWORD',
+ 'MYSQL_DB_NAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+
ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
'dbstate': {'success' : 'TRIGGER_SUCCESS',
- 'failure' : 'TRIGGER_FAILURE',
- 'retry' : 'TRIGGER_RETRY'},
- 'dbtable': {'CHANGE_MERGED' : 'ChangeMerged_Event',
- 'REF_UPDATED' : 'RefUpdated_Event'},
- 'dbkey': {'CHANGE_MERGED': {'changeNum' : GERRIT_CHANGE_NUMBER,
- 'patchsetNum' : GERRIT_PATCHSET_NUMBER},
- 'REF_UPDATED':{'oldRev' : GERRIT_OLDREV,
- 'newRev' : GERRIT_NEWREV}},
+ 'failure' : 'TRIGGER_FAILURE',
+ 'retry' : 'TRIGGER_RETRY'},
+ 'dbtable' : {'CHANGE_MERGED' : 'ChangeMerged_Event',
+ 'REF_UPDATED' : 'RefUpdated_Event'},
+ 'dbkey' : {'CHANGE_MERGED' : {'changeNum' : GERRIT_CHANGE_NUMBER,
+ 'patchsetNum' : GERRIT_PATCHSET_NUMBER},
+ 'REF_UPDATED' : {'oldRev' : GERRIT_OLDREV,
+ 'newRev' : GERRIT_NEWREV}},
}
def end(result = 'success'):
end('success')
# check whether exist git-obs-mapping.xml in local
- if GERRIT_PROJECT == mappingprj or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
- print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
- if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+ if GERRIT_PROJECT == MAPPING_PRJ or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+ print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+ if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
end('retry')
- if GERRIT_PROJECT == mappingprj:
+ if GERRIT_PROJECT == MAPPING_PRJ:
print '\nPulled scm/git-obs-mapping change to local, exit now'
end('success')
# update local git tree from remote
try:
- if utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), GERRIT_PROJECT, giturl)):
+ if utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), GERRIT_PROJECT, GIT_URL)):
if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
print 'use local repo as reference to clone: Failed.'
shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
- if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+ if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
end('retry')
# if scm/rpmlint-config changed, update HOME/.config/rpmlint
- print '\n', GERRIT_PROJECT, rpmlintprj
- if GERRIT_PROJECT == rpmlintprj:
+ print '\n', GERRIT_PROJECT, RPMLINT_PRJ
+ if GERRIT_PROJECT == RPMLINT_PRJ:
if not os.path.exists('%s/.config' % JENKINS_HOME):
os.makedirs('%s/.config' % JENKINS_HOME)
shutil.copy2('%s/rpmlint' % prjdir, '%s/.config/rpmlint' % JENKINS_HOME)
# the tagged commit has been merged on gerrit
if branch not in branchs:
title = '[Submit Request Failed]: improper tag: %s' % tag
- checktagmsg = 'The tag %s pushed, but it only can be used to submit commit on %s branch to OBS. Please "gbs submit" to trigger the submission.' % (tag, branch)
+ checktagmsg = 'The tag %s pushed, but the related commit does NOT exist in %s branch. please follow the below format submit/{version}/{date.time}. Suggest to use gbs submit to trigger submission.' % (tag, branch)
else:
GERRIT_BRANCH = branch
print 'submit tag : %s, on branch %s' % (tag, branch)
else:
# The tagged commmit still open, abort submit this time
print '\nThis change is still open in gerrit, exit now'
- title = '[Submit Request Failed]: tag: %s' % tag
+ title = '[Submit Request Pending]: tag: %s' % tag
checktagmsg = 'The commit tag %s attached is still under review in gerrit. After reviewer accpet this commit, it will be submitted to OBS corresponding project.' % tag
else:
print 'tag %s don\'t match the name format, exit now' % tag
title = '[Submit Request Failed]: unknown tag: %s' % tag
- checktagmsg = 'The tag %s pushed, but unknown tag format, please use "gbs submit" to trigger the submission.' % tag
+ checktagmsg = 'The tag %s pushed, but unknown tag format, please follow the below format submit/{version}/{date.time}. Suggest to use gbs submit to trigger submission.' % tag
else:
# Only when there is tag submit/*, it's for submit
if GERRIT_BRANCH == 'master':
print '\nThis change don\'t contain submit/*/* tag, exit now'
end('success')
- commitinfo = mygit.get_commit_info(tag)
tagger = mygit.get_tagger(tag)
- if GERRIT_EVENT_TYPE == "REF_UPDATED":
- gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
- print 'gerritinfo', gerritinfo
- if gerritinfo:
- GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
- GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
if not tagger:
print '\ntag %s is not annotated tag, exit now' % tag
end('failure')
packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
print('packaging dir is %s/%s' % (prjdir, packagingdir))
+ if not GERRIT_PATCHSET_REVISION:
+ GERRIT_PATCHSET_REVISION = mygit.rev_parse(tag)
+ commitinfo = mygit.get_commit_info(GERRIT_PATCHSET_REVISION)
+ if GERRIT_EVENT_TYPE == "REF_UPDATED":
+ gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
+ print 'gerritinfo', gerritinfo
+ if gerritinfo:
+ GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
+ GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
mygit.checkout(tag)
- mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+ mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
print 'git-obs-mapping:', mapping
for target in mapping:
if not os.path.isfile(specfile):
continue
- # use gbp to parse specfile
try:
+ # use gbp to parse specfile
spec = gbp.rpm.parse_spec(specfile)
- except GbpError, exc:
+ # use gbs export to generate tarball
+ outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
+ with utils.Workdir(prjdir):
+ runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
+ except Exception, exc:
print('gbp parse spec failed. %s' % exc)
end('failure')
- # use gbs export to generate tarball
- outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
- with utils.Workdir(prjdir):
- runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
- print '\ngbs export --spec=%s -o %s' % (specfile, outdir)
tarballdir = os.path.join(outdir, os.listdir(outdir)[0])
if obs_stg_prj != obs_dst_prj:
newreq = localpkg.submit_req(obs_dst_prj, msg=msg)
print 'New request %s is created' % newreq
break
- except errors.ObsError, exc:
+ except Exception, exc:
print('obs operation failed, retrying...')
+ print exc
sleep(1)
retry_count -= 1
comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
- print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
+ print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
else:
print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
import glob
import shutil
import re
-
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
-import errors
-import mysql
-from send_mail import sendmail
+from time import sleep
+
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
+from common import errors
+from common import mysql
+from common.send_mail import sendmail
import gbp.rpm
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_EVENT_TYPE',
+ 'GERRIT_PROJECT',
+ 'GERRIT_BRANCH',
+ 'GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME',
+ 'GERRIT_CHANGE_NUMBER',
+ 'GERRIT_PATCHSET_NUMBER',
+ 'GERRIT_PATCHSET_REVISION',
+ 'GERRIT_OLDREV',
+ 'GERRIT_NEWREV',
+ 'GERRIT_REFNAME',
+ 'WORKSPACE',
+ 'JENKINS_HOME',
+ 'OBS_API_URL',
+ 'OBS_OSCRC_PATH',
+ 'MYSQL_HOSTNAME',
+ 'MYSQL_USERNAME',
+ 'MYSQL_PASSWORD',
+ 'MYSQL_DB_NAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
- 'dbstate': {'success' : 'TRIGGER_SUCCESS',
- 'failure' : 'TRIGGER_FAILURE',
- 'retry' : 'TRIGGER_RETRY'},
- 'dbtable': {'CHANGE_MERGED' : 'ChangeMerged_Event',
- 'REF_UPDATED' : 'RefUpdated_Event'},
- 'dbkey': {'CHANGE_MERGED': {'changeNum' : GERRIT_CHANGE_NUMBER,
- 'patchsetNum' : GERRIT_PATCHSET_NUMBER},
- 'REF_UPDATED':{'oldRev' : GERRIT_OLDREV,
- 'newRev' : GERRIT_NEWREV}},
+ 'dbstate' : {'success' : 'TRIGGER_SUCCESS',
+ 'failure' : 'TRIGGER_FAILURE',
+ 'retry' : 'TRIGGER_RETRY'},
+ 'dbtable' : {'CHANGE_MERGED' : 'ChangeMerged_Event',
+ 'REF_UPDATED' : 'RefUpdated_Event'},
+ 'dbkey' : {'CHANGE_MERGED' : {'changeNum' : GERRIT_CHANGE_NUMBER,
+ 'patchsetNum' : GERRIT_PATCHSET_NUMBER},
+ 'REF_UPDATED' : {'oldRev' : GERRIT_OLDREV,
+ 'newRev' : GERRIT_NEWREV}},
}
def end(result = 'success'):
end('success')
# check whether exist git-obs-mapping.xml in local
- if GERRIT_PROJECT == mappingprj or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
- print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
- if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+ if GERRIT_PROJECT == MAPPING_PRJ or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+ print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+ if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
end('retry')
- if GERRIT_PROJECT == mappingprj:
+ if GERRIT_PROJECT == MAPPING_PRJ:
print '\nPulled scm/git-obs-mapping change to local, exit now'
end('success')
try:
if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
print 'use local repo as reference to clone: Failed.'
shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
- if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+ if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
end('retry')
packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
checktagmsg = ''
if GERRIT_EVENT_TYPE == "REF_UPDATED":
tag = GERRIT_REFNAME[len('refs/tags/'):]
- title = '[Submit Request Failed]: improper tag: %s' % tag
- checktagmsg = 'The submission tag %s pushed, which will not work several weeks later. Because submission process changed, please upgrade gbs and use \'gbs submit\' to trigger the submission.' % tag
+ title = '[Submit Request Succeed]: improper tag %s in %s' % (tag, GERRIT_PROJECT)
+ checktagmsg = 'Warning: The submission tag %s pushed in %s project, please use new tag format: annotated tag submit/{version}/{date.time}. Example: submit/trunk/20120803.174859. Suggest to use gbs submit to trigger submission.' % (tag, GERRIT_PROJECT)
else:
needsr = False
tag = mygit.describe('--exact-match --tags --match "build/*"', GERRIT_PATCHSET_REVISION)
if not needsr:
end('success')
- commitinfo = mygit.get_commit_info(tag)
tagger = mygit.get_tagger(tag)
+ if not GERRIT_PATCHSET_REVISION:
+ GERRIT_PATCHSET_REVISION = mygit.rev_parse(tag)
+ commitinfo = mygit.get_commit_info(GERRIT_PATCHSET_REVISION)
if GERRIT_EVENT_TYPE == "REF_UPDATED":
gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
print 'gerritinfo', gerritinfo
if gerritinfo:
GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
+
if checktagmsg and title:
if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
- print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg)
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg))
+ print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg)
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg))
if tagger:
print checktagmsg
checktagmsg = 'Hi, %s,\n\n' % tagger['author'] + checktagmsg + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
sendmail(title, checktagmsg, FROM_EMAIL, tagger['email'])
end('success')
- msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
+ if tagger:
+ msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
+ else:
+ msg = 'Git project: %s\nTag:%s\nCommit: %s %s' % (GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
mygit.checkout(tag)
- mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+ mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
print 'git-obs-mapping:', mapping
for target in mapping:
if not os.path.isfile(specfile):
continue
- # use gbp to parse specfile
try:
+ # use gbp to parse specfile
spec = gbp.rpm.parse_spec(specfile)
- except GbpError, exc:
+ # use gbs export to generate tarball
+ outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
+ with utils.Workdir(prjdir):
+ runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
+ except Exception, exc:
print('gbp parse spec failed. %s' % exc)
end('failure')
- # use gbs export to generate tarball
- outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
- with utils.Workdir(prjdir):
- runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
print '\ngbs export --spec=%s -o %s' % (specfile, outdir)
tarballdir = os.path.join(outdir, os.listdir(outdir)[0])
if obs_stg_prj != obs_dst_prj:
+ print "check whether tmp package exist in build project"
tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp',
apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
if tmppkg.is_new_pkg():
tmppkg.commit("Leave an empty package in this project to prevent OBS delete it automatically when all request from here are accepted.")
print '\nCheckout %s/%s to local' % (obs_stg_prj, spec.name)
+ print tmpdir, obs_stg_prj, spec.name, OBS_API_URL, OBS_OSCRC_PATH
localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name,
apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
oscworkdir = localpkg.get_workdir()
newreq = localpkg.submit_req(obs_dst_prj, msg=msg)
print 'New request %s is created' % newreq
break
- except errors.ObsError, exc:
+ except Exception, exc:
print('obs operation failed, retrying...')
+ print exc
sleep(1)
retry_count -= 1
# post sr info back to gerrit
requrl = ' %s/request/show/%s' % (OBS_URL, newreq)
- comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
+ if tagger:
+ comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
+ else:
+ comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
- print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
+ print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
else:
print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
- comment = 'Hi, %s,\n\n' % tagger['author'] + comment + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
- sendmail('[Submit Request]: changes to %s/%s' % (obs_dst_prj, spec.name), comment, FROM_EMAIL, tagger['email'])
+ if tagger:
+ comment = 'Hi, %s,\n\n' % tagger['author'] + comment + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
+ sendmail('[Submit Request]: changes to %s/%s' % (obs_dst_prj, spec.name), comment, FROM_EMAIL, tagger['email'])
end('success')