예제 #1
0
    def testShrink(self):
        an_fs = self._fs_class()
        if not can_resize(an_fs):
            self.skipTest("Not checking resize for this test category.")
        if not an_fs.formattable:
            self.skipTest("can not create filesystem %s" % an_fs.name)

        an_fs.device = self.loopDevices[0]
        self.assertIsNone(an_fs.create())
        an_fs.updateSizeInfo()

        TARGET_SIZE = Size("64 MiB")
        an_fs.targetSize = TARGET_SIZE
        self.assertIsNone(an_fs.doResize())

        TARGET_SIZE = TARGET_SIZE / 2
        self.assertTrue(TARGET_SIZE > an_fs.minSize)
        an_fs.targetSize = TARGET_SIZE
        self.assertEqual(an_fs.targetSize, TARGET_SIZE)
        self.assertNotEqual(an_fs._size, TARGET_SIZE)
        # FIXME:
        # doCheck() in updateSizeInfo() in doResize() does not complete tidily
        # here, so resizable becomes False and self.targetSize can not be
        # assigned to. This alerts us to the fact that now min size
        # and size are both incorrect values.
        if isinstance(an_fs, fs.NTFS):
            return
        self.assertIsNone(an_fs.doResize())
        ACTUAL_SIZE = TARGET_SIZE.roundToNearest(an_fs._resize.unit, rounding=ROUND_DOWN)
        self.assertEqual(an_fs._size, ACTUAL_SIZE)
        self._test_sizes(an_fs)
예제 #2
0
    def testShrink(self):
        an_fs = self._fs_class()
        if not can_resize(an_fs):
            self.skipTest("Not checking resize for this test category.")
        if not an_fs.formattable:
            self.skipTest("can not create filesystem %s" % an_fs.name)

        an_fs.device = self.loopDevices[0]
        self.assertIsNone(an_fs.create())
        an_fs.updateSizeInfo()

        TARGET_SIZE = Size("64 MiB")
        an_fs.targetSize = TARGET_SIZE
        self.assertIsNone(an_fs.doResize())

        TARGET_SIZE = TARGET_SIZE / 2
        self.assertTrue(TARGET_SIZE > an_fs.minSize)
        an_fs.targetSize = TARGET_SIZE
        self.assertEqual(an_fs.targetSize, TARGET_SIZE)
        self.assertNotEqual(an_fs._size, TARGET_SIZE)
        # FIXME:
        # doCheck() in updateSizeInfo() in doResize() does not complete tidily
        # here, so resizable becomes False and self.targetSize can not be
        # assigned to. This alerts us to the fact that now min size
        # and size are both incorrect values.
        if isinstance(an_fs, fs.NTFS):
            return
        self.assertIsNone(an_fs.doResize())
        ACTUAL_SIZE = TARGET_SIZE.roundToNearest(an_fs._resize.unit,
                                                 rounding=ROUND_DOWN)
        self.assertEqual(an_fs._size, ACTUAL_SIZE)
        self._test_sizes(an_fs)
예제 #3
0
    def testResize(self):
        an_fs = self._fs_class()
        if not an_fs.formattable:
            self.skipTest("can not create filesystem %s" % an_fs.name)
        an_fs.device = self.loopDevices[0]
        self.assertIsNone(an_fs.create())
        an_fs.updateSizeInfo()

        self._test_sizes(an_fs)
        # CHECKME: target size is still 0 after updatedSizeInfo is called.
        self.assertEqual(an_fs.size, Size(0) if an_fs.resizable else an_fs._size)

        if not can_resize(an_fs):
            self.assertFalse(an_fs.resizable)
            # Not resizable, so can not do resizing actions.
            with self.assertRaises(FSError):
                an_fs.targetSize = Size("64 MiB")
            with self.assertRaises(FSError):
                an_fs.doResize()
        else:
            self.assertTrue(an_fs.resizable)
            # Try a reasonable target size
            TARGET_SIZE = Size("64 MiB")
            an_fs.targetSize = TARGET_SIZE
            self.assertEqual(an_fs.targetSize, TARGET_SIZE)
            self.assertNotEqual(an_fs._size, TARGET_SIZE)
            self.assertIsNone(an_fs.doResize())
            ACTUAL_SIZE = TARGET_SIZE.roundToNearest(an_fs._resize.unit, rounding=ROUND_DOWN)
            self.assertEqual(an_fs.size, ACTUAL_SIZE)
            self.assertEqual(an_fs._size, ACTUAL_SIZE)
            self._test_sizes(an_fs)

        # and no errors should occur when checking
        self.assertIsNone(an_fs.doCheck())
예제 #4
0
    def testResize(self):
        an_fs = self._fs_class()
        if not an_fs.formattable:
            self.skipTest("can not create filesystem %s" % an_fs.name)
        an_fs.device = self.loopDevices[0]
        self.assertIsNone(an_fs.create())
        an_fs.updateSizeInfo()

        self._test_sizes(an_fs)
        # CHECKME: target size is still 0 after updatedSizeInfo is called.
        self.assertEqual(an_fs.size,
                         Size(0) if an_fs.resizable else an_fs._size)

        if not can_resize(an_fs):
            self.assertFalse(an_fs.resizable)
            # Not resizable, so can not do resizing actions.
            with self.assertRaises(FSError):
                an_fs.targetSize = Size("64 MiB")
            with self.assertRaises(FSError):
                an_fs.doResize()
        else:
            self.assertTrue(an_fs.resizable)
            # Try a reasonable target size
            TARGET_SIZE = Size("64 MiB")
            an_fs.targetSize = TARGET_SIZE
            self.assertEqual(an_fs.targetSize, TARGET_SIZE)
            self.assertNotEqual(an_fs._size, TARGET_SIZE)
            self.assertIsNone(an_fs.doResize())
            ACTUAL_SIZE = TARGET_SIZE.roundToNearest(an_fs._resize.unit,
                                                     rounding=ROUND_DOWN)
            self.assertEqual(an_fs.size, ACTUAL_SIZE)
            self.assertEqual(an_fs._size, ACTUAL_SIZE)
            self._test_sizes(an_fs)

        # and no errors should occur when checking
        self.assertIsNone(an_fs.doCheck())
예제 #5
0
파일: size_test.py 프로젝트: dashea/blivet
    def testRoundToNearest(self):
        self.assertEqual(size.ROUND_DEFAULT, size.ROUND_HALF_UP)

        s = Size("10.3 GiB")
        self.assertEqual(s.roundToNearest(GiB), Size("10 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DEFAULT),
                         Size("10 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DOWN),
                         Size("10 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_UP),
                         Size("11 GiB"))
        # >>> Size("10.3 GiB").convertTo(MiB)
        # Decimal('10547.19999980926513671875')
        self.assertEqual(s.roundToNearest(MiB), Size("10547 MiB"))
        self.assertEqual(s.roundToNearest(MiB, rounding=size.ROUND_UP),
                         Size("10548 MiB"))
        self.assertIsInstance(s.roundToNearest(MiB), Size)
        with self.assertRaises(ValueError):
            s.roundToNearest(MiB, rounding='abc')

        # arbitrary decimal rounding constants are not allowed
        from decimal import ROUND_HALF_DOWN
        with self.assertRaises(ValueError):
            s.roundToNearest(MiB, rounding=ROUND_HALF_DOWN)

        s = Size("10.51 GiB")
        self.assertEqual(s.roundToNearest(GiB), Size("11 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DEFAULT),
                         Size("11 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DOWN),
                         Size("10 GiB"))
        self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_UP),
                         Size("11 GiB"))

        s = Size("513 GiB")
        self.assertEqual(s.roundToNearest(GiB), s)
        self.assertEqual(s.roundToNearest(TiB), Size("1 TiB"))
        self.assertEqual(s.roundToNearest(TiB, rounding=size.ROUND_DOWN),
                         Size(0))

        # test Size parameters
        self.assertEqual(s.roundToNearest(Size("128 GiB")), Size("512 GiB"))
        self.assertEqual(s.roundToNearest(Size("1 KiB")), Size("513 GiB"))
        self.assertEqual(s.roundToNearest(Size("1 TiB")), Size("1 TiB"))
        self.assertEqual(s.roundToNearest(Size("1 TiB"), rounding=size.ROUND_DOWN), Size(0))
        self.assertEqual(s.roundToNearest(Size(0)), Size(0))
        self.assertEqual(s.roundToNearest(Size("13 GiB")), Size("507 GiB"))

        with self.assertRaises(ValueError):
            s.roundToNearest(Size("-1 B"))