neil / rpms / python-blivet

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