assemblers/qemu: add raw.xz format
Amazon images are sometimes delivered as `raw.xz` format. Use compression level of `-0`, which seems to be what Red Hat is using for cloud images.
This commit is contained in:
parent
40cd95dbf3
commit
2a1f49c8fa
2 changed files with 27 additions and 11 deletions
|
|
@ -89,7 +89,7 @@ def main(tree, output_dir, options, loop_client):
|
|||
if size % 512 != 0:
|
||||
raise ValueError("`size` must be a multiple of sector size (512)")
|
||||
|
||||
if fmt not in ["raw", "qcow2", "vdi", "vmdk", "vpc"]:
|
||||
if fmt not in ["raw", "raw.xz", "qcow2", "vdi", "vmdk", "vpc"]:
|
||||
raise ValueError("`format` must be one of raw, qcow, vdi, vmdk, vpc")
|
||||
|
||||
if root_fs_type == "ext4":
|
||||
|
|
@ -156,15 +156,26 @@ def main(tree, output_dir, options, loop_client):
|
|||
with mount(loop) as mountpoint:
|
||||
subprocess.run(["cp", "-a", f"{tree}/.", mountpoint], check=True)
|
||||
|
||||
extra_args = {
|
||||
"raw": [],
|
||||
"qcow2": ["-c"],
|
||||
"vdi": [],
|
||||
"vmdk": ["-c"],
|
||||
"vpc": ["-o", "subformat=fixed,force_size"]
|
||||
}
|
||||
|
||||
subprocess.run(["qemu-img", "convert", "-O", fmt, *extra_args[fmt], image, f"{output_dir}/{filename}"], check=True)
|
||||
if fmt == "raw":
|
||||
subprocess.run(["cp", image, f"{output_dir}/{filename}"], check=True)
|
||||
elif fmt == "raw.xz":
|
||||
with open(f"{output_dir}/{filename}", "w") as f:
|
||||
subprocess.run(["xz", "--keep", "--stdout", "-0", image], stdout=f, check=True)
|
||||
else:
|
||||
extra_args = {
|
||||
"qcow2": ["-c"],
|
||||
"vdi": [],
|
||||
"vmdk": ["-c"],
|
||||
"vpc": ["-o", "subformat=fixed,force_size"]
|
||||
}
|
||||
subprocess.run([
|
||||
"qemu-img",
|
||||
"convert",
|
||||
"-O", fmt,
|
||||
*extra_args[fmt],
|
||||
image,
|
||||
f"{output_dir}/{filename}"
|
||||
], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -77,8 +77,9 @@ class TestAssemblers(osbuildtest.TestCase):
|
|||
self.assertFilesystem(image, options["root_fs_uuid"], "ext4", tree_id)
|
||||
|
||||
def test_qemu(self):
|
||||
for fmt in ["raw", "qcow2", "vmdk", "vdi"]:
|
||||
for fmt in ["raw", "raw.xz", "qcow2", "vmdk", "vdi"]:
|
||||
with self.subTest(fmt=fmt):
|
||||
print(f" {fmt}", flush=True)
|
||||
options = {
|
||||
"format": fmt,
|
||||
"filename": f"image.{fmt}",
|
||||
|
|
@ -88,6 +89,10 @@ class TestAssemblers(osbuildtest.TestCase):
|
|||
}
|
||||
tree_id, output_id = self.run_assembler("org.osbuild.qemu", options)
|
||||
image = f"{self.store}/refs/{output_id}/image.{fmt}"
|
||||
if fmt == "raw.xz":
|
||||
subprocess.run(["unxz", image], check=True)
|
||||
image = image[:-3]
|
||||
fmt = "raw"
|
||||
self.assertImageFile(image, fmt, options["size"])
|
||||
with nbd_connect(image) as device:
|
||||
self.assertPartitionTable(device, "dos", options["ptuuid"], 1, boot_partition=1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue