Пример #1
0
class BlivetUtilsTestToolkit(unittest.TestCase):

    vdevs = None
    blivet_utils = None

    def setUp(self):
        self.blivet_utils = BlivetUtils(exclusive_disks=self.vdevs)

        # check we are really working only with the targetcli disks
        disks = self.blivet_utils.get_disks()
        self.assertCountEqual(self.vdevs, [d.name for d in disks])

    def get_blivet_device(self, device_name):
        return self.blivet_utils.storage.devicetree.get_device_by_name(device_name)

    def reset(self):
        self.blivet_utils.blivet_reset()
Пример #2
0
    def test_resizable(self):
        device = MagicMock(type="", size=Size("1 GiB"))
        device.format = MagicMock(exists=True)
        device.format.return_value = None

        # swap is not resizable
        device.format.configure_mock(type="swap")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # resizable device
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertTrue(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("500 MiB"))
        self.assertEqual(res.max_size, Size("2 GiB"))

        # resizable device and non-resizable format
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=False, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # LV with snapshot -> not resizable
        device.configure_mock(type="lvmlv",
                              resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNotNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))
Пример #3
0
    def test_resizable(self):
        device = MagicMock(type="", size=Size("1 GiB"))
        device.format = MagicMock(exists=True)
        device.format.return_value = None

        # swap is not resizable
        device.format.configure_mock(type="swap")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # resizable device
        device.configure_mock(resizable=True, max_size=Size("2 GiB"), min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertTrue(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("500 MiB"))
        self.assertEqual(res.max_size, Size("2 GiB"))

        # resizable device and non-resizable format
        device.configure_mock(resizable=True, max_size=Size("2 GiB"), min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=False, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # LV with snapshot -> not resizable
        device.configure_mock(type="lvmlv", resizable=True, max_size=Size("2 GiB"), min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True, type="ext4")
        res = BlivetUtils.device_resizable(MagicMock(), device)
        self.assertFalse(res.resizable)
        self.assertIsNotNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))
Пример #4
0
class BlivetUtilsTestToolkit(unittest.TestCase):

    vdevs = None
    blivet_utils = None

    def setUp(self):
        self.blivet_utils = BlivetUtils(exclusive_disks=self.vdevs)

        # check we are really working only with the targetcli disks
        disks = self.blivet_utils.get_disks()
        self.assertCountEqual(self.vdevs, [d.name for d in disks])

    def get_blivet_device(self, device_name):
        return self.blivet_utils.storage.devicetree.get_device_by_name(device_name)
Пример #5
0
    def setUp(self):
        self.blivet_utils = BlivetUtils(exclusive_disks=self.vdevs)

        # check we are really working only with the targetcli disks
        disks = self.blivet_utils.get_disks()
        self.assertCountEqual(self.vdevs, [d.name for d in disks])
Пример #6
0
    def setUp(self):
        self.blivet_utils = BlivetUtils(exclusive_disks=self.vdevs)

        # check we are really working only with the targetcli disks
        disks = self.blivet_utils.get_disks()
        self.assertCountEqual(self.vdevs, [d.name for d in disks])
Пример #7
0
    def test_resizable(self):
        with patch("blivetgui.blivet_utils.BlivetUtils.blivet_reset",
                   lambda _: True):
            storage = BlivetUtils()
        device = MagicMock(type="",
                           size=Size("1 GiB"),
                           protected=False,
                           format_immutable=False,
                           children=[])
        device.format = MagicMock(exists=True, system_mountpoint=None)
        device.format.return_value = None

        # swap is not resizable
        device.format.configure_mock(type="swap")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertEqual(
            res.error, _("Resizing of swap format is currently not supported"))
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # mounted devices are not resizable
        device.format.configure_mock(type="ext4", system_mountpoint="/")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertEqual(res.error, _("Mounted devices cannot be resized"))
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # resizable device
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True,
                                     type="ext4",
                                     system_mountpoint=None)
        res = storage.device_resizable(device)
        self.assertTrue(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("500 MiB"))
        self.assertEqual(res.max_size, Size("2 GiB"))

        # resizable device and non-resizable format
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=False, type="ext4")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # LV with snapshot -> not resizable
        with patch("blivetgui.blivet_utils.BlivetUtils._has_snapshots",
                   lambda _, device: True):
            device.configure_mock(type="lvmlv",
                                  resizable=True,
                                  max_size=Size("2 GiB"),
                                  min_size=Size("500 MiB"))
            device.format.configure_mock(resizable=True, type="ext4")
            res = storage.device_resizable(device)
            self.assertFalse(res.resizable)
            self.assertIsNotNone(res.error)
            self.assertEqual(res.min_size, Size("1 MiB"))
            self.assertEqual(res.max_size, Size("1 GiB"))