From 3d70b68854a68ea944277e3ef092cba40d3fcdd4 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Nov 07 2022 17:43:41 +0000 Subject: [PATCH 1/5] test_flatpak_builder: use right metadata for runtime In the real Fedora runtime and elsewhere in the tests, we use f33 for the branch. Set a sdk ID so we can test that too. --- diff --git a/tests/test_flatpak_builder.py b/tests/test_flatpak_builder.py index 109368e..d4e4e7e 100644 --- a/tests/test_flatpak_builder.py +++ b/tests/test_flatpak_builder.py @@ -142,7 +142,8 @@ compose: - flatpak-runtime:f33 flatpak: id: org.fedoraproject.Platform - branch: stable + sdk: org.fedoraproject.Sdk + branch: f33 end-of-life: Fedora 33 is no longer supported end-of-life-rebase: org.fedoraproject.NewPlatform """ From 1994b17f65d514d8184c6eafa5e7bba6b55b3141 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Nov 07 2022 17:44:45 +0000 Subject: [PATCH 2/5] test_flatpak_builder: remove a stray print --- diff --git a/tests/test_flatpak_builder.py b/tests/test_flatpak_builder.py index d4e4e7e..27a93f0 100644 --- a/tests/test_flatpak_builder.py +++ b/tests/test_flatpak_builder.py @@ -247,7 +247,6 @@ def check_get_components(builder, tmpdir, manifest): manifest_lines = [l + "\n" for l in manifest.strip().split("\n")] expected_components = [c for c in parse_manifest(manifest_lines) if c['include']] - print(expected_components) components = builder.get_components(manifestfile) def flatten(components): From dc56d98e8ebb1706c170fabfa6077554d23f37e5 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Nov 07 2022 17:46:10 +0000 Subject: [PATCH 3/5] test_flatpak_builder: Fix contents of generated Flatpaks Instead of using the contents of the original filesystem, use the munged tarball output from _export_from_stream() --- diff --git a/tests/test_flatpak_builder.py b/tests/test_flatpak_builder.py index 27a93f0..c69974b 100644 --- a/tests/test_flatpak_builder.py +++ b/tests/test_flatpak_builder.py @@ -288,9 +288,7 @@ def test_app_basic(testapp_source, tmpdir): with open(tmpdir / "export.tar", "rb") as f: outfile, manifest_file = (builder._export_from_stream(f, close_stream=False)) - check_call(["gzip", tmpdir / "export.tar"]) - - builder.build_container(str(tmpdir / "export.tar.gz")) + builder.build_container(outfile) # libfoo from the module should be listed in builder.get_components() check_get_components(builder, tmpdir, dedent("""\ @@ -338,9 +336,7 @@ def test_runtime_basic(runtime_source, tmpdir): with open(tmpdir / "export.tar", "rb") as f: outfile, manifest_file = (builder._export_from_stream(f, close_stream=False)) - check_call(["gzip", tmpdir / "export.tar"]) - - builder.build_container(str(tmpdir / "export.tar.gz")) + builder.build_container(outfile) # builder.get_components() should not filter out any packages check_get_components(builder, tmpdir, dedent("""\ From 594b65bffe740f99a7ed1cef066210ae3e272cb2 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Nov 07 2022 18:49:26 +0000 Subject: [PATCH 4/5] test_flatpak_builder: Add checks on the generated OCI Do some basic checks on the generated OCI - does it have the right labels, the right filenames? --- diff --git a/tests/test_flatpak_builder.py b/tests/test_flatpak_builder.py index c69974b..d7eccd4 100644 --- a/tests/test_flatpak_builder.py +++ b/tests/test_flatpak_builder.py @@ -1,5 +1,8 @@ +from io import TextIOWrapper +import json import os from subprocess import check_call +import tarfile from textwrap import dedent import gi @@ -7,6 +10,7 @@ gi.require_version('Modulemd', '2.0') from gi.repository import Modulemd import pytest +from six.moves import configparser import yaml from flatpak_module_tools.flatpak_builder import ( @@ -256,6 +260,60 @@ def check_get_components(builder, tmpdir, manifest): assert flatten(components) == flatten(expected_components) +def check_exported_oci(oci_outdir, runtime=False): + with open(os.path.join(oci_outdir, "index.json")) as f: + index = json.load(f) + + # Load the manifest that describes the container + def descriptor_to_path(descriptor): + digest = descriptor["digest"] + assert digest.startswith("sha256:") + return os.path.join(oci_outdir, "blobs", "sha256", digest[7:]) + + with open(descriptor_to_path(index["manifests"][0])) as f: + manifest = json.load(f) + + # Get the labels for the container + with open(descriptor_to_path(manifest["config"])) as f: + config = json.load(f) + + labels = config["config"]["Labels"] + + if runtime: + assert labels["org.flatpak.ref"] == "runtime/org.fedoraproject.Platform/x86_64/f33" + else: + assert labels["org.flatpak.ref"] == "app/org.fedoraproject.TestApp/x86_64/stable" + + # Do some basic checks on the metadata label + metadata_from_labels = labels["org.flatpak.metadata"] + cp = configparser.RawConfigParser() + cp.read_string(metadata_from_labels) + + if runtime: + assert cp.get("Runtime", "runtime") == \ + "org.fedoraproject.Platform/x86_64/f33" + assert cp.get("Runtime", "sdk") == \ + "org.fedoraproject.Sdk/x86_64/f33" + else: + assert cp.get("Application", "runtime") == \ + "org.fedoraproject.Platform/x86_64/f33" + + # Now get the contents we built + tar = tarfile.open(descriptor_to_path(manifest["layers"][0]), "r:gz") + + # Check that that has the same metadata as the labels - the metadata + # file here will be used after installation + extracted = tar.extractfile("metadata") + assert extracted + metadata_stream = TextIOWrapper(extracted) + metadata_from_tarfile = metadata_stream.read() + metadata_stream.close() + assert metadata_from_tarfile == metadata_from_labels + + # And check that the bin/hello file we add for both the runtime and app is there + assert tar.getmember("files/bin/hello") is not None + + def test_app_basic(testapp_source, tmpdir): workdir = str(tmpdir / "work") os.mkdir(workdir) @@ -288,7 +346,7 @@ def test_app_basic(testapp_source, tmpdir): with open(tmpdir / "export.tar", "rb") as f: outfile, manifest_file = (builder._export_from_stream(f, close_stream=False)) - builder.build_container(outfile) + ref_name, oci_outdir, tarred_oci_outdir = builder.build_container(outfile) # libfoo from the module should be listed in builder.get_components() check_get_components(builder, tmpdir, dedent("""\ @@ -308,6 +366,8 @@ def test_app_basic(testapp_source, tmpdir): true testapp-fancymath-0:1-1.x86_64 """)) + check_exported_oci(oci_outdir, runtime=False) + def test_runtime_basic(runtime_source, tmpdir): workdir = str(tmpdir / "work") @@ -336,7 +396,7 @@ def test_runtime_basic(runtime_source, tmpdir): with open(tmpdir / "export.tar", "rb") as f: outfile, manifest_file = (builder._export_from_stream(f, close_stream=False)) - builder.build_container(outfile) + refname, oci_outdir, tarred_oci_outdir = builder.build_container(outfile) # builder.get_components() should not filter out any packages check_get_components(builder, tmpdir, dedent("""\ @@ -345,6 +405,8 @@ def test_runtime_basic(runtime_source, tmpdir): true libfoo-0:1.2.3-1.fc33.x86_64 """)) + check_exported_oci(oci_outdir, runtime=True) + def test_export_long_filenames(testapp_source, tmpdir): """ From 59d858869114f36ee69317fa22e61bf6de6f2b21 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Nov 07 2022 21:10:18 +0000 Subject: [PATCH 5/5] Allow overriding the architecture that FlatpakBuilder uses We want to allow cross-building and generating a Flatpak OCI for an architecture other than the current one - to enable this, allow FlatpakBuilder(..., oci_arch=