From 2d0cfee9d3893b76acd584a8e264b65e7bf03d0d Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 21 Mar 2013 15:51:48 +0100 Subject: [PATCH] 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 --- ceph_deploy/lsb.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) 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): -- 2.47.3