From: Danny Al-Gaaf Date: Thu, 21 Mar 2013 14:51:48 +0000 (+0100) Subject: lsb.py: fix subprocess handling and raising error X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2d0cfee9d3893b76acd584a8e264b65e7bf03d0d;p=ceph-deploy.git lsb.py: fix subprocess handling and raising error Some fixes for lsb subprocess handling and error raising: - use proper variable naming (p vs process) - use process.communicate() instead of p.stdout.read() - fix subprocess.CalledProcessError() output= Signed-off-by: Danny Al-Gaaf --- diff --git a/ceph_deploy/lsb.py b/ceph_deploy/lsb.py index f7e0b21..1814463 100644 --- a/ceph_deploy/lsb.py +++ b/ceph_deploy/lsb.py @@ -1,53 +1,54 @@ + def lsb_release(): import subprocess args = [ 'which', 'lsb_release', ] - p = subprocess.Popen( + process = subprocess.Popen( args=args, stdout=subprocess.PIPE, ) - distro = p.stdout.read() - ret = p.wait() + distro, _ = process.communicate() + ret = process.wait() if ret != 0: raise RuntimeError('lsb_release not found on host') args = [ 'lsb_release', '-s', '-i' ] - p = subprocess.Popen( + process = subprocess.Popen( args=args, stdout=subprocess.PIPE, ) - distro = p.stdout.read() - ret = p.wait() + distro, _ = process.communicate() + ret = process.wait() if ret != 0: - raise subprocess.CalledProcessError(ret, args, output=out) + raise subprocess.CalledProcessError(ret, args, output=distro) if distro == '': raise RuntimeError('lsb_release gave invalid output for distro') args = [ 'lsb_release', '-s', '-r', ] - p = subprocess.Popen( + process = subprocess.Popen( args=args, stdout=subprocess.PIPE, ) - release = p.stdout.read() - ret = p.wait() + release, _ = process.communicate() + ret = process.wait() if ret != 0: - raise subprocess.CalledProcessError(ret, args, output=out) + raise subprocess.CalledProcessError(ret, args, output=release) if release == '': raise RuntimeError('lsb_release gave invalid output for release') args = [ 'lsb_release', '-s', '-c', ] - p = subprocess.Popen( + process = subprocess.Popen( args=args, stdout=subprocess.PIPE, ) - codename = p.stdout.read() - ret = p.wait() + codename, _ = process.communicate() + ret = process.wait() if ret != 0: - raise subprocess.CalledProcessError(ret, args, output=out) + raise subprocess.CalledProcessError(ret, args, output=codename) if codename == '': raise RuntimeError('lsb_release gave invalid output for codename') - return (distro.rstrip(), release.rstrip(), codename.rstrip()) + return (str(distro).rstrip(), str(release).rstrip(), str(codename).rstrip()) def choose_init(distro, codename):