def get_disk_info(args, image_info): disk_info = { "provisioned_size": image_info["virtual-size"], "initial_size": None, "backup": types.DiskBackup.INCREMENTAL if args.enable_backup else None } disk_format = args.disk_format or image_info["format"] # Convert qemu format names to oVirt constants ("raw", "cow"). if disk_format == "raw": disk_info["format"] = types.DiskFormat.RAW elif disk_format == "qcow2": disk_info["format"] = types.DiskFormat.COW # Create disk name from image name and disk format. basename = os.path.splitext(os.path.basename(args.ova_disk_name))[0] disk_info["name"] = "{}.{}".format(basename, disk_format) # The initial size is needed only when creating sparse qcow2 image on block # storage. On file storage the initial size is ignored. if args.disk_sparse and disk_format == "qcow2": measure = client.measure( args.ova_file, disk_format, member=args.ova_disk_name) disk_info["initial_size"] = measure["required"] return disk_info
def test_measure_to_qcow2(tmpdir, fmt, compressed): # Create temporary file with some data. size = 2 * 1024**2 tmp = str(tmpdir.join("tmp")) with open(tmp, "wb") as f: f.truncate(size) f.write(b"x" * CLUSTER_SIZE) # Created test image from temporary file. img = str(tmpdir.join("img")) qemu_img.convert(tmp, img, "raw", fmt, compressed=compressed) measure = client.measure(img, "qcow2") assert measure["required"] == 393216
def test_measure_from_ova(tmpdir, compressed, fmt): # Create temporary file with some data. size = 2 * 1024**2 tmp = str(tmpdir.join("tmp")) with open(tmp, "wb") as f: f.truncate(size) f.write(b"x" * CLUSTER_SIZE) # Created test image from temporary file. img = str(tmpdir.join("img")) qemu_img.convert(tmp, img, "raw", "qcow2", compressed=compressed) # Measure the image. img_measure = client.measure(img, fmt) # We don't add member info if member was not specified. assert "member-offset" not in img_measure assert "member-size" not in img_measure # Add test image to ova. member = os.path.basename(img) ova = str(tmpdir.join("ova")) with tarfile.open(ova, "w") as tar: tar.add(img, arcname=member) # Measure the image from the ova. ova_measure = client.measure(ova, fmt, member=member) # Measurement from ova should be same. assert ova_measure["required"] == img_measure["required"] assert ova_measure["fully-allocated"] == img_measure["fully-allocated"] # If member was specified, we report also the offset and size. with tarfile.open(ova) as tar: member_info = tar.getmember(member) assert ova_measure["member-offset"] == member_info.offset_data assert ova_measure["member-size"] == member_info.size