The generate-test-cases no longer maps from output format to boot type. Instead, the boot data is passed in through the standard input alongside the composer-request object.
70 lines
2.5 KiB
Python
Executable file
70 lines
2.5 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import subprocess
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
'''
|
|
This script generates a json test case. It accepts a test_case_request as input through standard input.
|
|
|
|
{
|
|
"boot": {
|
|
"type": "qemu"
|
|
},
|
|
"compose-request": {
|
|
"distro": "fedora-30",
|
|
"arch": "x86_64",
|
|
"output-format": "qcow2",
|
|
"filename": "disk.qcow2",
|
|
"blueprint": {}
|
|
}
|
|
}
|
|
|
|
It then outputs a json test case as standard output.
|
|
'''
|
|
|
|
|
|
def run_osbuild(manifest, store):
|
|
osbuild_cmd = ["osbuild", "--store", store, "--json", "-"]
|
|
result = json.loads(subprocess.check_output(osbuild_cmd, encoding="utf-8", input=json.dumps(manifest)))
|
|
return result.get("output_id")
|
|
|
|
|
|
def main(test_case, store):
|
|
boot_type = test_case["boot"]["type"]
|
|
compose_request = test_case["compose-request"]
|
|
|
|
blueprint = json.dumps(compose_request["blueprint"])
|
|
|
|
pipeline_command = ["go", "run", "./cmd/osbuild-pipeline", "-distro", compose_request["distro"], "-arch", compose_request["arch"], "-image-type", compose_request["output-format"], "-"]
|
|
test_case["manifest"] = json.loads(subprocess.check_output(pipeline_command, input=blueprint, encoding="utf-8"))
|
|
|
|
pipeline_command = ["go", "run", "./cmd/osbuild-pipeline", "-distro", compose_request["distro"], "-arch", compose_request["arch"], "-image-type", compose_request["output-format"], "-rpmmd", "-"]
|
|
test_case["rpmmd"] = json.loads(subprocess.check_output(pipeline_command, input=blueprint, encoding="utf-8"))
|
|
|
|
if boot_type != "nspawn-extract":
|
|
output_id = run_osbuild(test_case["manifest"], store)
|
|
image_file = os.path.join(store, "refs", output_id, compose_request["filename"])
|
|
|
|
# we don't yet support image-info on directory trees
|
|
if boot_type == "qemu-extract":
|
|
fn, ex = os.path.splitext(image_file)
|
|
if ex == ".xz":
|
|
with open(fn, "w") as f:
|
|
subprocess.run(["xz", "--decompress", "--stdout", image_file], stdout=f)
|
|
image_file = fn
|
|
test_case["image-info"] = json.loads(subprocess.check_output(["tools/image-info", image_file]))
|
|
|
|
return test_case
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description="Generate test cases")
|
|
parser.add_argument("store", metavar="DIRECTORY", type=os.path.abspath, help="path to the osbuild store")
|
|
args = parser.parse_args()
|
|
test_case_request = json.load(sys.stdin)
|
|
test_case = main(test_case_request, args.store)
|
|
sys.stdout.write(json.dumps(test_case))
|
|
sys.exit()
|