[pykickstart][PATCH] Add options for LVM cache specs to the 'logvol' command

Vratislav Podzimek vpodzime at redhat.com
Mon Jun 22 18:29:22 UTC 2015


As the first step towards the LVM cache support we need to teach the parser to
accept the options for specifying cache size, PVs it should used and mode it
should use.

Related: rhbz#1120421
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pykickstart/commands/logvol.py | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/commands/logvol.py       | 13 +++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/pykickstart/commands/logvol.py b/pykickstart/commands/logvol.py
index 4398ce7..b3cbc49 100644
--- a/pykickstart/commands/logvol.py
+++ b/pykickstart/commands/logvol.py
@@ -281,6 +281,9 @@ class RHEL7_LogVolData(F21_LogVolData):
     def __init__(self, *args, **kwargs):
         F21_LogVolData.__init__(self, *args, **kwargs)
         self.mkfsopts = kwargs.get("mkfsoptions", "")
+        self.cache_size = kwargs.get("cache_size", 0)
+        self.cache_mode = kwargs.get("cache_mode", "")
+        self.cache_pvs = kwargs.get("cache_pvs", [])
 
     def _getArgsAsStr(self):
         retval = F21_LogVolData._getArgsAsStr(self)
@@ -288,6 +291,13 @@ class RHEL7_LogVolData(F21_LogVolData):
         if self.mkfsopts:
             retval += " --mkfsoptions=\"%s\"" % self.mkfsopts
 
+        if self.cache_size:
+            retval += " --cachesize=%d" % self.cache_size
+        if self.cache_pvs:
+            retval += " --cachepvs=%s" % ",".join(self.cache_pvs)
+        if self.cache_mode:
+            retval += " --cachemode=%s" % self.cache_mode
+
         return retval
 
 class FC3_LogVol(KickstartCommand):
@@ -534,8 +544,17 @@ class RHEL7_LogVol(F21_LogVol):
     removedAttrs = F21_LogVol.removedAttrs
 
     def _getParser(self):
+        def pvs_cb(option, opt_str, value, parser):
+            for pv in value.split(","):
+                if pv:
+                    parser.values.ensure_value(option.dest, list()).append(pv)
+
         op = F21_LogVol._getParser(self)
         op.add_option("--mkfsoptions", dest="mkfsopts")
+        op.add_option("--cachesize", type="int", dest="cache_size")
+        op.add_option("--cachemode", type="string", action="store", nargs=1, dest="cache_mode")
+        op.add_option("--cachepvs", dest="cache_pvs", action="callback",
+                      callback=pvs_cb, nargs=1, type="string")
 
         return op
 
@@ -545,4 +564,25 @@ class RHEL7_LogVol(F21_LogVol):
         if not retval.format and retval.mkfsopts:
             raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions with --noformat has no effect.")))
 
+        if retval.cache_size or retval.cache_mode or retval.cache_pvs:
+            if retval.preexist:
+                err = formatErrorMsg(self.lineno, msg=_("Adding a cache to an existing logical volume is not supported"))
+                raise KickstartParseError(err)
+
+            if retval.thin_volume:
+                err = formatErrorMsg(self.lineno, msg=_("Thin volumes cannot be cached"))
+                raise KickstartParseError(err)
+
+            if not retval.cache_pvs:
+                err = formatErrorMsg(self.lineno, msg=_("Cache needs to have a list of (fast) PVs specified"))
+                raise KickstartParseError(err)
+
+            if not retval.cache_size:
+                err = formatErrorMsg(self.lineno, msg=_("Cache needs to have size specified"))
+                raise KickstartParseError(err)
+
+            if retval.cache_mode and retval.cache_mode not in ("writeback", "writethrough"):
+                err = formatErrorMsg(self.lineno, msg=_("Invalid cache mode given: %s") % retval.cache_mode)
+                raise KickstartParseError(err)
+
         return retval
diff --git a/tests/commands/logvol.py b/tests/commands/logvol.py
index 507dcce..731efe1 100644
--- a/tests/commands/logvol.py
+++ b/tests/commands/logvol.py
@@ -320,5 +320,18 @@ class RHEL7_TestCase(F21_TestCase):
         self.assert_parse_error("logvol / --size=4096 --name=LVNAME --vgname=VGNAME --mkfsoptions=some,thing --noformat",
                                 KickstartValueError)
 
+        # accept cache specifications
+        self.assert_parse("logvol /home --name=home --vgname=vg --size=500 --cachesize=250 --cachepvs=pv.01,pv.02 --cachemode=writeback")
+        # cache mode is not required
+        self.assert_parse("logvol /home --name=home --vgname=vg --size=500 --cachesize=250 --cachepvs=pv.01,pv.02")
+
+        # both cache size and cache PVs are required
+        self.assert_parse_error("logvol /home --name=home --vgname=vg --size=500 --cachesize=250")
+        self.assert_parse_error("logvol /home --name=home --vgname=vg --size=500 --cachepvs=pv.01,pv.02")
+        self.assert_parse_error("logvol /home --name=home --vgname=vg --size=500 --cachemode=writeback")
+        self.assert_parse_error("logvol /home --name=home --vgname=vg --size=500 --cachesize=250 --cachepvs=pv.01,pv.02 --cachemode=writeback --useexisting")
+        self.assert_parse_error("logvol /home --name=home --vgname=vg --size=500 --cachesize=250 --cachepvs=pv.01,pv.02 --cachemode=writeback --noformat")
+
+
 if __name__ == "__main__":
     unittest.main()
-- 
2.1.0



More information about the anaconda-patches mailing list