From: mulhern amulhern@redhat.com
Related: #56
Signed-off-by: mulhern amulhern@redhat.com --- tests/formats_test/luks_test.py | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
diff --git a/tests/formats_test/luks_test.py b/tests/formats_test/luks_test.py index d6127f1..a7c7d3a 100755 --- a/tests/formats_test/luks_test.py +++ b/tests/formats_test/luks_test.py @@ -1,5 +1,6 @@ import blivet.formats.luks as luks from blivet.size import Size +from blivet.errors import DeviceFormatError, LUKSError
from tests import loopbackedtestcase
@@ -64,3 +65,77 @@ def testSize(self): self.assertEqual(self.fmt.targetSize, self.fmt.size)
self.fmt.teardown() + + def testResize(self): + """ Test that resizing does the correct thing. """ + device = self.loopDevices[0] + + # create the device + self.fmt.device = device + self.assertIsNone(self.fmt.create()) + + self.fmt.updateSizeInfo() + + newsize = Size("64 MiB") + self.fmt.targetSize = newsize + + # can not resize an unopened device + with self.assertRaises(DeviceFormatError): + self.fmt.resize() + + # open the luks device + self.assertIsNone(self.fmt.setup()) + + # can resize an opened device + self.fmt.resize() + + # actually looking up the actual size, should yield same + # as target size. + self.assertEqual(self.fmt._sizeinfo.doTask(), newsize) + + # device format computed size + self.assertEqual(self.fmt.size, newsize) + self.assertEqual(self.fmt.currentSize, newsize) + self.assertEqual(self.fmt.targetSize, newsize) + + self.fmt.teardown() + + def testResizeBounds(self): + """ Test resizing outside the bounds of the device. + Note that the bounds of the device are not the same as the + bounds of the format. + """ + device = self.loopDevices[0] + + # create the device + self.fmt.device = device + self.assertIsNone(self.fmt.create()) + + self.fmt.updateSizeInfo() + + newsize = Size("128 MiB") + self.fmt.targetSize = newsize + + # open the luks device + self.assertIsNone(self.fmt.setup()) + + # can not resize outside the bounds of the device + with self.assertRaises(LUKSError): + self.fmt.resize() + + newsize = Size("96 MiB") + self.fmt.targetSize = newsize + + # can resize within the bounds of the device + self.assertIsNone(self.fmt.resize()) + + # actually looking up the actual size, should yield same + # as target size. + self.assertEqual(self.fmt._sizeinfo.doTask(), newsize) + + # device format computed size + self.assertEqual(self.fmt.size, newsize) + self.assertEqual(self.fmt.currentSize, newsize) + self.assertEqual(self.fmt.targetSize, newsize) + + self.fmt.teardown()