def test_bootloader_in_kickstart(self): ''' test that a bootloader such as prepboot/biosboot shows up in the kickstart data ''' # prepboot test case with patch( 'pyanaconda.storage.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device: with patch( 'pyanaconda.storage.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up prepboot partition bootloader_device_obj = PartitionDevice( "test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") prepboot_blivet_obj = InstallerStorage() # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata prepboot_ksdata = returnClassForVersion()() prepboot_blivet_obj.ksdata = prepboot_ksdata prepboot_blivet_obj.update_ksdata() self.assertIn("part prepboot", str(prepboot_blivet_obj.ksdata)) # biosboot test case with patch('pyanaconda.storage.osinstall.InstallerStorage.devices', new_callable=PropertyMock) as mock_devices: with patch( 'pyanaconda.storage.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up biosboot partition biosboot_device_obj = PartitionDevice( "biosboot_partition_device") biosboot_device_obj.size = Size('1MiB') biosboot_device_obj.format = formats.get_format("biosboot") biosboot_blivet_obj = InstallerStorage() # mountpoints must exist for updateKSData to run mock_devices.return_value = [biosboot_device_obj] mock_mountpoints.values.return_value = [] # initialize ksdata biosboot_ksdata = returnClassForVersion()() biosboot_blivet_obj.ksdata = biosboot_ksdata biosboot_blivet_obj.update_ksdata() self.assertIn("part biosboot", str(biosboot_blivet_obj.ksdata))
def test_bootloader_in_kickstart(self): ''' test that a bootloader such as prepboot/biosboot shows up in the kickstart data ''' with patch('blivet.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device: with patch('blivet.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up prepboot partition bootloader_device_obj = PartitionDevice( "test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") blivet_obj = InstallerStorage() # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata test_ksdata = returnClassForVersion()() blivet_obj.ksdata = test_ksdata blivet_obj.update_ksdata() self.assertTrue("part prepboot" in str(blivet_obj.ksdata))
def test_bootloader_in_kickstart(self): ''' test that a bootloader such as prepboot/biosboot shows up in the kickstart data ''' with patch('blivet.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device: with patch('blivet.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up prepboot partition bootloader_device_obj = PartitionDevice("test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") blivet_obj = InstallerStorage() # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata test_ksdata = returnClassForVersion()() blivet_obj.ksdata = test_ksdata blivet_obj.update_ksdata() self.assertTrue("part prepboot" in str(blivet_obj.ksdata))
def test_biosboot_bootloader_in_kickstart(self, mock_mountpoints, mock_devices, dbus): """Test that a biosboot bootloader shows up in the ks data.""" # set up biosboot partition biosboot_device_obj = PartitionDevice("biosboot_partition_device") biosboot_device_obj.size = Size('1MiB') biosboot_device_obj.format = formats.get_format("biosboot") # mountpoints must exist for updateKSData to run mock_devices.return_value = [biosboot_device_obj] mock_mountpoints.values.return_value = [] # initialize ksdata biosboot_blivet_obj = InstallerStorage(makeVersion()) biosboot_blivet_obj.update_ksdata() self.assertIn("part biosboot", str(biosboot_blivet_obj.ksdata))
def test_biosboot_bootloader_in_kickstart(self, mock_mountpoints, mock_devices, dbus): """Test that a biosboot bootloader shows up in the ks data.""" # set up biosboot partition biosboot_device_obj = PartitionDevice("biosboot_partition_device") biosboot_device_obj.size = Size('1MiB') biosboot_device_obj.format = formats.get_format("biosboot") # mountpoints must exist for updateKSData to run mock_devices.return_value = [biosboot_device_obj] mock_mountpoints.values.return_value = [] # initialize ksdata ksdata = makeVersion() biosboot_blivet_obj = InstallerStorage() update_storage_ksdata(biosboot_blivet_obj, ksdata) self.assertIn("part biosboot", str(ksdata))
def test_prepboot_bootloader_in_kickstart(self, mock_mountpoints, mock_bootloader_device, dbus): """Test that a prepboot bootloader shows up in the ks data.""" # set up prepboot partition bootloader_device_obj = PartitionDevice("test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata prepboot_blivet_obj = InstallerStorage(makeVersion()) prepboot_blivet_obj.update_ksdata() self.assertIn("part prepboot", str(prepboot_blivet_obj.ksdata))
def test_biosboot_bootloader_in_kickstart(self, mock_mountpoints, mock_devices, dbus): """Test that a biosboot bootloader shows up in the ks data.""" # set up biosboot partition biosboot_device_obj = PartitionDevice("biosboot_partition_device") biosboot_device_obj.size = Size('1MiB') biosboot_device_obj.format = get_format("biosboot") # mountpoints must exist for updateKSData to run mock_devices.return_value = [biosboot_device_obj] mock_mountpoints.values.return_value = [] # set up the storage self.module.on_storage_changed(create_storage()) self.assertTrue(self.module.storage) # initialize ksdata ksdata = self._setup_kickstart() self.assertIn("part biosboot", str(ksdata))
def test_prepboot_bootloader_in_kickstart(self, mock_mountpoints, dbus): """Test that a prepboot bootloader shows up in the ks data.""" # set up prepboot partition bootloader_device_obj = PartitionDevice("test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = get_format("prepboot") # mountpoints must exist for update_ksdata to run mock_mountpoints.values.return_value = [] # set up the storage self.module.on_storage_changed(create_storage()) assert self.module.storage self.module.storage.bootloader.stage1_device = bootloader_device_obj # initialize ksdata ksdata = self._setup_kickstart() assert "part prepboot" in str(ksdata)
def test_prepboot_bootloader_in_kickstart(self, mock_mountpoints, dbus): """Test that a prepboot bootloader shows up in the ks data.""" # disable other partitioning modules dbus.return_value.Enabled = False # set up prepboot partition bootloader_device_obj = PartitionDevice("test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") # mountpoints must exist for update_ksdata to run mock_mountpoints.values.return_value = [] # set up the storage prepboot_blivet_obj = InstallerStorage() prepboot_blivet_obj.bootloader.stage1_device = bootloader_device_obj # initialize ksdata ksdata = makeVersion() update_storage_ksdata(prepboot_blivet_obj, ksdata) self.assertIn("part prepboot", str(ksdata))
def test_target_size(self): with sparsetmpfile("targetsizetest", Size("10 MiB")) as disk_file: disk = DiskFile(disk_file) disk.format = get_format("disklabel", device=disk.path, label_type="msdos") grain_size = Size(disk.format.alignment.grainSize) sector_size = Size(disk.format.parted_device.sectorSize) start = int(grain_size) orig_size = Size("6 MiB") end = start + int(orig_size / sector_size) - 1 disk.format.add_partition(start, end) partition = disk.format.parted_disk.getPartitionBySector(start) self.assertNotEqual(partition, None) self.assertEqual(orig_size, Size(partition.getLength(unit='B'))) device = PartitionDevice(os.path.basename(partition.path), size=orig_size) device.disk = disk device.exists = True device.parted_partition = partition device.format = get_format("ext4", device=device.path) device.format.exists = True # grain size should be 1 MiB device.format._min_instance_size = Size("2 MiB") + (grain_size / 2) device.format._resizable = True # Make sure things are as expected to begin with. self.assertEqual(device.size, orig_size) self.assertEqual(device.min_size, Size("3 MiB")) # start sector's at 1 MiB self.assertEqual(device.max_size, Size("9 MiB")) # ValueError if not Size with six.assertRaisesRegex(self, ValueError, "new size must.*type Size"): device.target_size = 22 self.assertEqual(device.target_size, orig_size) # ValueError if size smaller than min_size with six.assertRaisesRegex(self, ValueError, "size.*smaller than the minimum"): device.target_size = Size("1 MiB") self.assertEqual(device.target_size, orig_size) # ValueError if size larger than max_size with six.assertRaisesRegex(self, ValueError, "size.*larger than the maximum"): device.target_size = Size("11 MiB") self.assertEqual(device.target_size, orig_size) # ValueError if unaligned with six.assertRaisesRegex(self, ValueError, "new size.*not.*aligned"): device.target_size = Size("3.1 MiB") self.assertEqual(device.target_size, orig_size) # successfully set a new target size new_target = device.max_size device.target_size = new_target self.assertEqual(device.target_size, new_target) self.assertEqual(device.size, new_target) parted_size = Size(device.parted_partition.getLength(unit='B')) self.assertEqual(parted_size, device.target_size) # reset target size to original size device.target_size = orig_size self.assertEqual(device.target_size, orig_size) self.assertEqual(device.size, orig_size) parted_size = Size(device.parted_partition.getLength(unit='B')) self.assertEqual(parted_size, device.target_size)
def test_min_max_size_alignment(self): with sparsetmpfile("minsizetest", Size("10 MiB")) as disk_file: disk = DiskFile(disk_file) disk.format = get_format("disklabel", device=disk.path) grain_size = Size(disk.format.alignment.grainSize) sector_size = Size(disk.format.parted_device.sectorSize) start = int(grain_size) end = start + int(Size("6 MiB") / sector_size) disk.format.add_partition(start, end) partition = disk.format.parted_disk.getPartitionBySector(start) self.assertNotEqual(partition, None) device = PartitionDevice(os.path.basename(partition.path)) device.disk = disk device.exists = True device.parted_partition = partition # Typical sector size is 512 B. # Default optimum alignment grain size is 2048 sectors, or 1 MiB. device.format = get_format("ext4", device=device.path) device.format.exists = True device.format._min_instance_size = Size("2 MiB") + (grain_size / 2) device.format._resizable = True ## # min_size ## # The end sector based only on format min size should be unaligned. min_sectors = int(device.format.min_size / sector_size) min_end_sector = partition.geometry.start + min_sectors - 1 self.assertEqual( disk.format.end_alignment.isAligned(partition.geometry, min_end_sector), False) # The end sector based on device min size should be aligned. min_sectors = int(device.min_size / sector_size) min_end_sector = partition.geometry.start + min_sectors - 1 self.assertEqual( disk.format.end_alignment.isAligned(partition.geometry, min_end_sector), True) ## # max_size ## # Add a partition starting three sectors past an aligned sector and # extending to the end of the disk so that there's a free region # immediately following the first partition with an unaligned end # sector. free = disk.format.parted_disk.getFreeSpaceRegions()[-1] raw_start = int(Size("9 MiB") / sector_size) start = disk.format.alignment.alignUp(free, raw_start) + 3 disk.format.add_partition(start, disk.format.parted_device.length - 1) # Verify the end of the free region immediately following the first # partition is unaligned. free = disk.format.parted_disk.getFreeSpaceRegions()[1] self.assertEqual(disk.format.end_alignment.isAligned(free, free.end), False) # The end sector based on device min size should be aligned. max_sectors = int(device.max_size / sector_size) max_end_sector = partition.geometry.start + max_sectors - 1 self.assertEqual( disk.format.end_alignment.isAligned(free, max_end_sector), True)