neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone
755168
From 3a42d9e2afdf04dbbfd2c507f5b2392193fda25b Mon Sep 17 00:00:00 2001
755168
From: Vojtech Trefny <vtrefny@redhat.com>
755168
Date: Wed, 26 May 2021 12:15:54 +0200
755168
Subject: [PATCH] Revert "More consistent lvm errors (API break)"
755168
755168
This reverts commit 49ec071c6d0673224a0774d613904387c52c7381.
755168
---
755168
 blivet/devices/lvm.py          | 72 +++++++++++++++++-----------------
755168
 tests/devices_test/lvm_test.py | 14 +++----
755168
 2 files changed, 43 insertions(+), 43 deletions(-)
755168
755168
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
755168
index a55515fc..6d23bfba 100644
755168
--- a/blivet/devices/lvm.py
755168
+++ b/blivet/devices/lvm.py
755168
@@ -307,7 +307,7 @@ class LVMVolumeGroupDevice(ContainerDevice):
755168
     def _add_log_vol(self, lv):
755168
         """ Add an LV to this VG. """
755168
         if lv in self._lvs:
755168
-            raise errors.DeviceError("lv is already part of this vg")
755168
+            raise ValueError("lv is already part of this vg")
755168
 
755168
         # verify we have the space, then add it
755168
         # do not verify for growing vg (because of ks)
755168
@@ -340,7 +340,7 @@ class LVMVolumeGroupDevice(ContainerDevice):
755168
     def _remove_log_vol(self, lv):
755168
         """ Remove an LV from this VG. """
755168
         if lv not in self.lvs:
755168
-            raise errors.DeviceError("specified lv is not part of this vg")
755168
+            raise ValueError("specified lv is not part of this vg")
755168
 
755168
         self._lvs.remove(lv)
755168
 
755168
@@ -415,7 +415,7 @@ class LVMVolumeGroupDevice(ContainerDevice):
755168
     @thpool_reserve.setter
755168
     def thpool_reserve(self, value):
755168
         if value is not None and not isinstance(value, ThPoolReserveSpec):
755168
-            raise AttributeError("Invalid thpool_reserve given, must be of type ThPoolReserveSpec")
755168
+            raise ValueError("Invalid thpool_reserve given, must be of type ThPoolReserveSpec")
755168
         self._thpool_reserve = value
755168
 
755168
     @property
755168
@@ -646,14 +646,14 @@ class LVMLogicalVolumeBase(DMDevice, RaidDevice):
755168
             if seg_type not in [None, "linear", "thin", "thin-pool", "cache", "vdo-pool", "vdo"] + lvm.raid_seg_types:
755168
                 raise ValueError("Invalid or unsupported segment type: %s" % seg_type)
755168
             if seg_type and seg_type in lvm.raid_seg_types and not pvs:
755168
-                raise errors.DeviceError("List of PVs has to be given for every non-linear LV")
755168
+                raise ValueError("List of PVs has to be given for every non-linear LV")
755168
             elif (not seg_type or seg_type == "linear") and pvs:
755168
                 if not all(isinstance(pv, LVPVSpec) for pv in pvs):
755168
-                    raise errors.DeviceError("Invalid specification of PVs for a linear LV: either no or complete "
755168
-                                             "specification (with all space split into PVs has to be given")
755168
+                    raise ValueError("Invalid specification of PVs for a linear LV: either no or complete "
755168
+                                     "specification (with all space split into PVs has to be given")
755168
                 elif sum(spec.size for spec in pvs) != size:
755168
-                    raise errors.DeviceError("Invalid specification of PVs for a linear LV: the sum of space "
755168
-                                             "assigned to PVs is not equal to the size of the LV")
755168
+                    raise ValueError("Invalid specification of PVs for a linear LV: the sum of space "
755168
+                                     "assigned to PVs is not equal to the size of the LV")
755168
 
755168
         # When this device's format is set in the superclass constructor it will
755168
         # try to access self.snapshots.
755168
@@ -702,13 +702,13 @@ class LVMLogicalVolumeBase(DMDevice, RaidDevice):
755168
         self._from_lvs = from_lvs
755168
         if self._from_lvs:
755168
             if exists:
755168
-                raise errors.DeviceError("Only new LVs can be created from other LVs")
755168
+                raise ValueError("Only new LVs can be created from other LVs")
755168
             if size or maxsize or percent:
755168
-                raise errors.DeviceError("Cannot specify size for a converted LV")
755168
+                raise ValueError("Cannot specify size for a converted LV")
755168
             if fmt:
755168
-                raise errors.DeviceError("Cannot specify format for a converted LV")
755168
+                raise ValueError("Cannot specify format for a converted LV")
755168
             if any(lv.vg != self.vg for lv in self._from_lvs):
755168
-                raise errors.DeviceError("Conversion of LVs only possible inside a VG")
755168
+                raise ValueError("Conversion of LVs only possible inside a VG")
755168
 
755168
         self._cache = None
755168
         if cache_request and not self.exists:
755168
@@ -723,13 +723,13 @@ class LVMLogicalVolumeBase(DMDevice, RaidDevice):
755168
             elif isinstance(pv_spec, StorageDevice):
755168
                 self._pv_specs.append(LVPVSpec(pv_spec, Size(0)))
755168
             else:
755168
-                raise AttributeError("Invalid PV spec '%s' for the '%s' LV" % (pv_spec, self.name))
755168
+                raise ValueError("Invalid PV spec '%s' for the '%s' LV" % (pv_spec, self.name))
755168
         # Make sure any destination PVs are actually PVs in this VG
755168
         if not set(spec.pv for spec in self._pv_specs).issubset(set(self.vg.parents)):
755168
             missing = [r.name for r in
755168
                        set(spec.pv for spec in self._pv_specs).difference(set(self.vg.parents))]
755168
             msg = "invalid destination PV(s) %s for LV %s" % (missing, self.name)
755168
-            raise errors.DeviceError(msg)
755168
+            raise ValueError(msg)
755168
         if self._pv_specs:
755168
             self._assign_pv_space()
755168
 
755168
@@ -1072,7 +1072,7 @@ class LVMLogicalVolumeBase(DMDevice, RaidDevice):
755168
         else:
755168
             msg = "the specified internal LV '%s' doesn't belong to this LV ('%s')" % (int_lv.lv_name,
755168
                                                                                        self.name)
755168
-            raise errors.DeviceError(msg)
755168
+            raise ValueError(msg)
755168
 
755168
     def populate_ksdata(self, data):
755168
         super(LVMLogicalVolumeBase, self).populate_ksdata(data)
755168
@@ -1171,7 +1171,7 @@ class LVMInternalLogicalVolumeMixin(object):
755168
     def _init_check(self):
755168
         # an internal LV should have no parents
755168
         if self._parent_lv and self._parents:
755168
-            raise errors.DeviceError("an internal LV should have no parents")
755168
+            raise ValueError("an internal LV should have no parents")
755168
 
755168
     @property
755168
     def is_internal_lv(self):
755168
@@ -1231,7 +1231,7 @@ class LVMInternalLogicalVolumeMixin(object):
755168
 
755168
     @readonly.setter
755168
     def readonly(self, value):  # pylint: disable=unused-argument
755168
-        raise errors.DeviceError("Cannot make an internal LV read-write")
755168
+        raise ValueError("Cannot make an internal LV read-write")
755168
 
755168
     @property
755168
     def type(self):
755168
@@ -1267,7 +1267,7 @@ class LVMInternalLogicalVolumeMixin(object):
755168
     def _check_parents(self):
755168
         # an internal LV should have no parents
755168
         if self._parents:
755168
-            raise errors.DeviceError("an internal LV should have no parents")
755168
+            raise ValueError("an internal LV should have no parents")
755168
 
755168
     def _add_to_parents(self):
755168
         # nothing to do here, an internal LV has no parents (in the DeviceTree's
755168
@@ -1277,13 +1277,13 @@ class LVMInternalLogicalVolumeMixin(object):
755168
     # internal LVs follow different rules limitting size
755168
     def _set_size(self, newsize):
755168
         if not isinstance(newsize, Size):
755168
-            raise AttributeError("new size must of type Size")
755168
+            raise ValueError("new size must of type Size")
755168
 
755168
         if not self.takes_extra_space:
755168
             if newsize <= self.parent_lv.size:  # pylint: disable=no-member
755168
                 self._size = newsize  # pylint: disable=attribute-defined-outside-init
755168
             else:
755168
-                raise errors.DeviceError("Internal LV cannot be bigger than its parent LV")
755168
+                raise ValueError("Internal LV cannot be bigger than its parent LV")
755168
         else:
755168
             # same rules apply as for any other LV
755168
             raise NotTypeSpecific()
755168
@@ -1361,18 +1361,18 @@ class LVMSnapshotMixin(object):
755168
             return
755168
 
755168
         if self.origin and not isinstance(self.origin, LVMLogicalVolumeDevice):
755168
-            raise errors.DeviceError("lvm snapshot origin must be a logical volume")
755168
+            raise ValueError("lvm snapshot origin must be a logical volume")
755168
         if self.vorigin and not self.exists:
755168
-            raise errors.DeviceError("only existing vorigin snapshots are supported")
755168
+            raise ValueError("only existing vorigin snapshots are supported")
755168
 
755168
         if isinstance(self.origin, LVMLogicalVolumeDevice) and \
755168
            isinstance(self.parents[0], LVMVolumeGroupDevice) and \
755168
            self.origin.vg != self.parents[0]:
755168
-            raise errors.DeviceError("lvm snapshot and origin must be in the same vg")
755168
+            raise ValueError("lvm snapshot and origin must be in the same vg")
755168
 
755168
         if self.is_thin_lv:
755168
             if self.origin and self.size and not self.exists:
755168
-                raise errors.DeviceError("thin snapshot size is determined automatically")
755168
+                raise ValueError("thin snapshot size is determined automatically")
755168
 
755168
     @property
755168
     def is_snapshot_lv(self):
755168
@@ -1544,7 +1544,7 @@ class LVMThinPoolMixin(object):
755168
     def _check_from_lvs(self):
755168
         if self._from_lvs:
755168
             if len(self._from_lvs) != 2:
755168
-                raise errors.DeviceError("two LVs required to create a thin pool")
755168
+                raise ValueError("two LVs required to create a thin pool")
755168
 
755168
     def _convert_from_lvs(self):
755168
         data_lv, metadata_lv = self._from_lvs
755168
@@ -1590,7 +1590,7 @@ class LVMThinPoolMixin(object):
755168
     def _add_log_vol(self, lv):
755168
         """ Add an LV to this pool. """
755168
         if lv in self._lvs:
755168
-            raise errors.DeviceError("lv is already part of this vg")
755168
+            raise ValueError("lv is already part of this vg")
755168
 
755168
         # TODO: add some checking to prevent overcommit for preexisting
755168
         self.vg._add_log_vol(lv)
755168
@@ -1601,7 +1601,7 @@ class LVMThinPoolMixin(object):
755168
     def _remove_log_vol(self, lv):
755168
         """ Remove an LV from this pool. """
755168
         if lv not in self._lvs:
755168
-            raise errors.DeviceError("specified lv is not part of this vg")
755168
+            raise ValueError("specified lv is not part of this vg")
755168
 
755168
         self._lvs.remove(lv)
755168
         self.vg._remove_log_vol(lv)
755168
@@ -1711,14 +1711,14 @@ class LVMThinLogicalVolumeMixin(object):
755168
         """Check that this device has parents as expected"""
755168
         if isinstance(self.parents, (list, ParentList)):
755168
             if len(self.parents) != 1:
755168
-                raise errors.DeviceError("constructor requires a single thin-pool LV")
755168
+                raise ValueError("constructor requires a single thin-pool LV")
755168
 
755168
             container = self.parents[0]
755168
         else:
755168
             container = self.parents
755168
 
755168
         if not container or not isinstance(container, LVMLogicalVolumeDevice) or not container.is_thin_pool:
755168
-            raise errors.DeviceError("constructor requires a thin-pool LV")
755168
+            raise ValueError("constructor requires a thin-pool LV")
755168
 
755168
     @property
755168
     def is_thin_lv(self):
755168
@@ -1755,7 +1755,7 @@ class LVMThinLogicalVolumeMixin(object):
755168
 
755168
     def _set_size(self, newsize):
755168
         if not isinstance(newsize, Size):
755168
-            raise AttributeError("new size must of type Size")
755168
+            raise ValueError("new size must of type Size")
755168
 
755168
         newsize = self.vg.align(newsize)
755168
         newsize = self.vg.align(util.numeric_type(newsize))
755168
@@ -2229,7 +2229,7 @@ class LVMLogicalVolumeDevice(LVMLogicalVolumeBase, LVMInternalLogicalVolumeMixin
755168
             container = self.parents
755168
 
755168
         if not isinstance(container, LVMVolumeGroupDevice):
755168
-            raise AttributeError("constructor requires a LVMVolumeGroupDevice")
755168
+            raise ValueError("constructor requires a LVMVolumeGroupDevice")
755168
 
755168
     @type_specific
755168
     def _add_to_parents(self):
755168
@@ -2240,12 +2240,12 @@ class LVMLogicalVolumeDevice(LVMLogicalVolumeBase, LVMInternalLogicalVolumeMixin
755168
     @type_specific
755168
     def _check_from_lvs(self):
755168
         """Check the LVs to create this LV from"""
755168
-        raise errors.DeviceError("Cannot create a new LV of type '%s' from other LVs" % self.seg_type)
755168
+        raise ValueError("Cannot create a new LV of type '%s' from other LVs" % self.seg_type)
755168
 
755168
     @type_specific
755168
     def _convert_from_lvs(self):
755168
         """Convert the LVs to create this LV from into its internal LVs"""
755168
-        raise errors.DeviceError("Cannot create a new LV of type '%s' from other LVs" % self.seg_type)
755168
+        raise ValueError("Cannot create a new LV of type '%s' from other LVs" % self.seg_type)
755168
 
755168
     @property
755168
     def external_dependencies(self):
755168
@@ -2265,7 +2265,7 @@ class LVMLogicalVolumeDevice(LVMLogicalVolumeBase, LVMInternalLogicalVolumeMixin
755168
     @type_specific
755168
     def _set_size(self, newsize):
755168
         if not isinstance(newsize, Size):
755168
-            raise AttributeError("new size must be of type Size")
755168
+            raise ValueError("new size must be of type Size")
755168
 
755168
         newsize = self.vg.align(newsize)
755168
         log.debug("trying to set lv %s size to %s", self.name, newsize)
755168
@@ -2274,7 +2274,7 @@ class LVMLogicalVolumeDevice(LVMLogicalVolumeBase, LVMInternalLogicalVolumeMixin
755168
         # space for it. A similar reasoning applies to shrinking the LV.
755168
         if not self.exists and newsize > self.size and newsize > self.vg.free_space + self.vg_space_used:
755168
             log.error("failed to set size: %s short", newsize - (self.vg.free_space + self.vg_space_used))
755168
-            raise errors.DeviceError("not enough free space in volume group")
755168
+            raise ValueError("not enough free space in volume group")
755168
 
755168
         LVMLogicalVolumeBase._set_size(self, newsize)
755168
 
755168
@@ -2622,7 +2622,7 @@ class LVMCache(Cache):
755168
                 spec.size = spec.pv.format.free
755168
                 space_to_assign -= spec.pv.format.free
755168
         if space_to_assign > 0:
755168
-            raise errors.DeviceError("Not enough free space in the PVs for this cache: %s short" % space_to_assign)
755168
+            raise ValueError("Not enough free space in the PVs for this cache: %s short" % space_to_assign)
755168
 
755168
     @property
755168
     def size(self):
755168
diff --git a/tests/devices_test/lvm_test.py b/tests/devices_test/lvm_test.py
755168
index 670c91c9..4156d0bf 100644
755168
--- a/tests/devices_test/lvm_test.py
755168
+++ b/tests/devices_test/lvm_test.py
755168
@@ -36,10 +36,10 @@ class LVMDeviceTest(unittest.TestCase):
755168
         lv = LVMLogicalVolumeDevice("testlv", parents=[vg],
755168
                                     fmt=blivet.formats.get_format("xfs"))
755168
 
755168
-        with six.assertRaisesRegex(self, errors.DeviceError, "lvm snapshot origin must be a logical volume"):
755168
+        with six.assertRaisesRegex(self, ValueError, "lvm snapshot origin must be a logical volume"):
755168
             LVMLogicalVolumeDevice("snap1", parents=[vg], origin=pv)
755168
 
755168
-        with six.assertRaisesRegex(self, errors.DeviceError, "only existing vorigin snapshots are supported"):
755168
+        with six.assertRaisesRegex(self, ValueError, "only existing vorigin snapshots are supported"):
755168
             LVMLogicalVolumeDevice("snap1", parents=[vg], vorigin=True)
755168
 
755168
         lv.exists = True
755168
@@ -64,7 +64,7 @@ class LVMDeviceTest(unittest.TestCase):
755168
         pool = LVMLogicalVolumeDevice("pool1", parents=[vg], size=Size("500 MiB"), seg_type="thin-pool")
755168
         thinlv = LVMLogicalVolumeDevice("thinlv", parents=[pool], size=Size("200 MiB"), seg_type="thin")
755168
 
755168
-        with six.assertRaisesRegex(self, errors.DeviceError, "lvm snapshot origin must be a logical volume"):
755168
+        with six.assertRaisesRegex(self, ValueError, "lvm snapshot origin must be a logical volume"):
755168
             LVMLogicalVolumeDevice("snap1", parents=[pool], origin=pv, seg_type="thin")
755168
 
755168
         # now make the constructor succeed so we can test some properties
755168
@@ -258,21 +258,21 @@ class LVMDeviceTest(unittest.TestCase):
755168
         vg = LVMVolumeGroupDevice("testvg", parents=[pv, pv2])
755168
 
755168
         # pvs have to be specified for non-linear LVs
755168
-        with self.assertRaises(errors.DeviceError):
755168
+        with self.assertRaises(ValueError):
755168
             lv = LVMLogicalVolumeDevice("testlv", parents=[vg], size=Size("512 MiB"),
755168
                                         fmt=blivet.formats.get_format("xfs"),
755168
                                         exists=False, seg_type="raid1")
755168
-        with self.assertRaises(errors.DeviceError):
755168
+        with self.assertRaises(ValueError):
755168
             lv = LVMLogicalVolumeDevice("testlv", parents=[vg], size=Size("512 MiB"),
755168
                                         fmt=blivet.formats.get_format("xfs"),
755168
                                         exists=False, seg_type="striped")
755168
 
755168
         # no or complete specification has to be given for linear LVs
755168
-        with self.assertRaises(errors.DeviceError):
755168
+        with self.assertRaises(ValueError):
755168
             lv = LVMLogicalVolumeDevice("testlv", parents=[vg], size=Size("512 MiB"),
755168
                                         fmt=blivet.formats.get_format("xfs"),
755168
                                         exists=False, pvs=[pv])
755168
-        with self.assertRaises(errors.DeviceError):
755168
+        with self.assertRaises(ValueError):
755168
             pv_spec = LVPVSpec(pv, Size("256 MiB"))
755168
             pv_spec2 = LVPVSpec(pv2, Size("250 MiB"))
755168
             lv = LVMLogicalVolumeDevice("testlv", parents=[vg], size=Size("512 MiB"),
755168
-- 
755168
2.31.1
755168