neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0004-allow-removing-btrfs-volumes-without-btrfs-support.patch

bda387
From fd07d14ad1f19c700d5344c8af11be6a1e314ceb Mon Sep 17 00:00:00 2001
34c36b
From: Vojtech Trefny <vtrefny@redhat.com>
34c36b
Date: Wed, 12 Sep 2018 10:45:41 +0200
34c36b
Subject: [PATCH 1/2] Allow removing btrfs volumes without btrfs support
34c36b
34c36b
Btrfs volumes are removed using wipefs so we don't need to check
34c36b
for device dependencies availability when removing the volume
34c36b
(btrfs support depends on libblockdev btrfs plugin).
34c36b
34c36b
Resolves: rhbz#1605213
34c36b
---
34c36b
 blivet/deviceaction.py | 23 ++++++++++++++++++-----
34c36b
 1 file changed, 18 insertions(+), 5 deletions(-)
34c36b
34c36b
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
34c36b
index 3e337e18..b3e9e5f1 100644
34c36b
--- a/blivet/deviceaction.py
34c36b
+++ b/blivet/deviceaction.py
bda387
@@ -160,15 +160,19 @@ def __init__(self, device):
34c36b
         if not isinstance(device, StorageDevice):
34c36b
             raise ValueError("arg 1 must be a StorageDevice instance")
34c36b
 
34c36b
-        unavailable_dependencies = device.unavailable_dependencies
34c36b
-        if unavailable_dependencies:
34c36b
-            dependencies_str = ", ".join(str(d) for d in unavailable_dependencies)
34c36b
-            raise DependencyError("device type %s requires unavailable_dependencies: %s" % (device.type, dependencies_str))
34c36b
-
34c36b
         self.device = device
34c36b
+
34c36b
+        self._check_device_dependencies()
34c36b
+
34c36b
         self.container = getattr(self.device, "container", None)
34c36b
         self._applied = False
34c36b
 
34c36b
+    def _check_device_dependencies(self):
34c36b
+        unavailable_dependencies = self.device.unavailable_dependencies
34c36b
+        if unavailable_dependencies:
34c36b
+            dependencies_str = ", ".join(str(d) for d in unavailable_dependencies)
34c36b
+            raise DependencyError("device type %s requires unavailable_dependencies: %s" % (self.device.type, dependencies_str))
34c36b
+
34c36b
     def apply(self):
34c36b
         """ apply changes related to the action to the device(s) """
34c36b
         self._applied = True
bda387
@@ -379,6 +383,15 @@ def __init__(self, device):
34c36b
         # XXX should we insist that device.fs be None?
34c36b
         DeviceAction.__init__(self, device)
34c36b
 
34c36b
+    def _check_device_dependencies(self):
34c36b
+        if self.device.type == "btrfs volume":
34c36b
+            # XXX destroying a btrfs volume is a special case -- we don't destroy
34c36b
+            # the device, but use wipefs to destroy format on its parents so we
34c36b
+            # don't need btrfs plugin or btrfs-progs for this
34c36b
+            return
34c36b
+
34c36b
+        super(ActionDestroyDevice, self)._check_device_dependencies()
34c36b
+
34c36b
     def execute(self, callbacks=None):
34c36b
         super(ActionDestroyDevice, self).execute(callbacks=callbacks)
34c36b
         self.device.destroy()
34c36b
bda387
From b9f1b4acb654c5fb70be1a2200bcf3a34dcde467 Mon Sep 17 00:00:00 2001
34c36b
From: Vojtech Trefny <vtrefny@redhat.com>
34c36b
Date: Mon, 17 Sep 2018 10:25:24 +0200
34c36b
Subject: [PATCH 2/2] Check device dependencies only for device actions
34c36b
34c36b
We don't want to check device dependencies for format actions.
34c36b
It should be possible to for example format an opened LUKS device
34c36b
without libblockdev crypto plugin.
34c36b
34c36b
Related: rhbz#1605213
34c36b
---
34c36b
 blivet/deviceaction.py                  | 3 ++-
bda387
 tests/devices_test/dependencies_test.py | 4 ----
bda387
 2 files changed, 2 insertions(+), 5 deletions(-)
34c36b
34c36b
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
34c36b
index b3e9e5f1..14a06ff0 100644
34c36b
--- a/blivet/deviceaction.py
34c36b
+++ b/blivet/deviceaction.py
bda387
@@ -162,7 +162,8 @@ def __init__(self, device):
34c36b
 
34c36b
         self.device = device
34c36b
 
34c36b
-        self._check_device_dependencies()
34c36b
+        if self.is_device:
34c36b
+            self._check_device_dependencies()
34c36b
 
34c36b
         self.container = getattr(self.device, "container", None)
34c36b
         self._applied = False
bda387
diff --git a/tests/devices_test/dependencies_test.py b/tests/devices_test/dependencies_test.py
bda387
index 0b44493e..e6b5bdb4 100644
bda387
--- a/tests/devices_test/dependencies_test.py
bda387
+++ b/tests/devices_test/dependencies_test.py
bda387
@@ -97,10 +97,6 @@ def test_availability_mdraidplugin(self):
bda387
             ActionCreateDevice(self.luks)
bda387
         with self.assertRaises(DependencyError):
bda387
             ActionDestroyDevice(self.dev)
bda387
-        with self.assertRaises(DependencyError):
bda387
-            ActionCreateFormat(self.dev)
bda387
-        with self.assertRaises(DependencyError):
bda387
-            ActionDestroyFormat(self.dev)
bda387
 
bda387
     def _clean_up(self):
bda387
         availability.BLOCKDEV_MDRAID_PLUGIN._method = self.mdraid_method