[master 9/21] Add availability checking to non-FS formats.

mulkieran installerbot-noreply at redhat.com
Tue May 12 21:35:51 UTC 2015


From: mulhern <amulhern at redhat.com>

Related: #12

Make use of the availability information in method formattable,
controllable, supported, destroyable.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/__init__.py | 16 ++++++++++++++++
 blivet/formats/luks.py     | 18 ++++++++++++++++++
 blivet/formats/lvmpv.py    | 14 ++++++++++++++
 blivet/formats/mdraid.py   | 14 ++++++++++++++
 blivet/formats/swap.py     | 14 ++++++++++++++
 5 files changed, 76 insertions(+)

diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 2acca22..b3e58fa 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -437,6 +437,12 @@ def _postDestroy(self, **kwargs):
         self.exists = False
         self.notifyKernel()
 
+    @property
+    def destroyable(self):
+        """ Do we have the facilities to destroy a format of this type. """
+        # assumes wipefs is always available
+        return True
+
     def setup(self, **kwargs):
         """ Activate the formatting.
 
@@ -458,6 +464,16 @@ def setup(self, **kwargs):
         self._setup(**kwargs)
         self._postSetup(**kwargs)
 
+    @property
+    def controllable(self):
+        """ Are external utilities available to allow this format to be both
+            setup and teared down.
+
+            :returns: True if this format can be set up, otherwise False
+            :rtype: bool
+        """
+        return True
+
     def _preSetup(self, **kwargs):
         """ Return True if setup should proceed. """
         if not self.exists:
diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py
index c855649..f729e1e 100644
--- a/blivet/formats/luks.py
+++ b/blivet/formats/luks.py
@@ -29,6 +29,7 @@
 from . import DeviceFormat, register_device_format
 from ..flags import flags
 from ..i18n import _, N_
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -44,6 +45,7 @@ class LUKS(DeviceFormat):
     _linuxNative = True                 # for clearpart
     _packages = ["cryptsetup"]          # required packages
     _minSize = crypto.LUKS_METADATA_SIZE
+    _plugin = availability.BLOCKDEV_CRYPTO_PLUGIN
 
     def __init__(self, **kwargs):
         """
@@ -150,6 +152,18 @@ def hasKey(self):
                 (self._key_file and os.access(self._key_file, os.R_OK)))
 
     @property
+    def formattable(self):
+        return super(LUKS, self).formattable and self._plugin.available
+
+    @property
+    def supported(self):
+        return super(LUKS, self).supported and self._plugin.available
+
+    @property
+    def controllable(self):
+        return super(LUKS, self).controllable and self._plugin.available
+
+    @property
     def configured(self):
         """ To be ready we need a key or passphrase and a map name. """
         return self.hasKey and self.mapName
@@ -203,6 +217,10 @@ def _postCreate(self, **kwargs):
             self.mapName = "luks-%s" % self.uuid
 
     @property
+    def destroyable(self):
+        return self._plugin.available
+
+    @property
     def keyFile(self):
         """ Path to key file to be used in /etc/crypttab """
         return self._key_file
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index 2a2e556..c1655d6 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -26,6 +26,7 @@
 from ..storage_log import log_method_call
 from parted import PARTITION_LVM
 from ..devicelibs import lvm
+from ..tasks import availability
 from ..i18n import N_
 from ..size import Size
 from . import DeviceFormat, register_device_format
@@ -46,6 +47,7 @@ class LVMPhysicalVolume(DeviceFormat):
     _minSize = lvm.LVM_PE_SIZE * 2      # one for metadata and one for data
     _packages = ["lvm2"]                # required packages
     _ksMountpoint = "pv."
+    _plugin = availability.BLOCKDEV_LVM_PLUGIN
 
     def __init__(self, **kwargs):
         """
@@ -94,6 +96,14 @@ def dict(self):
                   "peStart": self.peStart, "dataAlignment": self.dataAlignment})
         return d
 
+    @property
+    def formattable(self):
+        return super(LVMPhysicalVolume, self).formattable and self._plugin.available
+
+    @property
+    def supported(self):
+        return super(LVMPhysicalVolume, self).supported and self._plugin.available
+
     def _create(self, **kwargs):
         log_method_call(self, device=self.device,
                         type=self.type, status=self.status)
@@ -121,6 +131,10 @@ def _destroy(self, **kwargs):
             blockdev.lvm.pvscan(self.device)
 
     @property
+    def destroyable(self):
+        return self._plugin.available
+
+    @property
     def status(self):
         # XXX hack
         return (self.exists and self.vgName and
diff --git a/blivet/formats/mdraid.py b/blivet/formats/mdraid.py
index be4a915..5d8b22b 100644
--- a/blivet/formats/mdraid.py
+++ b/blivet/formats/mdraid.py
@@ -27,6 +27,7 @@
 from . import DeviceFormat, register_device_format
 from ..flags import flags
 from ..i18n import N_
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -43,6 +44,7 @@ class MDRaidMember(DeviceFormat):
     _linuxNative = True                 # for clearpart
     _packages = ["mdadm"]               # required packages
     _ksMountpoint = "raid."
+    _plugin = availability.BLOCKDEV_MDRAID_PLUGIN
 
     def __init__(self, **kwargs):
         """
@@ -74,10 +76,22 @@ def dict(self):
         d.update({"mdUUID": self.mdUuid, "biosraid": self.biosraid})
         return d
 
+    @property
+    def formattable(self):
+        return super(MDRaidMember, self).formattable and self._plugin.available
+
+    @property
+    def supported(self):
+        return super(MDRaidMember, self).supported and self._plugin.available
+
     def _destroy(self, **kwargs):
         blockdev.md.destroy(self.device)
 
     @property
+    def destroyable(self):
+        return self._plugin.available
+
+    @property
     def status(self):
         # XXX hack -- we don't have a nice way to see if the array is active
         return False
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index 26ebd4f..a93a70f 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -22,6 +22,7 @@
 
 from parted import PARTITION_SWAP, fileSystemType
 from ..storage_log import log_method_call
+from ..tasks import availability
 from . import DeviceFormat, register_device_format
 from ..size import Size
 from gi.repository import BlockDev as blockdev
@@ -40,6 +41,7 @@ class SwapSpace(DeviceFormat):
     _formattable = True                # can be formatted
     _supported = True                  # is supported
     _linuxNative = True                # for clearpart
+    _plugin = availability.BLOCKDEV_SWAP_PLUGIN
 
     #see rhbz#744129 for details
     _maxSize = Size("128 GiB")
@@ -80,6 +82,18 @@ def dict(self):
         d.update({"priority": self.priority, "label": self.label})
         return d
 
+    @property
+    def formattable(self):
+        return super(SwapSpace, self).formattable and self._plugin.available
+
+    @property
+    def supported(self):
+        return super(SwapSpace, self).supported and self._plugin.available
+
+    @property
+    def controllable(self):
+        return super(SwapSpace, self).controllable and self._plugin.available
+
     def labeling(self):
         """Returns True as mkswap can write a label to the swap space."""
         return True


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/0651dfb1ab5f8b35fd8ba1f359ce19e8587c457b


More information about the anaconda-patches mailing list