[master 1/5] Add unit tests for the LVM cache support
vpodzime
installerbot-noreply at redhat.com
Fri Aug 14 05:31:49 UTC 2015
From: Vratislav Podzimek <vpodzime at redhat.com>
So that we can catch possible regressions easily in the future.
---
tests/devices_test/lvm_test.py | 28 +++++++++++++
tests/partitioning_test.py | 89 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+)
diff --git a/tests/devices_test/lvm_test.py b/tests/devices_test/lvm_test.py
index e8d0290..c2611da 100644
--- a/tests/devices_test/lvm_test.py
+++ b/tests/devices_test/lvm_test.py
@@ -11,6 +11,7 @@
from blivet.devices import LVMThinPoolDevice
from blivet.devices import LVMThinSnapShotDevice
from blivet.devices import LVMVolumeGroupDevice
+from blivet.devices.lvm import LVMCacheRequest
from blivet.size import Size
DEVICE_CLASSES = [
@@ -91,6 +92,33 @@ def testLVMThinSnapShotDeviceInit(self):
snap1.exists = True
self.assertEqual(snap1.dependsOn(thinlv), False)
+ def testLVMCachedLogicalVolumeInit(self):
+ pv = StorageDevice("pv1", fmt=blivet.formats.getFormat("lvmpv"),
+ size=Size("1 GiB"))
+ pv2 = StorageDevice("pv2", fmt=blivet.formats.getFormat("lvmpv"),
+ size=Size("512 MiB"))
+ vg = LVMVolumeGroupDevice("testvg", parents=[pv, pv2])
+
+ cache_req = LVMCacheRequest(Size("512 MiB"), [pv2], "writethrough")
+ lv = LVMLogicalVolumeDevice("testlv", parents=[vg],
+ fmt=blivet.formats.getFormat("xfs"),
+ exists=False, cacheRequest=cache_req)
+ self.assertEqual(lv.vgSpaceUsed, Size("512 MiB"))
+
+ # check that the LV behaves like a cached LV
+ self.assertTrue(lv.cached)
+ cache = lv.cache
+ self.assertIsNotNone(cache)
+
+ # check parameters reported by the (non-existing) cache
+ self.assertEqual(cache.size, Size("512 MiB"))
+ self.assertFalse(cache.exists)
+ self.assertIsNone(cache.stats)
+ self.assertEqual(cache.mode, "writethrough")
+ self.assertIsNone(cache.backing_device_name)
+ self.assertIsNone(cache.cache_device_name)
+ self.assertEqual(set(cache.fast_pvs), set([pv2]))
+
def testTargetSize(self):
pv = StorageDevice("pv1", fmt=blivet.formats.getFormat("lvmpv"),
size=Size("1 GiB"))
diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py
index 4e9900c..5f94e25 100644
--- a/tests/partitioning_test.py
+++ b/tests/partitioning_test.py
@@ -21,6 +21,7 @@
from blivet.devices import LVMLogicalVolumeDevice
from blivet.devices import DiskFile
from blivet.devices import PartitionDevice
+from blivet.devices.lvm import LVMCacheRequest
from tests.imagebackedtestcase import ImageBackedTestCase
from blivet.util import sparsetmpfile
@@ -504,6 +505,94 @@ def testVGChunk(self):
self.assertEqual(req2.growth, 3956)
self.assertEqual(req3.growth, 512)
+ def testVGChunkWithCache(self):
+ pv = StorageDevice("pv1", size=Size("40 GiB"),
+ fmt=getFormat("lvmpv"))
+ # 1025 MiB so that the PV provides 1024 MiB of free space (see LVMVolumeGroupDevice.extents)
+ pv2 = StorageDevice("pv2", size=Size("1025 MiB"),
+ fmt=getFormat("lvmpv"))
+ vg = LVMVolumeGroupDevice("vg", parents=[pv, pv2])
+
+ cache_req1 = LVMCacheRequest(Size("512 MiB"), [pv2], "writethrough")
+ lv1 = LVMLogicalVolumeDevice("lv1", parents=[vg],
+ size=Size("1 GiB"), grow=True,
+ cacheRequest=cache_req1)
+
+ cache_req2 = LVMCacheRequest(Size("512 MiB"), [pv2], "writethrough")
+ lv2 = LVMLogicalVolumeDevice("lv2", parents=[vg],
+ size=Size("10 GiB"), grow=True,
+ cacheRequest=cache_req2)
+
+ lv3 = LVMLogicalVolumeDevice("lv3", parents=[vg],
+ size=Size("10 GiB"), grow=True,
+ maxsize=Size("12 GiB"))
+
+ req1 = LVRequest(lv1)
+ req2 = LVRequest(lv2)
+ req3 = LVRequest(lv3)
+ chunk = VGChunk(vg, requests=[req1, req2, req3])
+
+ chunk.growRequests()
+
+ # the chunk is done growing since its pool has been exhausted
+ self.assertEqual(chunk.done, True)
+
+ # there are still two requests remaining since lv1 and lv2 have no max
+ self.assertEqual(chunk.remaining, 2)
+
+ # All the sizes should be the same as without the caches (see the
+ # testVGChunk test for their "rationales") because the space for the
+ # caches should just be reserved.
+ self.assertEqual(req1.growth, 395)
+ self.assertEqual(req2.growth, 3956)
+ self.assertEqual(req3.growth, 512)
+
+ def testVGChunkWithCachePVfree(self):
+ pv = StorageDevice("pv1", size=Size("40 GiB"),
+ fmt=getFormat("lvmpv"))
+ # 1069 MiB so that the PV provides 1068 MiB of free space (see
+ # LVMVolumeGroupDevice.extents) which is 44 MiB more than the caches
+ # need and which should thus be split into the LVs
+ pv2 = StorageDevice("pv2", size=Size("1069 MiB"),
+ fmt=getFormat("lvmpv"))
+ vg = LVMVolumeGroupDevice("vg", parents=[pv, pv2])
+
+ cache_req1 = LVMCacheRequest(Size("512 MiB"), [pv2], "writethrough")
+ lv1 = LVMLogicalVolumeDevice("lv1", parents=[vg],
+ size=Size("1 GiB"), grow=True,
+ cacheRequest=cache_req1)
+
+ cache_req2 = LVMCacheRequest(Size("512 MiB"), [pv2], "writethrough")
+ lv2 = LVMLogicalVolumeDevice("lv2", parents=[vg],
+ size=Size("10 GiB"), grow=True,
+ cacheRequest=cache_req2)
+
+ lv3 = LVMLogicalVolumeDevice("lv3", parents=[vg],
+ size=Size("10 GiB"), grow=True,
+ maxsize=Size("12 GiB"))
+
+ req1 = LVRequest(lv1)
+ req2 = LVRequest(lv2)
+ req3 = LVRequest(lv3)
+ chunk = VGChunk(vg, requests=[req1, req2, req3])
+
+ chunk.growRequests()
+
+ # the chunk is done growing since its pool has been exhausted
+ self.assertEqual(chunk.done, True)
+
+ # there are still two requests remaining since lv1 and lv2 have no max
+ self.assertEqual(chunk.remaining, 2)
+
+ # All the sizes should be the same as without the caches (see the
+ # testVGChunk test for their "rationales") because the space for the
+ # caches should just be reserved.
+ # The extra 11 extents available on the pv2 should go in the 1:10 ratio
+ # to req1 and req2.
+ self.assertEqual(req1.growth, 395 + 1)
+ self.assertEqual(req2.growth, 3956 + 10)
+ self.assertEqual(req3.growth, 512)
+
def testAlignFreeRegions(self):
# disk with two free regions -- first unaligned, second aligned
disk = Mock()
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/bba699289fc32a003741994fcef7377908b0bbd7
More information about the anaconda-patches
mailing list