[master 10/21] Track external dependencies in devices.

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


From: mulhern <amulhern at redhat.com>

Related: #12

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devices/btrfs.py   |  3 +++
 blivet/devices/disk.py    |  3 +++
 blivet/devices/dm.py      |  5 +++++
 blivet/devices/loop.py    |  2 ++
 blivet/devices/lvm.py     |  2 ++
 blivet/devices/md.py      |  2 ++
 blivet/devices/storage.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 60 insertions(+)

diff --git a/blivet/devices/btrfs.py b/blivet/devices/btrfs.py
index ced4275..867e271 100644
--- a/blivet/devices/btrfs.py
+++ b/blivet/devices/btrfs.py
@@ -41,10 +41,13 @@
 from .container import ContainerDevice
 from .raid import RaidDevice
 
+from ..tasks import availability
+
 class BTRFSDevice(StorageDevice):
     """ Base class for BTRFS volume and sub-volume devices. """
     _type = "btrfs"
     _packages = ["btrfs-progs"]
+    _external_dependencies = [availability.BLOCKDEV_BTRFS_PLUGIN]
 
     def __init__(self, *args, **kwargs):
         """ Passing None or no name means auto-generate one like btrfs.%d """
diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py
index 39acea2..0d06c30 100644
--- a/blivet/devices/disk.py
+++ b/blivet/devices/disk.py
@@ -29,6 +29,7 @@
 from ..storage_log import log_method_call
 from .. import udev
 from ..size import Size
+from ..tasks import availability
 
 from ..fcoe import fcoe
 
@@ -163,6 +164,7 @@ class DMRaidArrayDevice(DMDevice, ContainerDevice):
     _isDisk = True
     _formatClassName = property(lambda s: "dmraidmember")
     _formatUUIDAttr = property(lambda s: None)
+    _external_dependencies = [availability.BLOCKDEV_DM_PLUGIN]
 
     def __init__(self, name, fmt=None,
                  size=None, parents=None, sysfsPath=''):
@@ -242,6 +244,7 @@ class MultipathDevice(DMDevice):
     _packages = ["device-mapper-multipath"]
     _partitionable = True
     _isDisk = True
+    _external_dependencies = [availability.MULTIPATH_APP]
 
     def __init__(self, name, fmt=None, size=None, serial=None,
                  parents=None, sysfsPath=''):
diff --git a/blivet/devices/dm.py b/blivet/devices/dm.py
index f980f64..10eca77 100644
--- a/blivet/devices/dm.py
+++ b/blivet/devices/dm.py
@@ -27,6 +27,7 @@
 from .. import util
 from ..storage_log import log_method_call
 from .. import udev
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -38,6 +39,10 @@ class DMDevice(StorageDevice):
     """ A device-mapper device """
     _type = "dm"
     _devDir = "/dev/mapper"
+    _external_dependencies = [
+       availability.KPARTX_APP,
+       availability.BLOCKDEV_DM_PLUGIN
+    ]
 
     def __init__(self, name, fmt=None, size=None, dmUuid=None, uuid=None,
                  target=None, exists=False, parents=None, sysfsPath=''):
diff --git a/blivet/devices/loop.py b/blivet/devices/loop.py
index aca8d44..301fdf4 100644
--- a/blivet/devices/loop.py
+++ b/blivet/devices/loop.py
@@ -24,6 +24,7 @@
 
 from .. import errors
 from ..storage_log import log_method_call
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -33,6 +34,7 @@
 class LoopDevice(StorageDevice):
     """ A loop device. """
     _type = "loop"
+    _external_dependencies = [availability.BLOCKDEV_LOOP_PLUGIN]
 
     def __init__(self, name=None, fmt=None, size=None, sysfsPath=None,
                  exists=False, parents=None):
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index d7526e4..a4bc712 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -35,6 +35,7 @@
 from ..storage_log import log_method_call
 from .. import udev
 from ..size import Size, KiB, MiB, ROUND_UP, ROUND_DOWN
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -445,6 +446,7 @@ class LVMLogicalVolumeDevice(DMDevice):
     _resizable = True
     _packages = ["lvm2"]
     _containerClass = LVMVolumeGroupDevice
+    _external_dependencies = default=[availability.BLOCKDEV_LVM_PLUGIN]
 
     def __init__(self, name, parents=None, size=None, uuid=None,
                  copies=1, logSize=None, segType=None,
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index 82b5ec8..d81f058 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -32,6 +32,7 @@
 from ..storage_log import log_method_call
 from .. import udev
 from ..size import Size
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -47,6 +48,7 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
     _devDir = "/dev/md"
     _formatClassName = property(lambda s: "mdmember")
     _formatUUIDAttr = property(lambda s: "mdUuid")
+    _external_dependencies = [availability.BLOCKDEV_MDRAID_PLUGIN]
 
     def __init__(self, name, level=None, major=None, minor=None, size=None,
                  memberDevices=None, totalDevices=None,
diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index 052b397..aae22af 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -56,6 +56,7 @@ class StorageDevice(Device):
     _partitionable = False
     _isDisk = False
     _encrypted = False
+    _external_dependencies = []
 
     def __init__(self, name, fmt=None, uuid=None,
                  size=None, major=None, minor=None,
@@ -748,3 +749,45 @@ def isNameValid(cls, name):
 
         badchars = any(c in ('\x00', '/') for c in name)
         return not(badchars or name == '.' or name == '..')
+
+    @classmethod
+    def typeExternalDependencies(cls):
+        """ A list of external dependencies of this device type.
+
+            :returns: a set of external dependencies
+            :rtype: set of availability.ExternalResource
+
+            The external dependencies include the dependencies of this
+            device type and of all superclass device types.
+        """
+        return set(
+           d for p in cls.__mro__ if issubclass(p, StorageDevice) for d in p._external_dependencies
+        )
+
+    @classmethod
+    def unavailableTypeDependencies(cls):
+        """ A set of unavailable dependencies for this type.
+
+            :return: the unavailable external dependencies for this type
+            :rtype: set of availability.ExternalResource
+        """
+        return set(e for e in cls.typeExternalDependencies() if not e.available)
+
+    @property
+    def externalDependencies(self):
+        """ A list of external dependencies of this device and its parents.
+
+            :returns: the external dependencies of this device and all parents.
+            :rtype: set of availability.ExternalResource
+        """
+        return set(d for p in self.ancestors for d in p.typeExternalDependencies())
+
+    @property
+    def unavailableDependencies(self):
+        """ Any unavailable external dependencies of this device or its
+            parents.
+
+            :returns: A list of unavailable external dependencies.
+            :rtype: set of availability.externalResource
+        """
+        return set(e for e in self.externalDependencies if not e.available)


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


More information about the anaconda-patches mailing list