]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
cleanup #6: too many changes (most likely completely broken)
authorMathias Klette <mathias.klette@profitbricks.com>
Fri, 3 May 2013 08:50:01 +0000 (10:50 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Fri, 3 May 2013 08:50:01 +0000 (10:50 +0200)
common_code.py
debian_build.py
lib/dput.py

index bb57bb0a1efcb59908541ee1a6ada1b537046986..0806432b06eab39c7c2acba708a568ede2604732 100755 (executable)
@@ -21,7 +21,7 @@ def logger_init(
 
     if log_level == None: 
         try:
-            if ENV['GIT_BRANCH_NAME'] == 'master':
+            if ENV['GIT_BRANCH'] == 'master':
                 log_level = logging.INFO
             else:
                 log_level = logging.DEBUG
@@ -48,9 +48,11 @@ ENV = os.environ
 ENV.setdefault('ARGV',' '.join(sys.argv))
 ENV.setdefault('CWD',os.getcwd())
 
+BIN_DCH = '/usr/bin/dch'
 BIN_DPUT = '/usr/bin/dput'
 BIN_FIGLET = '/usr/bin/figlet-figlet'
 BIN_GIT = '/usr/bin/git'
+BIN_GIT_DCH = '/usr/bin/git-dch'
 BIN_MAKE_KPKG = '/usr/bin/make-kpkg'
 BIN_RM = '/bin/rm'
 BIN_SUDO = '/usr/bin/sudo'
index 29cf1af5792cf1b63668a2d679887ad5693f18d7..15ce01486331d69190156d8c7cc158a89272ce72 100755 (executable)
@@ -25,6 +25,9 @@ import time
 from ConfigParser import SafeConfigParser
 from multiprocessing import cpu_count
 
+# import 3rd parties
+from debian import changelog
+
 # import local modules
 from add_liveboot_request import add_liveboot_request
 from cidb import *
@@ -40,7 +43,6 @@ logger = logger_init(__file__)
 
 # jenkins environment - parameters
 ENV.setdefault('NO_UPLOAD','')
-ENV.setdefault('GIT_BRANCH_NAME',ENV['GIT_BRANCH'])
 GIT_REPO_PATH = ENV['GIT_REPO_PATH']
 
 # local constants
@@ -60,28 +62,12 @@ STABLE_DISTRIBUTIONS = (
     'production', 
     'production-proposed-updates'
     )
-
-dput_obj = dput.Dput()
-dput_obj.config = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf')
-dput_obj.section = 'profitbricks'
-if ENV['GIT_BRANCH_NAME'].startswith('feature/') or ENV['GIT_BRANCH_NAME'].startswith('poc/') or ENV['GIT_BRANCH_NAME'].startswith('bugfix/'):   
-    dput_obj.contents = {
-        'fqdn': 'alexandria.pb.local',
-        'method': 'scp',
-        'login': 'reprepro',
-        'incoming': '/srv/dev-repository/incoming/',
-        'allow_unsigned_uploads': 1,
-        'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
-        }
-else:
-    dput_obj.contents = {
-        fqdn: 'alexandria.pb.local',
-        method: 'scp',
-        login: 'reprepro',
-        incoming: '/srv/profitbricks-repository/incoming/profitbricks',
-        allow_unsigned_uploads: 1,
-        post_upload_command: 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
-        },
+STABLE_BRANCHES_RE = re.compile(
+    '^(master|hotfix/.*)$')
+DEVELOP_BRANCHES_RE = re.compile(
+    '^(develop|pre-staging|release/.*)$')
+EXPERIMENTAL_BRANCHES_RE = re.compile(
+    '^(experimental|(feature|poc|bugfix)/.*)$')
 
 def getopts():
     usage = '%prog [options]'
@@ -121,178 +107,206 @@ def getopts():
 if __name__ == '__main__':
     logger.debug('Environment: %s' %(ENV))
 
+    # Act I: prepare variables
+    # .. command line arguments
     # FIXME: not used right now, shall it be used?
     options, args = getopts()
 
+    # .. actions related, define defaults
+    do_autoincrement = False
+    do_cidb = False
+    do_cleanup = True
+    do_liveboot_request = True
+    do_reports = True
+    do_tagging = False
+    do_uploads = True
+
+    # .. repository related
+    curr_commit = ENV['GIT_COMMIT']
     gitrepo = git.Repo('.')
+    local_branch = ENV['GIT_BRANCH']
+    remote_branch = os.path.join('origin', ENV['GIT_BRANCH'])
+
+    # .. dput related (some overrides happening below, though)
+    dput_obj = dput.Dput(
+        config = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf'),
+        section = 'profitbricks',
+        contents = {
+            'fqdn': 'alexandria.pb.local',
+            'method': 'scp',
+            'login': 'reprepro',
+            'incoming': '/srv/profitbricks-repository/incoming/profitbricks',
+            'allow_unsigned_uploads': 1,
+            'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
+            }
+        )
+
+    # .. changelog related
+    daily_date = BUILD_START.strftime('%Y%m%d%H%M%S')
+
+    fh = open('debian/changelog')
+    cl = changlog(fh)
+    curr_name = cl.package
+    curr_version = cl.full_version
+    curr_dist = cl.distributions
+    fh.close()
+    logger.info(
+        'Current Changelog: Package {name} with version {version} in distribution {dist}'.format(
+            name = curr_name,
+            version = curr_version,
+            dist = curr_dist,
+            ))
+
+
+    # Act II: make decissions
+    for line in fileinput.input('debian/control'):
+        if line.lower().startswith('section: unknown'):
+            raise Exception('debian/control sets "section" to unknown. This is not allowed, failing...')
+            exit_error()
 
-    # reset local repository first
-    localname = ENV['GIT_BRANCH_NAME']
-    remotename = os.path.join('origin', ENV['GIT_BRANCH_NAME'])
-
-    logger.info('Reset and clean repository.')
-    gitrepo.git.fetch('--force','--prune').strip()
-    gitrepo.git.reset('--hard','HEAD').strip()
-    gitrepo.git.execute('sudo','git','clean','-fdx').strip()
-    gitrepo.git.branch('-D','%s' %(localname),with_exceptions=False).strip()
-
-    try:
-        logger.info('Checkout branch %s.' %(remotename))
-        gitrepo.git.checkout('-b','%s' %(localname),'%s' %(remotename)).strip()
-    except Exception as error:
-        raise Exception('Failure while checking out Git clone: ',exc_info=error)
+    if re.match(STABLE_BRANCHES_RE,ENV['GIT_BRANCH']):
+        new_dist = 'production-proposed-updates'
+        new_version = '{version}'.format(
+            version = curr_version, 
+            )
+        # replace valid debian version chars that are invalid for git tagging
+        new_tag = curr_version.replace('~','_')
+        new_tag = new_tag.replace(':',',')
+        # reset actions
+        # .. always include successful build packages into CIDB
+        do_cidb = True
+        # .. only take care of changelog automation if we want it to
+        if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
+            do_autoincrement = True
+        # .. fail if we already found the tag we would create upon a successfull build,
+        #    except, the existing tag uses the same commit as we were triggered with
+        remote_tag = [tag for tag in gitrepo.tags if tag.name == version_tag]
+        if len(remote_tag) > 0: 
+            if remote_tag[0].commit.id == curr_commit:
+                logger.info('Tag was already created for this commit.')
+                do_tagging = False
+            else:
+                logger.error('Tag was already created for another commit.')
+                exit_error()
+        else:
+            do_tagging = True
+
+    elif re.match(DEVELOP_BRANCHES_RE,ENV['GIT_BRANCH']):
+        new_dist = 'pre-staging'
+        new_version = '{version}~develop{date}+{build}+{commit}'.format(
+            version = curr_version, 
+            date = daily_date, 
+            build = ENV['BUILD_NUMBER'], 
+            commit = curr_commit[0:7],
+            )
+        # reset actions
+        # .. always include successful build packages into CIDB
+        do_cidb = True
+        # .. never tag in-development builds
+        do_tagging = False
+
+    elif re.match(EXPERIMENTAL_BRANCHES_RE,ENV['GIT_BRANCH']):
+        new_dist ='dev-'+ ENV['GIT_BRANCH'].replace("/","-")
+        new_version = '{version}~experimental{date}+{build}+{commit}'.format(
+            version = curr_version, 
+            date = daily_date, 
+            build = ENV['BUILD_NUMBER'], 
+            commit = curr_commit[0:7],
+            )
+        dput_obj.contents.update({
+            'incoming': '/srv/dev-repository/incoming/',
+            'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
+            })
+
+    #FIXME: enable this once Florian acks.
+    #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
+    #    if ENV['GIT_BRANCH_NAME'] == 'pre-staging':
+    #        version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
+    #        changelog_distro = 'pre-staging'
+    #    else:
+    #        # use shorter date because we can
+    #        daily_date = datetime.datetime.now().strftime('%Y%m%d')
+    #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
+    #        changelog_distro = 'unstable'
+
+    # .. just used for GitBuildPackage()
+    pb_suite = new_dist
+
+
+    # ACT III: do something actually
+    # .. do some housekeeping first
+    if not do_cleanup:
+        figlet('Skip cleanup')
     else:
+        # .. reset local repository at first
+        logger.info('Reset and clean repository.')
+        gitrepo.git.fetch('--force','--prune').strip()
+        gitrepo.git.reset('--hard','HEAD').strip()
+        gitrepo.git.execute('sudo','git','clean','-fdx').strip()
+        gitrepo.git.branch('-D','%s' %(local_branch),with_exceptions=False).strip()
+
+        # .. and re-checkout the requested branch
+        logger.info('Checkout branch %s.' %(remote_branch))
+        gitrepo.git.checkout(
+            '-b','%s' %(local_branch),
+            '%s' %(remote_branch),
+            ).strip()
         logger.debug('Status is now:\n%s' %(gitrepo.git.status().strip()))
 
-    if ENV['GIT_BRANCH_NAME'] == 'master' and ENV['JOB_NAME'] in AUTO_CHANGELOG_REPONAMES:
-        subprocess.check_call(['/usr/bin/dch', '-i', 'Released by jenkins.'])
-        subprocess.check_call(['/usr/bin/git-dch', '-R', '-a', '--spawn-editor=none'])
+        # .. and also cleanup existing *orig.tar.gz
+        if os.path.isdir(BUILD_AREA):
+            files = [os.path.join(BUILD_AREA, file) 
+                     for file in fnmatch.filter(
+                         os.listdir(BUILD_AREA), '*.orig.tar.gz'
+                         )]
+
+            if len(files) > 0:
+                logger.debug('Previous upstream tarball(s) found: %s' %(files))
+                cmd = [BIN_SUDO, BIN_RM, '-v']
+                cmd.extend(files)
+                logger.debug('Executing "%s" ...' %(' '.join(cmd)))
+                cmdobj = subprocess.Popen(
+                        cmd,
+                        shell=False,
+                        cwd='/',
+                        close_fds=True,
+                        stdout=subprocess.PIPE,
+                        stderr=subprocess.STDOUT,
+                        env={'':''}
+                        ).wait()
+
+                for line in cmdobj.stdout.readlines():
+                    logger.debug('%s' %(line.strip()))
+
+                logger.debug('Returned with status %d' %(cmdobj.returncode))
+
+    # .. update changelog if we trust the package
+    if do_autoincrement:
+        subprocess.check_call([BIN_DCH, '-i', 'Released by jenkins.'])
+        subprocess.check_call([BIN_GIT_DCH, '-R', '-a', '--spawn-editor=none'])
         gitrepo.git.commit('-a','-s','-m','Released by jenkins')
         gitrepo.git.push('origin', 'master')
         logger.info('Changelog incremented by jenkins using debian_build.py!')
 
-    # cleanup existing *orig.tar.gz
-    if os.path.isdir(BUILD_AREA):
-        files = [os.path.join(BUILD_AREA, file) 
-                 for file in fnmatch.filter(os.listdir(BUILD_AREA), '*.orig.tar.gz')]
-
-        if len(files) > 0:
-            logger.debug('Previous upstream tarball(s) found: %s' %( files ))
-            cmd = [BIN_SUDO, BIN_RM, '-v']
-            cmd.extend(files)
-            logger.debug('Executing "%s" ...' %(' '.join(cmd)))
-            cmdobj = subprocess.Popen(
-                    cmd,
-                    shell=False,
-                    cwd='/',
-                    close_fds=True,
-                    stdout=subprocess.PIPE,
-                    stderr=subprocess.STDOUT,
-                    env={'':''}
-                    ).wait()
-
-            for line in cmdobj.stdout.readlines():
-                logger.debug('%s' %(line.strip()))
-
-            logger.debug('Returned with status %d' %(cmdobj.returncode))
-
-    # gather details from changelog
-    cmd = ['dpkg-parsechangelog']
-    parse_changelog =  subprocess.Popen(
-            cmd,
-            shell=False,
-            close_fds=True,
-            stdout=subprocess.PIPE,
-            stderr=sys.stderr,
-            cwd='./'
-            )
-    ret = parse_changelog.wait()
-    if ret:
-        message = '{cmd} failed with return code {code}'.format(
-            cmd = ' '.join(cmd),
-            code = ret,
-            )
-        logger.error(message)
-        raise Exception(message)
-        exit_error()
+    # .. or to set approriate versions for development candidates
     else:
-        changelog = parse_changelog.stdout
-
-    cmd = ['grep-dctrl', '-n', '-s', 'Source,Version,Distribution', '']
-    grep_dctrl =  subprocess.Popen(
-            cmd,
-            shell=False,
-            close_fds=True,
-            stdin=changelog,
-            stdout=subprocess.PIPE,
-            stderr=sys.stderr,
-            cwd=os.getcwd()
-            )
-    ret = grep_dctrl.wait()
-    if ret:
-        message = '{cmd} failed with return code {code}'.format(
-            cmd = ' '.join(cmd),
-            code = ret,
-            )
-        logger.error(message)
-        raise Exception(message)
-        exit_error()
-    else:
-        pkg_name = grep_dctrl.stdout.readline().strip()
-        version = grep_dctrl.stdout.readline().strip()
-        distribution = grep_dctrl.stdout.readline().strip()
-        logger.info(
-            'Changelog: Package {name} with version {version} in distribution {dist}'.format(
-                name = pkg_name,
-                version = version,
-                dist = distribution,
-                ))
-
-    section_error=False
-    for line in fileinput.input('debian/control'):
-        if line.lower().startswith('section: unknown'):
-            logger.error('debian/control sets "section" to unknown. This is not allowed, failing...')
-            section_error=True
-    if section_error:
-        raise Exception('debian/control sets "section" to unknown. This is not allowed, failing...')
-        exit_error()
-
-    # enforce correct distribution in debian/changelog for master and hotfix branches
-    if (ENV['GIT_BRANCH_NAME'] == 'master' or ENV['GIT_BRANCH_NAME'].startswith('hotfix/')) and distribution not in STABLE_DISTRIBUTIONS:
-        message = 'Distribution %s in debian/changelog not listed in %s' %(
-            distribution,
-            STABLE_DISTRIBUTIONS,
-            )
-        logger.error(message)
-        raise Exception(message)
-        exit_error()
-
-    # get the current commit id
-    current_commit = git_helper.git_get_commit_id()
-
-    if ENV['GIT_BRANCH_NAME'] == 'develop' or ENV['GIT_BRANCH_NAME'] == 'pre-staging' or ENV['GIT_BRANCH_NAME'].startswith('feature/') or ENV['GIT_BRANCH_NAME'].startswith('poc/') or ENV['GIT_BRANCH_NAME'].startswith('bugfix/') or ENV['GIT_BRANCH_NAME'].startswith('release/'):
-        daily_date = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
-        if ENV['GIT_BRANCH_NAME'].startswith('release/'):
-            changelog_distro = 'staging'
-            # use shorter date because we can
-            daily_date = datetime.datetime.now().strftime('%Y%m%d')
-            version = '%s~rc%s+%s+%s' %(version, daily_date, ENV['BUILD_NUMBER'], current_commit[0:7])
-        elif ENV['GIT_BRANCH_NAME'].startswith('feature/') or ENV['GIT_BRANCH_NAME'].startswith('poc/') or ENV['GIT_BRANCH_NAME'].startswith('bugfix/'):
-            changelog_distro ='dev-'+ ENV['GIT_BRANCH_NAME'].replace("/","-")
-            version = '%s~experimental%s+%s+%s' %(version, daily_date, ENV['BUILD_NUMBER'], current_commit[0:7])
-        else:
-            #FIXME: enable this once Florian acks.
-            #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
-            #    if ENV['GIT_BRANCH_NAME'] == 'pre-staging':
-            #        version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
-            #        changelog_distro = 'pre-staging'
-            #    else:
-            #        # use shorter date because we can
-            #        daily_date = datetime.datetime.now().strftime('%Y%m%d')
-            #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
-            #        changelog_distro = 'unstable'
-            #else:
-            version = '%s~develop%s+%s+%s' %(version, daily_date, ENV['BUILD_NUMBER'], current_commit[0:7])
-            changelog_distro = 'pre-staging'
-
-        new_log = 'Generated by jenkins build of %s' % current_commit
-
         cmd = [
-            '/usr/bin/dch',
+            BIN_DCH,
             '--newversion',
-            '%s' %(version),
+            '%s' %(new_version),
             '--force-bad-version',
             '--distribution',
-            '%s' %(changelog_distro),
+            '%s' %(new_dist),
             '--force-distribution',
             '--preserve',
             '--no-auto-nmu',
             '--',
-            '%s' %(''.join(new_log)),
+            'Generated by Jenkins build of commit {commit}'.format(
+                commit = curr_commit
+                ),
             ]
 
-        logger.debug('Trying to call: %s' %(' '.join(cmd)))
-
+        logger.debug('Executing "%s" ...' %(' '.join(cmd)))
         dch = subprocess.Popen(
             cmd,
             shell=False,
@@ -305,22 +319,15 @@ if __name__ == '__main__':
         dch.stdin.write('\n')
         ret = dch.wait()
 
+        # we need to commit here else git-buildpackage will use the existing debian/changelog...
+        # TODO: Later we should investigate why "--ignore-new" does not work!
+        gitrepo.git.add('-A')
+        gitrepo.git.commit('-a', '-m', 'add new changelog entry')
+
         if ret:
             raise Exception(
-                    '"%s" returned with exitcode: %s' %(' '.join(cmd), ret)
-            )
-    else:
-        line_counter = 0
-        for line in fileinput.input('debian/changelog', inplace=1):
-          line_counter += 1
-          if line_counter == 3:
-              print '  * Generated by jenkins build of %s' % git_helper.git_get_commit_id()
-          print line.rstrip('\n')
-
-    # we need to commit here else git-buildpackage will use the existing debian/changelog...
-    # TODO: Later we should investigate why "--ignore-new" does not work!
-    gitrepo.git.add('-A')
-    gitrepo.git.commit('-a', '-m', 'add new changelog entry')
+                '"%s" returned with exitcode: %s' %(' '.join(cmd), ret))
+
 
     # let me see the first two changelog entries:
     line_counter = 0
@@ -330,79 +337,53 @@ if __name__ == '__main__':
         if line_counter <= 2:
             print('debian/changelog: %s' %(line.rstrip('\n')))
 
-    # fail early if we already found the tag we would create upon a successfull build,
-    # except the already existing tag uses exactly the same commit as we are triggered with
-    if ENV['GIT_BRANCH_NAME'] == 'master' or ENV['GIT_BRANCH_NAME'].startswith('hotfix/'):
-        create_tag = True
-        logger.debug('version: %s' %(version))
-        # replace valid debian version chars that are invalid for git tagging
-        version_tag = version.replace('~','_')
-        version_tag = version_tag.replace(':',',')
-        logger.debug('version_tag: %s' %(version_tag))
-        
-        remote_tag = [tag for tag in gitrepo.tags if tag.name == version_tag]
-        if len(remote_tag) > 0: 
-            if remote_tag[0].commit.id == ENV['GIT_COMMIT']:
-                logger.info('Tag was already created for this commit.')
-                create_tag = False
-            else:
-                logger.error('Tag was already created for another commit.')
-                exit_error()
-
-    # set pb_suite which GitBuildPackage() will turn into PB_SUITE
-    # if we wrote a changelog entry, use that one
-    if ENV['GIT_BRANCH_NAME'].startswith('feature/') or ENV['GIT_BRANCH_NAME'].startswith('poc/') or ENV['GIT_BRANCH_NAME'].startswith('bugfix/') or ENV['GIT_BRANCH_NAME'] == 'develop' or ENV['GIT_BRANCH_NAME'] == 'pre-staging' or ENV['GIT_BRANCH_NAME'].startswith('release/'):
-        pb_suite=changelog_distro
-    elif ENV['GIT_BRANCH_NAME'].startswith('hotfix/') or ENV['GIT_BRANCH_NAME'] == 'master':
-        # just take suite from changelog for these branches
-        pb_suite='production-proposed-updates'
-    else:
-         raise Exception('unhandled branch, failing.')
-
-
-    logger.info('dist: %s' %(pb_suite))
-    figlet('dist: %s' %(pb_suite))
-    logger.info('version: %s' %(version))
-    figlet('version: %s' %(version))
 
+    # ACT IV: preparations are set, let's build
     gbp = git_buildpackage.GitBuildPackage(
-            upstream_branch=ENV['GIT_BRANCH'],
-            debian_branch=ENV['GIT_BRANCH'],
-            dist='squeeze',
-            arch='amd64',
-            pb_suite=pb_suite,
-            git_commit_id=current_commit[0:7]
-    )
-
-    logger.info('used to start git-buildpackage here...')
+        upstream_branch = ENV['GIT_BRANCH'],
+        debian_branch = ENV['GIT_BRANCH'],
+        dist = 'squeeze',
+        arch = 'amd64',
+        pb_suite = pb_suite,
+        git_commit_id = current_commit[0:7]
+        )
+    logger.info('Building ...')
     ret = gbp.build()
-    # remove last commit (the one where we added the changelog entry)
+    # .. remove last commit (the one where we added the changelog entry)
     gitrepo.git.reset('--soft', 'HEAD~1')
-    # now handle gpb result
+
+    # .. now handle the result
     if ret:
         logger.error(
-            'git-buildpackage returned non-zero. exitcode was: %s' % ret
-            )
+            'git-buildpackage returned non-zero. exitcode was: %s' % ret)
         exit_error()
     else:
         logger.debug('git-buildpackage executed successfully')
 
-    # make test results available in jenkins:
-    #
-    # if reports.tgz exists untar it to workspace and delete it.
-    # reports.tgz is generated by /root/.pbuilder/hooks.d/B01-test
-    try:
-        reports_file = os.path.join(
-                ENV['WORKSPACE'],
-                '../build-area/result/reports.tgz',
-                )
-        subprocess.check_call(['/bin/tar', 'xzvf', '-C', ENV['WORKSPACE'], reports_file])
-        subprocess.check_call(['/usr/bin/sudo' , '/bin/rm', reports_file])
-    except:
-        pass
 
-    # build was succesful, now let's tag it
-    if create_tag:
+    # ACT V: post-build actions
+    #
+    # .. make test results available in jenkins:
+    #
+    #    if reports.tgz exists untar it to workspace and delete it.
+    #    reports.tgz is generated by /root/.pbuilder/hooks.d/B01-test
+    if not do_reports:
+        figlet('Skip reports')
+    else:
+        try:
+            reports_file = os.path.join(
+                    ENV['WORKSPACE'],
+                    '../build-area/result/reports.tgz',
+                    )
+            subprocess.check_call(['/bin/tar', 'xzvf', '-C', ENV['WORKSPACE'], reports_file])
+            subprocess.check_call(['/usr/bin/sudo' , '/bin/rm', reports_file])
+        except:
+            pass
+
+    # .. let's tag
+    if not do_tagging:
+        figlet('Skip tagging')
+    else:
         try:
             gitrepo.git.tag(version_tag)
         except Exception as error:
@@ -417,37 +398,48 @@ if __name__ == '__main__':
 
         logger.info('Tagged as "%s".' % version_tag)
 
-    # now upload (at least, try to...)
-    try:
-        dput_obj.configure()
-        # strip epoch
-        if ":" in version:
-            version = version.split(":", 1)[1]
-        changes_file =  os.path.join(ENV['WORKSPACE'], '../build-area/result/', '%s_%s_amd64.changes' % (pkg_name, version))
-        # display changes file
-        fh = open(changes_file, 'r')
-        logger.info('%s' % (fh.read()))
-        fh.close()
-        # upload (if NO_UPLOAD is not set)
-        if ENV['NO_UPLOAD'] not in ('true', 'True'):
+    # .. and upload
+    if not do_upload:
+        figlet('Skip upload')
+    else:
+        try:
+            dput_obj.configure()
+
+            # strip epoch
+            if ":" in version:
+                version = version.split(":", 1)[1]
+
+            # construct path for changes file
+            changes_file =  os.path.join(
+                ENV['WORKSPACE'], 
+                '../build-area/result/', 
+                '{name}_{version}_amd64.changes'.format(
+                    name = new_name,
+                    version = new_version,
+                    )
+                )
+
+            # display changes file
+            fh = open(changes_file, 'r')
+            logger.info('%s' % (fh.read()))
+            fh.close()
+
+            # upload changes file
             dput_obj.upload(changes_file)
-        else:
-            logger.debug('value of NO_UPLOAD: %s' % ENV['NO_UPLOAD'])
-        logger.info('dist: %s' %(pb_suite))
-        figlet('dist: %s' %(pb_suite))
-        logger.info('version: %s' %(version))
-        figlet('version: %s' %(version))
-
-    except Exception, error:
-        figlet('upload failed:')
-        logger.exception(error)
-        exit_error()
 
+        except Exception as error:
+            figlet('upload failed:')
+            logger.exception(error)
+
+
+    # .. define the time of completion
     BUILD_END = datetime.datetime.now()
 
-    # cidb wise, we only care about builds from master, hotfix + develop
-    package_instances=[]
-    if ENV['GIT_BRANCH_NAME'] == 'master' or ENV['GIT_BRANCH_NAME'] == 'develop' or ENV['GIT_BRANCH_NAME'].startswith('hotfix/'):
+    # .. and add all the records to CIDB
+    if not do_cidb:
+        figlet('Skip CIDB')
+    else:
+        package_instances=[]
         try:
             package_instances = add_package_instances(
                 "profitbricks", 
@@ -459,16 +451,21 @@ if __name__ == '__main__':
                 BUILD_END,
                 )
         except Exception as error:
-            figlet('CIDB problem:')
-            logger.error("package instance not added to DB", exc_info=error)
+            figlet('CIDB failed:')
+            logger.error("package instance not added to DB", exc_info=error)
             exit_error()
-        # only trigger liveboots automatically for builds from master+hotfix/* branches
-        if len(package_instances) > 0 and ( ENV['GIT_BRANCH_NAME'] == 'master' or ENV['GIT_BRANCH_NAME'].startswith('hotfix/')):
+
+    # .. finally trigger the next liveboot automatically if we succeed with CIDB
+    if not do_liveboot_request:
+        figlet('Skip Liveboot Request')
+    else:
+        if len(package_instances) > 0:
             try:
                 add_liveboot_request(package_instances)
             except:
                 logger.debug("liveboot request failed")
-    # finally
+
+    # finally, finished!
     logger.info('---------------------------------------------------------------------------------------------------------')
     figlet('Success!!!')
     exit_ok()
index d5c61e9ba69831e6dec2b0bce9c58c38bc12914a..c3999aa204b73202cd199769e203925aa09e041b 100644 (file)
@@ -6,46 +6,41 @@ class Dput(object):
     TODO
     '''
     def __init__(
+            self,
             config   = '', #FIXME: whats the correct default?
             section  = 'profitbricks',
-            contents = {
-                fqdn: 'alexandria.pb.local',
-                method: 'scp',
-                login: 'reprepro',
-                incoming: '/srv/profitbricks-repository/incoming/profitbricks',
-                allow_unsigned_uploads: 1,
-                post_upload_command: 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
-                },
+            contents = {},
             ):
         self.config = config
         self.section = section
         self.contents = contents
 
     @property
-    def config():
+    def config(self):
         return self._config
 
     @config.setter
-    def config(value):
+    def config(self,value):
         self._config = value
 
     @property
-    def section():
+    def section(self):
         return self._section
 
     @section.setter
-    def section(value):
+    def section(self,value):
         self._section = value
 
     @property
-    def contents():
+    def contents(self):
         return self._contents
 
     @contents.setter
-    def contents(value):
+    def contents(self,value):
         self._contents = value
 
     def configure(
+            self,
             config = self.config,
             section = self.section,
             contents = self.contents,
@@ -69,6 +64,7 @@ class Dput(object):
         return False
 
     def upload(
+            self,
             config = self.config,
             files = [],
             ):