def _create_hdd_image(device: disk.Device): verbose("hdd.img created.") partitioner = disk.Partitioner(device) partitioner.repartition([ disk.Partitioner.efi_partition(size=disk.byte_size("512M")), disk.Partitioner.swap_partition(size=disk.byte_size("1G"), name="swap"), disk.Partitioner.data_partition(name="data"), ]) verbose("hdd.img repartitioned.") debug("Format EFI partitition.") run("/usr/bin/mkfs.vfat", "-F32", device.device(1)) debug("Set up swap partitition.") run("/usr/bin/mkswap", device.device(2)) debug("Format data partitition.") run("/usr/bin/mkfs.btrfs", "-L", "fs_btrfs", device.device(3))
def validate_image(file: str, format: str, size: str, dir: str) -> typing.Tuple[str, str, str]: if not os.path.isdir(dir): (f"{dir} is not a directory.") return ("", "", "") if file.startswith("/dev/") or file.startswith("/sys/"): (f'"{file}" does not look like a image file name.') return ("", "", "") if not os.path.exists(file): if not size: (f'No size for missing image file "{file}"') return ("", "", "") disk.create_image_file(file, disk.byte_size(size), disk_format=format) if not os.path.isfile(file): (f'"{file}" exists but is no file.') return ("", "", "") return (file, format, dir)
def test_partitioner(tmpdir) -> None: if os.geteuid() != 0: pytest.skip("This test needs root to run.") with disk.NbdDevice.new_image_file(os.path.join(tmpdir, "testdisk"), disk.byte_size("512m")) as device: partitioner = disk.Partitioner(device) assert not partitioner.is_partitioned() assert partitioner.label() is None print("LBA: {}-{}".format(partitioner.first_lba(), partitioner.last_lba())) parts = [ disk.Partitioner.efi_partition(size="64M"), disk.Partitioner.swap_partition(size="128M"), disk.Partitioner.data_partition(name="PV0 of vg_something"), ] partitioner.repartition(parts) assert partitioner.is_partitioned() assert partitioner.label() == "gpt"
def test_partitioner(tmpdir) -> None: if os.geteuid() != 0: pytest.skip('This test needs root to run.') with disk.NbdDevice.new_image_file(os.path.join(tmpdir, 'testdisk'), disk.byte_size('512m')) as device: partitioner = disk.Partitioner(device) assert not partitioner.is_partitioned() assert partitioner.label() is None print('LBA: {}-{}'.format(partitioner.first_lba(), partitioner.last_lba())) parts = [ disk.Partitioner.efi_partition(size='64M'), disk.Partitioner.swap_partition(size='128M'), disk.Partitioner.data_partition(name='PV0 of vg_something') ] partitioner.repartition(parts) assert partitioner.is_partitioned() assert partitioner.label() == 'gpt'
def test_disk_byte_size_errors(input_size) -> None: """Test absolute input file name.""" with pytest.raises(ValueError): disk.byte_size(input_size)
def test_disk_byte_size(input_size, output_size) -> None: """Test absolute input file name.""" result = disk.byte_size(input_size) assert result == output_size