From: Gary Lowell Date: Thu, 7 Mar 2013 23:39:38 +0000 (-0800) Subject: lsb.py: Update for rpm based systems X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bacd05f50574a3149d5e765be8821f66bd14191b;p=ceph-deploy.git lsb.py: Update for rpm based systems lsb_release returns multiple fields seperated by newlines on some platforms and spaces on others. Get release, version, and codename fields individually instead of using a single request. lsb_release is not installed by default on some system. Check if it's present before calling. This allows a better error message. Signed-off-by: Gary Lowell --- diff --git a/ceph_deploy/lsb.py b/ceph_deploy/lsb.py index a969681..f7e0b21 100644 --- a/ceph_deploy/lsb.py +++ b/ceph_deploy/lsb.py @@ -1,30 +1,53 @@ - def lsb_release(): import subprocess - args = [ - 'lsb_release', - '-s', - '-i', - '-r', - '-c', - ] + args = [ 'which', 'lsb_release', ] + p = subprocess.Popen( + args=args, + stdout=subprocess.PIPE, + ) + distro = p.stdout.read() + ret = p.wait() + if ret != 0: + raise RuntimeError('lsb_release not found on host') + + args = [ 'lsb_release', '-s', '-i' ] + p = subprocess.Popen( + args=args, + stdout=subprocess.PIPE, + ) + distro = p.stdout.read() + ret = p.wait() + if ret != 0: + raise subprocess.CalledProcessError(ret, args, output=out) + if distro == '': + raise RuntimeError('lsb_release gave invalid output for distro') + + args = [ 'lsb_release', '-s', '-r', ] + p = subprocess.Popen( + args=args, + stdout=subprocess.PIPE, + ) + release = p.stdout.read() + ret = p.wait() + if ret != 0: + raise subprocess.CalledProcessError(ret, args, output=out) + if release == '': + raise RuntimeError('lsb_release gave invalid output for release') + + args = [ 'lsb_release', '-s', '-c', ] p = subprocess.Popen( args=args, stdout=subprocess.PIPE, ) - out = p.stdout.read() + codename = p.stdout.read() ret = p.wait() if ret != 0: raise subprocess.CalledProcessError(ret, args, output=out) + if codename == '': + raise RuntimeError('lsb_release gave invalid output for codename') - try: - (distro, release, codename, empty) = out.split('\n', 3) - except ValueError: - raise RuntimeError('lsb_release gave invalid output') - if empty != '': - raise RuntimeError('lsb_release gave invalid output') - return (distro, release, codename) + return (distro.rstrip(), release.rstrip(), codename.rstrip()) def choose_init(distro, codename):