image-info: show format version for qcow2

Change the "image-format" from a string to a dict, with a "type":
$value entry, where $value contains the previous plain string
data.
Additionally, include the qcow2 format version, if the given
image is indeed a qcow2.
Adapt all manifest test accordingly (partly done by Ondřej)

Python 3 script used for conversion of manifest tests:
import os
import json

for name in os.listdir(os.getcwd()):
    if not name.endswith(".json"):
        continue
    print(name)
    with open(name, "r") as old:
        data = json.load(old)
        info = data.get("image-info", {})
        format = info.get("image-format")
        if not format:
            continue
        info["image-format"] = {
            "type": format
        }
        if format != "qcow2":
            continue
        info["image-format"]["compat"] = "1.1"
        with open(name + ".new", "w") as new:
            json.dump(data, new, indent=2)
            new.write("\n")
            new.flush()
    os.rename(name+".new", name)

test: use the new image-info format in all test manifests

The previous commit converted only qcow2 and openstack manifests but this change
is actually needed for all manifests produced by the qemu assembler.

Co-Developed-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Christian Kellner 2021-04-07 17:35:25 +00:00 committed by Ondřej Budai
parent 41fdfbd168
commit 5937b9adca
49 changed files with 179 additions and 50 deletions

View file

@ -152,7 +152,11 @@ def subprocess_check_output(argv, parse_fn=None):
def read_image_format(device):
qemu = subprocess_check_output(["qemu-img", "info", "--output=json", device], json.loads)
return qemu["format"]
format = qemu["format"]
result = {"type": format}
if format == "qcow2":
result["compat"] = qemu["format-specific"]["data"]["compat"]
return result
def read_partition(device, partition):