From 7db7bbef951f30b8b90f6f8ec4742dbb6ba18c8c Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 22 Apr 2015 08:16:40 -0400 Subject: [PATCH] Track external dependencies in devices. Related: #12 Signed-off-by: mulhern --- 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 8c59443cc..f7cfe3b2f 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 5f35ce600..a274bda35 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 e834abf52..ed1b6825b 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 641044323..3e2d5c482 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 a32dd6083..5f0187915 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 588ef1e7d..7e9e09076 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 052b3975b..016435e40 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)