From b6e2257e3cd2ff567436c84bf64fdd9983f1581e Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Apr 27 2017 22:30:59 +0000 Subject: fix namespace, add error checking The containers namespace in distgit and pkgdb have changed from docker to container in order to highlight that we are targeting all OCI compliant container runtimes and not just one specific one. This patch handles the migration. This patch also adds further error checking to flr-koji for container rebuilds in order to gracefully handle various failure scenarios. Signed-off-by: Adam Miller --- diff --git a/flr/koji.py b/flr/koji.py index 663c35d..a77fc16 100644 --- a/flr/koji.py +++ b/flr/koji.py @@ -162,7 +162,6 @@ def rebuild(build_type, branch, anames, user=None, stage=False): fedpkg_prefix = ["fedpkg", user_opt[0], user_opt[1]] koji_prefix = ["koji", user_opt[0], user_opt[1]] - if build_type in ['rpm', 'rpms']: flr.log.error( "Not yet implemented, utility only supports containers at this time" @@ -172,8 +171,7 @@ def rebuild(build_type, branch, anames, user=None, stage=False): # Currently the container namespace in DistGit is called "docker" # but there's plans to change that in the future. - cntr_ns = 'docker' - + cntr_ns = 'container' work_dir = tempfile.mkdtemp() @@ -195,19 +193,24 @@ def rebuild(build_type, branch, anames, user=None, stage=False): for aname in anames: # Clone the DistGit repo - cmd = fedpkg_prefix + [ 'clone', '{}/{}'.format(cntr_ns, aname)] + cmd = fedpkg_prefix + ['clone', '{}/{}'.format(cntr_ns, aname)] # Execute the koji command - flr.util.subproc_call( + if not flr.util.subproc_call( cmd, - log_msg="Cloning {}/{} distgit repo".format(cntr_ns, aname) - ) + log_msg="Cloning {}/{} distgit repo".format(cntr_ns, aname), + ignore_failure=True + ): + flr.log.error( + "Failed to clone {}/{}".format(cntr_ns, aname) + ) + continue # Change dirs into the DistGit repo flr.log.info("Changing dirs into {}/{}".format(work_dir, aname)) os.chdir(os.path.join(work_dir, aname)) # Switch branch to requested DistGit branch to operate on - cmd = fedpkg_prefix + [ 'switch-branch', branch ] + cmd = fedpkg_prefix + ['switch-branch', branch] flr.util.subproc_call( cmd, log_msg="Switching branch to {}".format(branch) @@ -222,13 +225,29 @@ def rebuild(build_type, branch, anames, user=None, stage=False): # Bump the RELEASE ENV var for the rebuild flr.log.info("Bumping RELEASE in Dockerfile") - dfp_release = dfp.envs['RELEASE'] - # This is a weird hack, but it works and takes into account that we - # don't want 0.9 + 0.1 to "wrap" to 1.0 - dfp_relsplit = dfp_release.split('.') - dfp_newrel = dfp_relsplit[:-1] - dfp_newrel.append(str(int(dfp_relsplit[-1]) + 1)) - dfp.envs['RELEASE'] = u'{}'.format('.'.join(dfp_newrel)) + + # Need to support both old and new style + if dfp.envs.has_key('RELEASE'): + release_str = 'RELEASE' + elif dfp.envs.has_key('release'): + release_str = 'release' + else: + release_str = None + + if release_str: + dfp_release = dfp.envs[release_str] + # This is a weird hack, but it works and takes into account + # that we don't want 0.9 + 0.1 to "wrap" to 1.0 + dfp_relsplit = dfp_release.split('.') + dfp_newrel = dfp_relsplit[:-1] + dfp_newrel.append(str(int(dfp_relsplit[-1]) + 1)) + dfp.envs[release_str] = u'{}'.format('.'.join(dfp_newrel)) + else: + flr.log.info("FAILED TO BUMP RELEASE - SKIPPING: {}/{}".format( + cntr_ns, + aname + ) + ) # commit changes cmd = fedpkg_prefix + [ @@ -262,13 +281,10 @@ def rebuild(build_type, branch, anames, user=None, stage=False): os.chdir(work_dir) shutil.rmtree(os.path.join(work_dir, aname)) - # Wait for the koji tasks flr.log.info("Waiting for koji tasks to complete.") cmd = koji_prefix + ['watch-task'] cmd.extend(koji_tasks) flr.util.subproc_call(cmd) - - # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/flr/util.py b/flr/util.py index a43596c..be33c6a 100644 --- a/flr/util.py +++ b/flr/util.py @@ -21,12 +21,13 @@ import sys import flr import subprocess -def subproc_call(cmd, log_msg=None): +def subproc_call(cmd, log_msg=None, ignore_failure=False): """ subprocess.call wrapper with logging and error handling :param cmd: list, command to pass to subprocess.call :param log_msg: str, info level log message + :return: bool, false = command non-zero exit, true = zero exit code """ # Log @@ -36,7 +37,13 @@ def subproc_call(cmd, log_msg=None): # Check return code, raise exception if failure occurs if subprocess.call(cmd): flr.log.error("COMMAND FAILED: {}".format(cmd)) - raise RuntimeError("Command returned non-zero: {}".format(cmd)) + if ignore_failure: + return False + else: + raise RuntimeError("Command returned non-zero: {}".format(cmd)) + + # If we get here, it's been successful + return True def subproc_popen(cmd, log_msg=None): """