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

mulkieran installerbot-noreply at redhat.com
Thu Apr 23 16:39:47 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      |  4 ++++
 blivet/devices/loop.py    |  2 ++
 blivet/devices/lvm.py     |  2 ++
 blivet/devices/md.py      |  2 ++
 blivet/devices/storage.py | 34 ++++++++++++++++++++++++++++++++++
 7 files changed, 50 insertions(+)

diff --git a/blivet/devices/btrfs.py b/blivet/devices/btrfs.py
index 8c59443..f7cfe3b 100644
--- a/blivet/devices/btrfs.py
+++ b/blivet/devices/btrfs.py
@@ -42,10 +42,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 5f35ce6..a274bda 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.application("multipath")]
 
     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 e834abf..ed1b682 100644
--- a/blivet/devices/dm.py
+++ b/blivet/devices/dm.py
@@ -28,6 +28,7 @@
 from .. import util
 from ..storage_log import log_method_call
 from .. import udev
+from ..tasks import availability
 
 import logging
 log = logging.getLogger("blivet")
@@ -39,6 +40,9 @@ class DMDevice(StorageDevice):
     """ A device-mapper device """
     _type = "dm"
     _devDir = "/dev/mapper"
+    _external_dependencies = \
+       [availability.application("kpartx"), 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 6410443..3e2d5c4 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 a32dd60..5f01879 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -36,6 +36,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")
@@ -446,6 +447,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 588ef1e..7e9e090 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -33,6 +33,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")
@@ -48,6 +49,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..016435e 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,36 @@ def isNameValid(cls, name):
 
         badchars = any(c in ('\x00', '/') for c in name)
         return not(badchars or name == '.' or name == '..')
+
+    @property
+    def typeExternalDependencies(self):
+        """ 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 self.__class__.__mro__ if issubclass(p, StorageDevice) for d in p._external_dependencies
+        )
+
+    @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/7db7bbef951f30b8b90f6f8ec4742dbb6ba18c8c


More information about the anaconda-patches mailing list