From 77e052201c1aa258def5fdde5c9b8745b79611f2 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 27 Feb 2009 10:18:46 -0600 Subject: Lots of minor fixes and cleanups. A non-exhaustive list follows. - Change minsize/maxsize to minSize/maxSize since that's the convention elsewhere throughout the code. - Redirect output from all external utilities to tty5, not /dev/null. - Don't waste calls to basename for debug log statements, especially when the device can be None. - Add lots of missing imports. - Fix lots of remnants of previous code usage. --- storage/devicelibs/crypto.py | 30 ++++++++++---------- storage/devicelibs/dm.py | 6 ++-- storage/devicelibs/lvm.py | 65 ++++++++++++++++++++++---------------------- storage/devicelibs/mdraid.py | 26 ++++++++---------- storage/devicelibs/swap.py | 16 ++++++----- 5 files changed, 72 insertions(+), 71 deletions(-) (limited to 'storage/devicelibs') diff --git a/storage/devicelibs/crypto.py b/storage/devicelibs/crypto.py index 0872ed052..d69e7d3ac 100644 --- a/storage/devicelibs/crypto.py +++ b/storage/devicelibs/crypto.py @@ -30,8 +30,8 @@ _ = lambda x: gettext.ldgettext("anaconda", x) def is_luks(device): rc = iutil.execWithRedirect("cryptsetup", ["isLuks", device], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) if rc: return False @@ -41,15 +41,15 @@ def is_luks(device): def luks_uuid(device): uuid = iutil.execWithCapture("cryptsetup", ["luksUUID", device], - stderr="/dev/null") + stderr="/dev/tty5") return uuid.strip() def luks_status(name): """0 means active, 1 means inactive (or non-existent)""" rc = iutil.execWithRedirect("cryptsetup", ["status", name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) return rc @@ -78,8 +78,8 @@ def luks_format(device, rc = iutil.execWithRedirect("cryptsetup", argv, stdin = p[0], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) os.close(p[0]) @@ -100,8 +100,8 @@ def luks_open(device, name, passphrase=None, key_file=None): rc = iutil.execWithRedirect("cryptsetup", argv, stdin = p[0], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) os.close(p[0]) @@ -111,8 +111,8 @@ def luks_open(device, name, passphrase=None, key_file=None): def luks_close(name): rc = iutil.execWithRedirect("cryptsetup", ["luksClose", name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) if rc: @@ -147,8 +147,8 @@ def luks_add_key(device, device, new_key_spec], stdin = p[0], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) os.close(p[0]) @@ -184,8 +184,8 @@ def luks_remove_key(device, device, del_key_spec], stdin = p[0], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath = 1) os.close(p[0]) diff --git a/storage/devicelibs/dm.py b/storage/devicelibs/dm.py index 02c88f614..74d8228de 100644 --- a/storage/devicelibs/dm.py +++ b/storage/devicelibs/dm.py @@ -39,7 +39,7 @@ def name_from_dm_node(dm_node): ["info", "--columns", "--noheadings", "-o", "name", "-j", str(major), "-m", str(minor)], - stderr="/dev/null") + stderr="/dev/tty5") log.debug("name_from_dm(%s) returning '%s'" % (dm_node, name.strip())) return name.strip() @@ -49,7 +49,7 @@ def dm_node_from_name(map_name): "--noheadings", "-o", "devno", map_name], - stderr="/dev/null") + stderr="/dev/tty5") (major, sep, minor) = devnum.strip().partition(":") if not sep: raise DMError("dm device does not exist") @@ -65,7 +65,7 @@ def _get_backing_devnums_from_map(map_name): "--noheadings", "-o", "devnos_used", map_name], - stderr="/dev/null") + stderr="/dev/tty5") dev_nums = buf.split() for dev_num in dev_nums: (major, colon, minor) = dev_num.partition(":") diff --git a/storage/devicelibs/lvm.py b/storage/devicelibs/lvm.py index 14a11577f..cd3970745 100644 --- a/storage/devicelibs/lvm.py +++ b/storage/devicelibs/lvm.py @@ -22,6 +22,7 @@ import os import math +import re import iutil @@ -72,10 +73,10 @@ def getMaxLVSize(pe): else: return (16*1024*1024) #Max is 16TiB -def safeLvmName(str): - tmp = string.strip(str) +def safeLvmName(name): + tmp = name.strip() tmp = tmp.replace("/", "_") - tmp = re.sub("[^0-9a-zA-Z._]", "", str) + tmp = re.sub("[^0-9a-zA-Z._]", "", tmp) tmp = tmp.lstrip("_") return tmp @@ -110,8 +111,8 @@ def clampSize(size, pesize, roundup=None): def pvcreate(device): rc = iutil.execWithRedirect("lvm", ["pvcreate", device], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: raise LVMError("pvcreate failed for %s" % device) @@ -122,8 +123,8 @@ def pvresize(device, size): ["pvresize", "--setphysicalvolumesize", size_arg, device], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: raise LVMError("pvresize failed for %s" % device) @@ -131,8 +132,8 @@ def pvresize(device, size): def pvremove(device): rc = iutil.execWithRedirect("lvm", ["pvremove", device], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: raise LVMError("pvremove failed for %s" % device) @@ -153,7 +154,7 @@ def pvinfo(device): "-o", "pv_name,pv_mda_count,vg_name,vg_uuid", device], - stderr = "/dev/null") + stderr = "/dev/tty5") vals = rc.split() if not vals: raise LVMError("pvinfo failed for %s" % device) @@ -172,8 +173,8 @@ def vgcreate(vg_name, pvs, pe_size): argv.append(pv_list) rc = iutil.execWithRedirect("lvm", argv, - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -181,8 +182,8 @@ def vgcreate(vg_name, pvs, pe_size): def vgremove(vg_name): rc = iutil.execWithRedirect("lvm", ["vgremove", vg_name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -190,16 +191,16 @@ def vgremove(vg_name): def vgactivate(vg_name): rc = iutil.execWithRedirect("lvm", ["vgchange" "-a", "y", vg_name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: raise LVMError("vgactivate failed for %s" % vg_name) def vgdeactivate(vg_name): rc = iutil.execWithRedirect("lvm", ["vgchange", "-a", "n", vg_name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -208,8 +209,8 @@ def vgdeactivate(vg_name): def vgreduce(vg_name, pv_list): pvs = " ".join(pv_list) rc = iutil.execWithRedirect("lvm", ["vgreduce", vg_name, pvs], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -220,7 +221,7 @@ def vginfo(vg_name): ["vgs", "--noheadings", "--nosuffix", "--units", "m", "-o", "uuid,size,free,extent_size,extent_count,free_count,pv_count", vg_name], - stderr="/dev/null") + stderr="/dev/tty5") info = buf.split() if len(info) != 7: raise LVMError(_("vginfo failed for %s" % vg_name)) @@ -235,7 +236,7 @@ def lvs(vg_name): ["lvs", "--noheadings", "--nosuffix", "--units", "m", "-o", "lv_name,lv_uuid,lv_size"], - stderr="/dev/null") + stderr="/dev/tty5") lvs = {} @@ -255,8 +256,8 @@ def lvcreate(vg_name, lv_name, size): "-L", size_arg, "-n", lv_name, vg_name], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -265,8 +266,8 @@ def lvcreate(vg_name, lv_name, size): def lvremove(vg_name, lv_name): lv_path = "%s/%s" % (vg_name, lv_name) rc = iutil.execWithRedirect("lvm", ["lvremove", lv_path], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -279,8 +280,8 @@ def lvresize(vg_name, lv_name, size): ["lvresize", "-L", size_arg, lv_path], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: @@ -290,8 +291,8 @@ def lvactivate(vg_name, lv_name): # see if lvchange accepts paths of the form 'mapper/$vg-$lv' lv_path = "%s/%s" % (vg_name, lv_name) rc = iutil.execWithRedirect("lvm", ["lvchange", "-a", "y", lv_path], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: raise LVMError("lvactivate failed for %s" % lv_path) @@ -299,8 +300,8 @@ def lvactivate(vg_name, lv_name): def lvdeactivate(vg_name, lv_name): lv_path = "%s/%s" % (vg_name, lv_name) rc = iutil.execWithRedirect("lvm", ["lvchange", "-a", "n", lv_path], - stdout = "/dev/null", - stderr = "/dev/null", + stdout = "/dev/tty5", + stderr = "/dev/tty5", searchPath=1) if rc: diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py index 75613d46a..a0d2f6ae3 100644 --- a/storage/devicelibs/mdraid.py +++ b/storage/devicelibs/mdraid.py @@ -108,8 +108,8 @@ def mdcreate(device, level, disks, spares=0): rc = iutil.execWithRedirect("mdadm", argv, - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: @@ -121,23 +121,21 @@ def mdcreate(device, level, disks, spares=0): def mddestroy(device): rc = iutil.execWithRedirect("mdadm", ["--zero-superblock", device], - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: raise MDRaidError("mddestroy failed for %s" % device) def mdadd(device): - # XXX NOTUSED: mdadm -I is broken and dledford says it should be - # avoided if possible, so we used mdadm -A instead rc = iutil.execWithRedirect("mdadm", ["--incremental", "--quiet", - "--auto=yes", + "--auto=md", device], - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: @@ -174,8 +172,8 @@ def mdactivate(device, members=[], super_minor=None, uuid=None): identifier, "--auto=md", "--update=super-minor"], - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if filename and os.access(filename, os.R_OK): @@ -191,8 +189,8 @@ def mdactivate(device, members=[], super_minor=None, uuid=None): def mddeactivate(device): rc = iutil.execWithRedirect("mdadm", ["--stop", device], - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: @@ -207,7 +205,7 @@ def mdexamine(device): # parsed output format. lines = iutil.execWithCapture("mdadm", ["--examine", device], - stderr="/dev/null").splitlines() + stderr="/dev/tty5").splitlines() info = { 'major': "-1", diff --git a/storage/devicelibs/swap.py b/storage/devicelibs/swap.py index b6c9b1ab8..8ee5b5bb3 100644 --- a/storage/devicelibs/swap.py +++ b/storage/devicelibs/swap.py @@ -20,6 +20,8 @@ # Red Hat Author(s): Dave Lehman # +import resource + import iutil from ..errors import * @@ -35,8 +37,8 @@ def mkswap(device, label=''): argv.append(device) rc = iutil.execWithRedirect("mkswap", argv, - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: @@ -68,14 +70,14 @@ def swapon(device, priority=None): raise SuspendError argv = [] - if 0 <= priority <= 32767: + if isinstance(priority, int) and 0 <= priority <= 32767: argv.extend(["-p", priority]) argv.append(device) rc = iutil.execWithRedirect("swapon", argv, - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: @@ -83,8 +85,8 @@ def swapon(device, priority=None): def swapoff(device): rc = iutil.execWithRedirect("swapoff", [device], - stderr = "/dev/null", - stdout = "/dev/null", + stderr = "/dev/tty5", + stdout = "/dev/tty5", searchPath=1) if rc: -- cgit