neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

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

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