summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorMartin Gracik <mgracik@redhat.com>2009-03-09 10:59:19 +0100
committerMartin Gracik <mgracik@redhat.com>2009-03-13 11:11:50 +0100
commite9c01eb4e23874e3294d52eabc5673f82e07999f (patch)
tree93b068de9245c065bc9bab9d170b9501c2045585 /storage
parent09e79bc538c870fc50d227780d04555561050447 (diff)
downloadanaconda-e9c01eb4e23874e3294d52eabc5673f82e07999f.tar.gz
anaconda-e9c01eb4e23874e3294d52eabc5673f82e07999f.tar.xz
anaconda-e9c01eb4e23874e3294d52eabc5673f82e07999f.zip
Added test case for devicelib mdraid.py.
Rewrote the devicelibs unittest baseclass so we can create and remove another loop devices within the tests. Rewrote the isRaidXY(raidlevel) functions in mdraid.py into one function isRaid(XY, raidlevel). Rewrote the get_raid_min_members and get_raid_max_spares functions to use the new isRaid function, and not use many if-elif-else statements. Changed the minimum raid members for raid10 to 2.
Diffstat (limited to 'storage')
-rw-r--r--storage/devicelibs/mdraid.py78
1 files changed, 40 insertions, 38 deletions
diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py
index a0d2f6ae3..a1a40d2e1 100644
--- a/storage/devicelibs/mdraid.py
+++ b/storage/devicelibs/mdraid.py
@@ -28,6 +28,13 @@ from ..errors import *
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
+# raidlevels constants
+RAID10 = 10
+RAID6 = 6
+RAID5 = 5
+RAID1 = 1
+RAID0 = 0
+
def getRaidLevels():
avail = []
try:
@@ -52,51 +59,46 @@ def getRaidLevels():
raid_levels = getRaidLevels()
-# FIXME: these functions should be consolidated into one function
-def isRaid10(raidlevel):
- """Return whether raidlevel is a valid descriptor of RAID10."""
- return raidlevel in ("RAID10", "10", 10)
-
-def isRaid6(raidlevel):
- """Return whether raidlevel is a valid descriptor of RAID6."""
- return raidlevel in ("RAID6", "6", 6)
-
-def isRaid5(raidlevel):
- """Return whether raidlevel is a valid descriptor of RAID5."""
- return raidlevel in ("RAID5", "5", 5)
+def isRaid(raid, raidlevel):
+ """Return whether raidlevel is a valid descriptor of raid"""
+ raid_descriptors = {RAID10: ("RAID10", "10", 10),
+ RAID6: ("RAID6", "6", 6),
+ RAID5: ("RAID5", "5", 5),
+ RAID1: ("mirror", "RAID1", "1", 1),
+ RAID0: ("stripe", "RAID0", "0", 0)}
-def isRaid1(raidlevel):
- """Return whether raidlevel is a valid descriptor of RAID1."""
- return raidlevel in ("mirror", "RAID1", "1", 1)
-
-def isRaid0(raidlevel):
- """Return whether raidlevel is a valid descriptor of RAID0."""
- return raidlevel in ("stripe", "RAID0", "0", 0)
+ if raid in raid_descriptors:
+ return raidlevel in raid_descriptors[raid]
+ else:
+ raise ValueError, "invalid raid level %d" % raid
def get_raid_min_members(raidlevel):
"""Return the minimum number of raid members required for raid level"""
- if isRaid0(raidlevel):
- return 2
- elif isRaid1(raidlevel):
- return 2
- elif isRaid5(raidlevel):
- return 3
- elif isRaid6(raidlevel):
- return 4
- elif isRaid10(raidlevel):
- return 4
- else:
- raise ValueError, "invalid raidlevel in get_raid_min_members"
+ raid_min_members = {RAID10: 2,
+ RAID6: 4,
+ RAID5: 3,
+ RAID1: 2,
+ RAID0: 2}
+
+ for raid, min_members in raid_min_members.items():
+ if isRaid(raid, raidlevel):
+ return min_members
+
+ raise ValueError, "invalid raid level %d" % raidlevel
def get_raid_max_spares(raidlevel, nummembers):
"""Return the maximum number of raid spares for raidlevel."""
- if isRaid0(raidlevel):
- return 0
- elif isRaid1(raidlevel) or isRaid5(raidlevel) or \
- isRaid6(raidlevel) or isRaid10(raidlevel):
- return max(0, nummembers - get_raid_min_members(raidlevel))
- else:
- raise ValueError, "invalid raidlevel in get_raid_max_spares"
+ raid_max_spares = {RAID10: lambda: max(0, nummembers - get_raid_min_members(RAID10)),
+ RAID6: lambda: max(0, nummembers - get_raid_min_members(RAID6)),
+ RAID5: lambda: max(0, nummembers - get_raid_min_members(RAID5)),
+ RAID1: lambda: max(0, nummembers - get_raid_min_members(RAID1)),
+ RAID0: lambda: 0}
+
+ for raid, max_spares_func in raid_max_spares.items():
+ if isRaid(raid, raidlevel):
+ return max_spares_func()
+
+ raise ValueError, "invalid raid level %d" % raidlevel
def mdcreate(device, level, disks, spares=0):
argv = ["--create", device, "--level", str(level)]