[PATCH 1/1][pykickstart] Update raid --device to be an array name specifier.

David Lehman dlehman at redhat.com
Wed Jun 12 17:26:22 UTC 2013


Md array names are no longer based on minor since it is impossible to
predict what minor mdadm will use when auto-assembling an array with
no mdadm.conf in place. Now the user can specify an array name for
arrays that support names or a filesystem label, filesystem uuid, or
md array uuid, eg: --device=UUID=adfsadfasdfs.

Related: rhbz#965299
---
 pykickstart/commands/raid.py    | 23 +++++++++++++++++++----
 pykickstart/handlers/control.py |  4 ++--
 tests/commands/raid.py          | 15 +++++++++++++--
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/pykickstart/commands/raid.py b/pykickstart/commands/raid.py
index d99f992..5406e3d 100644
--- a/pykickstart/commands/raid.py
+++ b/pykickstart/commands/raid.py
@@ -284,6 +284,13 @@ class FC3_Raid(KickstartCommand):
                       default=False)
         return op
 
+    def _getDevice(self, s):
+        """ Convert the argument to --device= to its internal format. """
+        # --device can't just take an int in the callback above, because it
+        # could be specificed as "mdX", which causes optparse to error when
+        # it runs int().
+        return int(s)
+
     def parse(self, args):
         (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
 
@@ -299,10 +306,11 @@ class FC3_Raid(KickstartCommand):
         self._setToObj(self.op, opts, rd)
         rd.lineno = self.lineno
 
-        # --device can't just take an int in the callback above, because it
-        # could be specificed as "mdX", which causes optparse to error when
-        # it runs int().
-        rd.device = int(rd.device)
+        # In older pykickstart --device was always specifying a minor, so
+        # rd.device had to be an integer.
+        # In newer pykickstart it has to be the array name since the minor
+        # cannot be reliably predicted due to lack of mdadm.conf during boot.
+        rd.device = self._getDevice(rd.device)
         rd.mountpoint = extra[0]
 
         if len(extra) > 1:
@@ -315,6 +323,9 @@ class FC3_Raid(KickstartCommand):
         if not rd.preexist and not rd.level:
             raise KickstartValueError, formatErrorMsg(self.lineno, msg="RAID Partition defined without RAID level")
 
+        if rd.preexist and rd.device == "":
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg="Device required for preexisting RAID device")
+
         return rd
 
     def dataList(self):
@@ -429,3 +440,7 @@ class F18_Raid(F15_Raid):
         op = F15_Raid._getParser(self)
         op.add_option("--cipher")
         return op
+
+class F19_Raid(F18_Raid):
+    def _getDevice(self, s):
+        return s
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index a88045b..a663f08 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -800,7 +800,7 @@ commandMap = {
         "part": partition.F14_Partition,
         "partition": partition.F14_Partition,
         "poweroff": reboot.FC6_Reboot,
-        "raid": raid.F15_Raid,
+        "raid": raid.F19_Raid,
         "reboot": reboot.FC6_Reboot,
         "repo": repo.F15_Repo,
         "rescue": rescue.F10_Rescue,
@@ -982,7 +982,7 @@ commandMap = {
         "part": partition.F18_Partition,
         "partition": partition.F18_Partition,
         "poweroff": reboot.F18_Reboot,
-        "raid": raid.F18_Raid,
+        "raid": raid.F19_Raid,
         "realm": realm.F19_Realm,
         "reboot": reboot.F18_Reboot,
         "repo": repo.F15_Repo,
diff --git a/tests/commands/raid.py b/tests/commands/raid.py
index bc63632..9e996ce 100644
--- a/tests/commands/raid.py
+++ b/tests/commands/raid.py
@@ -30,6 +30,7 @@ class FC3_TestCase(CommandTest):
     def __init__(self, *kargs, **kwargs):
         CommandTest.__init__(self, *kargs, **kwargs)
         self.validLevels = ["RAID0", "RAID1", "RAID5", "RAID6"]
+        self.minorBasedDevice = True
 
     def runTest(self):
         if "--bytes-per-inode" in self.optionList:
@@ -88,8 +89,13 @@ class FC3_TestCase(CommandTest):
         # Both raid members and useexisting given
         self.assert_parse_error("raid / --level=0 --device=md0 --useexisting raid.01 raid.02", KickstartValueError)
 
-        # Invalid device string - device=asdf0
-        self.assert_parse_error("raid / --device=asdf0 --level=RAID1 raid.01 raid.02 raid.03", ValueError)
+        if self.minorBasedDevice:
+            # Invalid device string - device=asdf0 (--device=(md)?<minor>)
+            self.assert_parse_error("raid / --device=asdf0 --level=RAID1 raid.01 raid.02 raid.03", ValueError)
+        else:
+            # --device=<name>
+            self.assert_parse("raid / --device=root --level=RAID1 raid.01 raid.02 raid.03",
+                              "raid / --device=root --level=RAID1 raid.01 raid.02 raid.03\n")
 
 class FC4_TestCase(FC3_TestCase):
     def runTest(self):
@@ -218,5 +224,10 @@ class F18_TestCase(F15_TestCase):
 
         self.assert_parse_error("raid / --cipher --device=md0 --level=1 raid.01 raid.02")
 
+class F19_TestCase(F18_TestCase):
+    def __init__(self, *kargs, **kwargs):
+        F18_TestCase.__init__(self, *kargs, **kwargs)
+        self.minorBasedDevice = False
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.8.1.4



More information about the anaconda-patches mailing list