Blob Blame History Raw
From fd07d14ad1f19c700d5344c8af11be6a1e314ceb Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 12 Sep 2018 10:45:41 +0200
Subject: [PATCH 1/2] Allow removing btrfs volumes without btrfs support

Btrfs volumes are removed using wipefs so we don't need to check
for device dependencies availability when removing the volume
(btrfs support depends on libblockdev btrfs plugin).

Resolves: rhbz#1605213
---
 blivet/deviceaction.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index 3e337e18..b3e9e5f1 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -160,15 +160,19 @@ def __init__(self, device):
         if not isinstance(device, StorageDevice):
             raise ValueError("arg 1 must be a StorageDevice instance")
 
-        unavailable_dependencies = device.unavailable_dependencies
-        if unavailable_dependencies:
-            dependencies_str = ", ".join(str(d) for d in unavailable_dependencies)
-            raise DependencyError("device type %s requires unavailable_dependencies: %s" % (device.type, dependencies_str))
-
         self.device = device
+
+        self._check_device_dependencies()
+
         self.container = getattr(self.device, "container", None)
         self._applied = False
 
+    def _check_device_dependencies(self):
+        unavailable_dependencies = self.device.unavailable_dependencies
+        if unavailable_dependencies:
+            dependencies_str = ", ".join(str(d) for d in unavailable_dependencies)
+            raise DependencyError("device type %s requires unavailable_dependencies: %s" % (self.device.type, dependencies_str))
+
     def apply(self):
         """ apply changes related to the action to the device(s) """
         self._applied = True
@@ -379,6 +383,15 @@ def __init__(self, device):
         # XXX should we insist that device.fs be None?
         DeviceAction.__init__(self, device)
 
+    def _check_device_dependencies(self):
+        if self.device.type == "btrfs volume":
+            # XXX destroying a btrfs volume is a special case -- we don't destroy
+            # the device, but use wipefs to destroy format on its parents so we
+            # don't need btrfs plugin or btrfs-progs for this
+            return
+
+        super(ActionDestroyDevice, self)._check_device_dependencies()
+
     def execute(self, callbacks=None):
         super(ActionDestroyDevice, self).execute(callbacks=callbacks)
         self.device.destroy()

From b9f1b4acb654c5fb70be1a2200bcf3a34dcde467 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Mon, 17 Sep 2018 10:25:24 +0200
Subject: [PATCH 2/2] Check device dependencies only for device actions

We don't want to check device dependencies for format actions.
It should be possible to for example format an opened LUKS device
without libblockdev crypto plugin.

Related: rhbz#1605213
---
 blivet/deviceaction.py                  | 3 ++-
 tests/devices_test/dependencies_test.py | 4 ----
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index b3e9e5f1..14a06ff0 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -162,7 +162,8 @@ def __init__(self, device):
 
         self.device = device
 
-        self._check_device_dependencies()
+        if self.is_device:
+            self._check_device_dependencies()
 
         self.container = getattr(self.device, "container", None)
         self._applied = False
diff --git a/tests/devices_test/dependencies_test.py b/tests/devices_test/dependencies_test.py
index 0b44493e..e6b5bdb4 100644
--- a/tests/devices_test/dependencies_test.py
+++ b/tests/devices_test/dependencies_test.py
@@ -97,10 +97,6 @@ def test_availability_mdraidplugin(self):
             ActionCreateDevice(self.luks)
         with self.assertRaises(DependencyError):
             ActionDestroyDevice(self.dev)
-        with self.assertRaises(DependencyError):
-            ActionCreateFormat(self.dev)
-        with self.assertRaises(DependencyError):
-            ActionDestroyFormat(self.dev)
 
     def _clean_up(self):
         availability.BLOCKDEV_MDRAID_PLUGIN._method = self.mdraid_method