Re: [PATCH] Try to include error messages in lvm/mdadm exceptions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ack, I like (although what if one of these commands gives
a multi line error message?)

Maybe we should put this in F-12 too ?

Regards,

Hans


On 10/01/2009 04:11 PM, David Lehman wrote:
This should reduce the dogpiling in bugzilla for overly-generic
errors like "lvcreate failed for VolGroup/lv_root".
---
  storage/devicelibs/lvm.py    |  153 ++++++++++++++++++-----------------------
  storage/devicelibs/mdraid.py |   85 +++++++++++------------
  2 files changed, 107 insertions(+), 131 deletions(-)

diff --git a/storage/devicelibs/lvm.py b/storage/devicelibs/lvm.py
index 5fa9198..1f7e1c7 100644
--- a/storage/devicelibs/lvm.py
+++ b/storage/devicelibs/lvm.py
@@ -157,17 +157,30 @@ def clampSize(size, pesize, roundup=None):

      return long(round(float(size)/float(pesize)) * pesize)

+def lvm(args):
+    rc = iutil.execWithRedirect("lvm", args,
+                                stdout = "/dev/tty5",
+                                stderr = "/dev/tty5",
+                                searchPath=1)
+    if not rc:
+        return
+
+    try:
+        msg = open("/tmp/program.log").readlines()[-1].strip()
+    except Exception:
+        msg = ""
+
+    raise LVMError(msg)
+
  def pvcreate(device):
      args = ["pvcreate"] + \
              config_args + \
              [device]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-    if rc:
-        raise LVMError("pvcreate failed for %s" % device)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("pvcreate failed for %s: %s" % (device, msg))

  def pvresize(device, size):
      args = ["pvresize"] + \
@@ -175,24 +188,20 @@ def pvresize(device, size):
              config_args + \
              [device]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-    if rc:
-        raise LVMError("pvresize failed for %s" % device)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("pvresize failed for %s: %s" % (device, msg))

  def pvremove(device):
      args = ["pvremove"] + \
              config_args + \
              [device]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-    if rc:
-        raise LVMError("pvremove failed for %s" % device)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("pvremove failed for %s: %s" % (device, msg))

  def pvinfo(device):
      """
@@ -237,51 +246,40 @@ def vgcreate(vg_name, pv_list, pe_size):
      argv.append(vg_name)
      argv.extend(pv_list)

-    rc = iutil.execWithRedirect("lvm", argv,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("vgcreate failed for %s" % vg_name)
+    try:
+        lvm(argv)
+    except LVMError as msg:
+        raise LVMError("vgcreate failed for %s: %s" % (vg_name, msg))

  def vgremove(vg_name):
      args = ["vgremove"] + \
              config_args +\
              [vg_name]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("vgremove failed for %s" % vg_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("vgremove failed for %s: %s" % (vg_name, msg))

  def vgactivate(vg_name):
      args = ["vgchange", "-a", "y"] + \
              config_args + \
              [vg_name]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-    if rc:
-        raise LVMError("vgactivate failed for %s" % vg_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("vgactivate failed for %s: %s" % (vg_name, msg))

  def vgdeactivate(vg_name):
      args = ["vgchange", "-a", "n"] + \
              config_args + \
              [vg_name]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("vgdeactivate failed for %s" % vg_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("vgdeactivate failed for %s: %s" % (vg_name, msg))

  def vgreduce(vg_name, pv_list, rm=False):
      """ Reduce a VG.
@@ -296,13 +294,10 @@ def vgreduce(vg_name, pv_list, rm=False):
      else:
          args.extend([vg_name] + pv_list)

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("vgreduce failed for %s" % vg_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("vgreduce failed for %s: %s" % (vg_name, msg))

  def vginfo(vg_name):
      args = ["vgs", "--noheadings", "--nosuffix"] + \
@@ -372,26 +367,20 @@ def lvcreate(vg_name, lv_name, size):
              config_args + \
              [vg_name]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("lvcreate failed for %s/%s" % (vg_name, lv_name))
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("lvcreate failed for %s/%s: %s" % (vg_name, lv_name, msg))

  def lvremove(vg_name, lv_name):
      args = ["lvremove"] + \
              config_args + \
              ["%s/%s" % (vg_name, lv_name)]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("lvremove failed for %s" % lv_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("lvremove failed for %s: %s" % (lv_name, msg))

  def lvresize(vg_name, lv_name, size):
      args = ["lvresize"] + \
@@ -399,13 +388,10 @@ def lvresize(vg_name, lv_name, size):
              config_args + \
              ["%s/%s" % (vg_name, lv_name)]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("lvresize failed for %s" % lv_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("lvresize failed for %s: %s" % (lv_name, msg))

  def lvactivate(vg_name, lv_name):
      # see if lvchange accepts paths of the form 'mapper/$vg-$lv'
@@ -413,23 +399,18 @@ def lvactivate(vg_name, lv_name):
              config_args + \
              ["%s/%s" % (vg_name, lv_name)]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-    if rc:
-        raise LVMError("lvactivate failed for %s" % lv_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("lvactivate failed for %s: %s" % (lv_name, msg))

  def lvdeactivate(vg_name, lv_name):
      args = ["lvchange", "-a", "n"] + \
              config_args + \
              ["%s/%s" % (vg_name, lv_name)]

-    rc = iutil.execWithRedirect("lvm", args,
-                                stdout = "/dev/tty5",
-                                stderr = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise LVMError("lvdeactivate failed for %s" % lv_name)
+    try:
+        lvm(args)
+    except LVMError as msg:
+        raise LVMError("lvdeactivate failed for %s: %s" % (lv_name, msg))

diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py
index b082c7b..73099c4 100644
--- a/storage/devicelibs/mdraid.py
+++ b/storage/devicelibs/mdraid.py
@@ -119,6 +119,21 @@ def get_raid_max_spares(raidlevel, nummembers):

      raise ValueError, "invalid raid level %d" % raidlevel

+def mdadm(args):
+    rc = iutil.execWithRedirect("mdadm", args,
+                                stdout = "/dev/tty5",
+                                stderr = "/dev/tty5",
+                                searchPath=1)
+    if not rc:
+        return
+
+    try:
+        msg = open("/tmp/program.log").readlines()[-1].strip()
+    except Exception:
+        msg = ""
+
+    raise MDRaidError(msg)
+
  def mdcreate(device, level, disks, spares=0):
      argv = ["--create", device, "--run", "--level=%s" % level]
      raid_devs = len(disks) - spares
@@ -127,27 +142,18 @@ def mdcreate(device, level, disks, spares=0):
          argv.append("--spare-devices=%d" % spares)
      argv.extend(disks)

-    rc = iutil.execWithRedirect("mdadm",
-                                argv,
-                                stderr = "/dev/tty5",
-                                stdout = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise MDRaidError("mdcreate failed for %s" % device)
-
-    # mdadm insists on starting the new array, so we have to stop it here
-    #self.mddeactivate(device)
+    try:
+        mdadm(argv)
+    except MDRaidError as msg:
+        raise MDRaidError("mdcreate failed for %s: %s" % (device, msg))

  def mddestroy(device):
-    rc = iutil.execWithRedirect("mdadm",
-                                ["--zero-superblock", device],
-                                stderr = "/dev/tty5",
-                                stdout = "/dev/tty5",
-                                searchPath=1)
+    args = ["--zero-superblock", device]

-    if rc:
-        raise MDRaidError("mddestroy failed for %s" % device)
+    try:
+        mdadm(args)
+    except MDRaidError as msg:
+        raise MDRaidError("mddestroy failed for %s: %s" % (device, msg))

  def mdadd(device, no_degraded=False):
      args = ["--incremental", "--quiet"]
@@ -155,14 +161,10 @@ def mdadd(device, no_degraded=False):
          args.append("--no-degraded")
      args.append(device)

-    rc = iutil.execWithRedirect("mdadm",
-                                args,
-                                stderr = "/dev/tty5",
-                                stdout = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise MDRaidError("mdadd failed for %s" % device)
+    try:
+        mdadm(args)
+    except MDRaidError as msg:
+        raise MDRaidError("mdadd failed for %s: %s" % (device, msg))

  def mdactivate(device, members=[], super_minor=None, update_super_minor=False,
                 uuid=None):
@@ -181,29 +183,22 @@ def mdactivate(device, members=[], super_minor=None, update_super_minor=False,
      else:
          extra_args = [ ]

-    rc = iutil.execWithRedirect("mdadm",
-                                ["--assemble",
-                                 device,
-                                 identifier,
-                                 "--run",
-                                 "--auto=md"] + extra_args + members,
-                                stderr = "/dev/tty5",
-                                stdout = "/dev/tty5",
-                                searchPath=1)
-
-    if rc:
-        raise MDRaidError("mdactivate failed for %s" % device)
+    args = ["--assemble", device, identifier, "--run", "--auto=md"]
+    args += extra_args
+    args += members

+    try:
+        mdadm(args)
+    except MDRaidError as msg:
+        raise MDRaidError("mdactivate failed for %s: %s" % (device, msg))

  def mddeactivate(device):
-    rc = iutil.execWithRedirect("mdadm",
-                                ["--stop", device],
-                                stderr = "/dev/tty5",
-                                stdout = "/dev/tty5",
-                                searchPath=1)
+    args = ["--stop", device]

-    if rc:
-        raise MDRaidError("mddeactivate failed for %s" % device)
+    try:
+        mdadm(args)
+    except MDRaidError as msg:
+        raise MDRaidError("mddeactivate failed for %s: %s" % (device, msg))

  def mdexamine(device):
      vars = iutil.execWithCapture("mdadm",

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux