neil / rpms / python-blivet

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