Tools: fetch image test case generation matrix from composer

Add a simple tool `osbuild-composer-image-definitions` which dumps the
matrix of all distributions, architectures and image types names
supported by composer as a JSON to the stdout.

Default to fetching the image test case generation matrix directly from
composer. This eliminates the need to update a JSON source file with
this information every time a new distro or image type are added to
composer.

Delete the previously used JSON source file with the image test case
generation matrix.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2022-02-23 21:03:46 +01:00 committed by Alexander Todorov
parent 035b616308
commit 40c095a850
3 changed files with 47 additions and 415 deletions

View file

@ -0,0 +1,35 @@
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
)
func main() {
definitions := map[string]map[string][]string{}
distroRegistry := distroregistry.NewDefault()
for _, distroName := range distroRegistry.List() {
distro := distroRegistry.GetDistro(distroName)
for _, archName := range distro.ListArches() {
arch, err := distro.GetArch(archName)
if err != nil {
panic(fmt.Sprintf("failed to get arch %q of distro %q listed in aches list", archName, distroName))
}
_, ok := definitions[distroName]
if !ok {
definitions[distroName] = map[string][]string{}
}
definitions[distroName][archName] = arch.ListImageTypes()
}
}
encoder := json.NewEncoder(os.Stdout)
err := encoder.Encode(definitions)
if err != nil {
panic(err)
}
}

View file

@ -1,409 +0,0 @@
{
"fedora-34": {
"x86_64": [
"ami",
"fedora-iot-commit",
"fedora-iot-container",
"fedora-iot-installer",
"openstack",
"qcow2",
"vhd",
"vmdk",
"oci"
],
"aarch64": [
"ami",
"fedora-iot-commit",
"fedora-iot-container",
"fedora-iot-installer",
"openstack",
"qcow2",
"oci"
]
},
"fedora-35": {
"x86_64": [
"ami",
"fedora-iot-commit",
"fedora-iot-container",
"fedora-iot-installer",
"openstack",
"qcow2",
"vhd",
"vmdk",
"oci"
],
"aarch64": [
"ami",
"fedora-iot-commit",
"fedora-iot-container",
"fedora-iot-installer",
"openstack",
"qcow2",
"oci"
]
},
"centos-8": {
"x86_64": [
"ami",
"gce",
"openstack",
"tar",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"openstack",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
]
},
"rhel-8": {
"x86_64": [
"ami",
"openstack",
"qcow2",
"rhel-edge-commit",
"tar",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"openstack",
"qcow2",
"rhel-edge-commit",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-84": {
"x86_64": [
"ami",
"gce",
"gce-rhui",
"openstack",
"tar",
"qcow2",
"rhel-edge-commit",
"rhel-edge-container",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"openstack",
"qcow2",
"rhel-edge-commit",
"rhel-edge-container",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2"
]
},
"rhel-85": {
"x86_64": [
"ami",
"azure-rhui",
"ec2",
"ec2-ha",
"gce",
"gce-rhui",
"openstack",
"tar",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"image-installer",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"openstack",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-86": {
"x86_64": [
"ami",
"azure-rhui",
"ec2",
"ec2-ha",
"ec2-sap",
"gce",
"gce-rhui",
"openstack",
"tar",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"openstack",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-87": {
"x86_64": [
"ami",
"azure-rhui",
"ec2",
"ec2-ha",
"ec2-sap",
"gce",
"gce-rhui",
"openstack",
"tar",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"openstack",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-90-beta": {
"x86_64": [
"ami",
"ec2",
"ec2-ha",
"ec2-sap",
"edge-commit",
"edge-container",
"image-installer",
"openstack",
"qcow2",
"tar",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"edge-commit",
"edge-container",
"openstack",
"qcow2",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-90": {
"x86_64": [
"ami",
"ec2",
"ec2-ha",
"ec2-sap",
"gce",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"openstack",
"qcow2",
"tar",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"openstack",
"qcow2",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"rhel-91": {
"x86_64": [
"ami",
"ec2",
"ec2-ha",
"ec2-sap",
"gce",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"openstack",
"qcow2",
"tar",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"ec2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"openstack",
"qcow2",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
},
"centos-9": {
"x86_64": [
"ami",
"gce",
"openstack",
"tar",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"vhd",
"vmdk"
],
"aarch64": [
"ami",
"openstack",
"qcow2",
"edge-commit",
"edge-container",
"edge-installer",
"edge-simplified-installer",
"image-installer",
"edge-simplified-installer",
"tar"
],
"ppc64le": [
"qcow2",
"tar"
],
"s390x": [
"qcow2",
"tar"
]
}
}

View file

@ -1390,7 +1390,7 @@ def get_args():
"--gen-matrix-file",
metavar="PATH",
help="JSON file with test case generation matrix (distro x arch x image type)." + \
" If not provided, '<script_location_dir>/distro-arch-imagetype-map.json' is read.",
" If not provided, the matrix is fetched directly from composer.",
type=os.path.abspath
)
parser.add_argument(
@ -1458,11 +1458,17 @@ def main(args):
if not os.path.isdir(output):
raise RuntimeError(f"output directory {output} does not exist")
script_dir = os.path.dirname(__file__)
gen_matrix_path = gen_matrix_file if gen_matrix_file else f"{script_dir}/distro-arch-imagetype-map.json"
log.info("Loading generation matrix from file: '%s'", gen_matrix_path)
with open(gen_matrix_path, "r") as gen_matrix_json:
gen_matrix_dict = json.load(gen_matrix_json)
if gen_matrix_file is None:
# load the matrix directly from composer
script_dir = os.path.dirname(__file__)
matrix_generator_path = os.path.join(script_dir, "../../cmd/osbuild-composer-image-definitions/main.go")
raw_output = subprocess.check_output(["go", "run", matrix_generator_path], encoding="UTF-8")
gen_matrix_dict = json.loads(raw_output)
else:
# read the matrix from a file
log.info("Loading generation matrix from file: '%s'", gen_matrix_file)
with open(gen_matrix_file, "r") as gen_matrix_json:
gen_matrix_dict = json.load(gen_matrix_json)
# Filter generation matrix based on passed arguments
for distro in list(gen_matrix_dict.keys()):