]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
lsb.py: Update for rpm based systems
authorGary Lowell <glowell@inktank.com>
Thu, 7 Mar 2013 23:39:38 +0000 (15:39 -0800)
committerGary Lowell <glowell@inktank.com>
Thu, 7 Mar 2013 23:39:38 +0000 (15:39 -0800)
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 <gary.lowell@inktank.com>
ceph_deploy/lsb.py

index a969681a173ce6f0b7220f198dad78e405c6ffe5..f7e0b210aea1ebaa2cd650b9fd0a9f2d8af53182 100644 (file)
@@ -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):