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

[PATCH] Add support for reserved space in volume group.



reserved-space is an amount to reserve in MB
reserved-percent is a percentage of total vg space to reserve

This is a combination of three commits from master:

    2bf694471fec6bbd9eaaae9ee2d1ad73b69f4881
    30596fb8bddc1aa722b0fa30fb930a4b04ed6f75
    d19f9b1a313c0c4241b7f52fadef210032fafcb5

Resolves: rhbz#790457
---
 pykickstart/commands/volgroup.py |   58 ++++++++++++++++++++++++++++++++++---
 pykickstart/handlers/control.py  |    4 +-
 tests/commands/volgroup.py       |   58 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 7 deletions(-)
 create mode 100644 tests/commands/volgroup.py

diff --git a/pykickstart/commands/volgroup.py b/pykickstart/commands/volgroup.py
index 929052e..b295de2 100644
--- a/pykickstart/commands/volgroup.py
+++ b/pykickstart/commands/volgroup.py
@@ -18,6 +18,7 @@
 # with the express permission of Red Hat, Inc. 
 #
 from pykickstart.base import *
+from pykickstart.errors import *
 from pykickstart.options import *
 
 import gettext
@@ -40,10 +41,8 @@ class FC3_VolGroupData(BaseData):
     def __eq__(self, y):
         return self.vgname == y.vgname
 
-    def __str__(self):
-        retval = BaseData.__str__(self)
-        retval += "volgroup %s" % self.vgname
-
+    def _getArgsAsStr(self):
+        retval = ""
         if not self.format:
             retval += " --noformat"
         if self.pesize != 0:
@@ -51,7 +50,28 @@ class FC3_VolGroupData(BaseData):
         if self.preexist:
             retval += " --useexisting"
 
-        return retval + " " + string.join(self.physvols, " ") + "\n"
+        return retval
+
+    def __str__(self):
+        retval = BaseData.__str__(self)
+        retval += "volgroup %s" % self.vgname
+        retval += self._getArgsAsStr()
+        return retval + " " + " ".join(self.physvols) + "\n"
+
+class FC16_VolGroupData(FC3_VolGroupData):
+    def __init__(self, *args, **kwargs):
+        FC3_VolGroupData.__init__(self, *args, **kwargs)
+        self.reserved_space = kwargs.get("reserved-space", 0)
+        self.reserved_percent = kwargs.get("reserved-percent", 0)
+
+    def _getArgsAsStr(self):
+        retval = FC3_VolGroupData._getArgsAsStr(self)
+        if self.reserved_space > 0:
+            retval += " --reserved-space=%d" % self.reserved_space
+        if self.reserved_percent > 0:
+            retval += " --reserved-percent=%d" % self.reserved_percent
+
+        return retval
 
 class FC3_VolGroup(KickstartCommand):
     removedKeywords = KickstartCommand.removedKeywords
@@ -90,6 +110,13 @@ class FC3_VolGroup(KickstartCommand):
         vg = self.handler.VolGroupData()
         self._setToObj(self.op, opts, vg)
         vg.lineno = self.lineno
+
+        if len(extra) == 0:
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=_("volgroup must be given a VG name"))
+
+        if len(extra) == 1:
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=_("volgroup must be given a list of partitions"))
+
         vg.vgname = extra[0]
         vg.physvols = extra[1:]
 
@@ -101,3 +128,24 @@ class FC3_VolGroup(KickstartCommand):
 
     def dataList(self):
         return self.vgList
+
+class FC16_VolGroup(FC3_VolGroup):
+    def _getParser(self):
+        def space_cb(option, opt_str, value, parser):
+            if value < 0:
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg="Volume group reserved space must be a positive integer."))
+
+            parser.values.reserved_space = value
+
+        def percent_cb(option, opt_str, value, parser):
+            if not 0 < value < 100:
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg="Volume group reserved space percentage must be between 1 and 99."))
+
+            parser.values.reserved_percent = value
+
+        op = FC3_VolGroup._getParser(self)
+        op.add_option("--reserved-space", action="callback", callback=space_cb,
+                      dest="reserved_space", type="int", nargs=1, default=0)
+        op.add_option("--reserved-percent", action="callback", callback=percent_cb,
+                      dest="reserved_percent", type="int", nargs=1, default=0)
+        return op
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index e89d10c..100bf67 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -865,7 +865,7 @@ commandMap = {
         "url": method.RHEL6_Method,
         "user": user.F12_User,
         "vnc": vnc.F9_Vnc,
-        "volgroup": volgroup.FC3_VolGroup,
+        "volgroup": volgroup.FC16_VolGroup,
         "xconfig": xconfig.F10_XConfig,
         "zerombr": zerombr.F9_ZeroMbr,
         "zfcp": zfcp.F12_ZFCP,
@@ -1076,7 +1076,7 @@ dataMap = {
         "RepoData": repo.RHEL6_RepoData,
         "SshPwData": sshpw.F13_SshPwData,
         "UserData": user.F12_UserData,
-        "VolGroupData": volgroup.FC3_VolGroupData,
+        "VolGroupData": volgroup.FC16_VolGroupData,
         "ZFCPData": zfcp.F12_ZFCPData,
     }
 }
diff --git a/tests/commands/volgroup.py b/tests/commands/volgroup.py
new file mode 100644
index 0000000..96ad0d4
--- /dev/null
+++ b/tests/commands/volgroup.py
@@ -0,0 +1,58 @@
+import unittest, shlex
+from tests.baseclass import *
+
+from pykickstart.base import *
+from pykickstart.errors import *
+from pykickstart.version import *
+from pykickstart.commands.volgroup import *
+
+class FC3_TestCase(CommandTest):
+    command = "volgroup"
+
+    def runTest(self):
+        # --noformat
+        self.assert_parse("volgroup vg.01 pv.01 --noformat",
+                          "volgroup vg.01 --noformat --pesize=32768 --useexisting pv.01\n")
+        # --useexisting
+        self.assert_parse("volgroup vg.01 pv.01 --useexisting",
+                          "volgroup vg.01 --pesize=32768 --useexisting pv.01\n")
+
+        # --pesize
+        self.assert_parse("volgroup vg.01 pv.01 --pesize=70000",
+                          "volgroup vg.01 --pesize=70000 pv.01\n")
+
+        # assert data types
+        self.assert_type("volgroup", "pesize", "int")
+        self.assert_type("volgroup", "format", "boolean")
+        self.assert_type("volgroup", "preexist", "boolean")
+
+        # fail - incorrect type
+        self.assert_parse_error("volgroup vg.01 pv.01 --pesize=SIZE", KickstartParseError)
+
+        # fail - missing name
+        self.assert_parse_error("volgroup", KickstartParseError)
+
+        # fail - missing list of partitions
+        self.assert_parse_error("volgroup vg01", KickstartParseError)
+
+class RHEL6_TestCase(FC3_TestCase):
+    def runTest(self):
+        FC3_TestCase.runTest(self)
+
+        # Pass - correct usage.
+        self.assert_parse("volgroup vg.01 pv.01 --reserved-space=1000",
+                          "volgroup vg.01 --pesize=32768 --reserved-space=1000 pv.01\n")
+        self.assert_parse("volgroup vg.01 pv.01 --reserved-percent=50",
+                          "volgroup vg.01 --pesize=32768 --reserved-percent=50 pv.01\n")
+
+        # Fail - missing required argument.
+        self.assert_parse_error("volgroup vg.01 pv.01 --reserved-space", KickstartParseError)
+        self.assert_parse_error("volgroup vg.01 pv.01 --reserved-percent", KickstartParseError)
+
+        # Fail - incorrect values.
+        self.assert_parse_error("volgroup vg.01 pv.01 --reserved-space=-1", KickstartValueError)
+        self.assert_parse_error("volgroup vg.01 pv.01 --reserved-percent=0", KickstartValueError)
+        self.assert_parse_error("volgroup vg.01 pv.01 --reserved-percent=100", KickstartValueError)
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.7.6


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