Skip to content

Commit

Permalink
test: add test that ensure disk space is doubled
Browse files Browse the repository at this point in the history
Ensure that the disk size of a container is taken into account
when the image is generated. The current heuristic is that we
just double the container size.

The test will not build an image just generate a manifest and
check that the image file is generated with the expected size.
  • Loading branch information
mvo5 committed Mar 20, 2024
1 parent 1cb9a99 commit 2a1d06e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bib/internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"os"
"path/filepath"

"golang.org/x/sys/unix"

"github.com/osbuild/bootc-image-builder/bib/internal/podmanutil"
"github.com/osbuild/bootc-image-builder/bib/internal/util"
"golang.org/x/sys/unix"
)

// EnsureEnvironment mutates external filesystem state as necessary
Expand Down
47 changes: 46 additions & 1 deletion test/test_manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import subprocess
import textwrap

import pytest

Expand All @@ -10,10 +11,20 @@
if not testutil.can_start_rootful_containers():
pytest.skip("tests require to be able to run rootful containers (try: sudo)", allow_module_level=True)

from containerbuild import build_container_fixture # noqa: F401
from containerbuild import build_container_fixture, make_container # noqa: F401
from testcases import gen_testcases


def find_image_size_from(manifest_str):
manifest = json.loads(manifest_str)
for pipl in manifest["pipelines"]:
if pipl["name"] == "image":
for st in pipl["stages"]:
if st["type"] == "org.osbuild.truncate":
return st["options"]["size"]
raise ValueError(f"cannot find disk size in manifest:\n{manifest_str}")


@pytest.mark.parametrize("testcase_ref", gen_testcases("manifest"))
def test_manifest_smoke(build_container, testcase_ref):
# testcases_ref has the form "container_url,img_type1+img_type2,arch"
Expand All @@ -30,3 +41,37 @@ def test_manifest_smoke(build_container, testcase_ref):
# just some basic validation
assert manifest["version"] == "2"
assert manifest["pipelines"][0]["name"] == "build"
# default disk size is 10G
disk_size = find_image_size_from(output)
# default image size is 10G
assert int(disk_size) == 10 * 1024 * 1024 * 1024


@pytest.mark.parametrize("testcase_ref", gen_testcases("manifest"))
def test_manifest_disksize(tmp_path, build_container, testcase_ref):
# create derrived container with 6G silly file to ensure that
# bib doubles the size to 12G+
cntf_path = tmp_path / "Containerfile"
cntf_path.write_text(textwrap.dedent(f"""\n
FROM {testcase_ref}
RUN truncate -s 2G /big-file1
RUN truncate -s 2G /big-file2
RUN truncate -s 2G /big-file3
"""), encoding="utf8")

print(f"building big size container from {testcase_ref}")
with make_container(tmp_path) as container_tag:
print(f"using {container_tag}")
manifest_str = subprocess.check_output([
"podman", "run", "--rm",
"--privileged",
"--security-opt", "label=type:unconfined_t",
# ensure local storage is here
"-v", "/var/lib/containers/storage:/var/lib/containers/storage",
# need different entry point
f'--entrypoint=["/usr/bin/bootc-image-builder", "manifest", "--local", "localhost/{container_tag}"]',
build_container,
], encoding="utf8")
# ensure disk size is bigger than the default 10G
disk_size = find_image_size_from(manifest_str)
assert int(disk_size) > 11_000_000_000

0 comments on commit 2a1d06e

Please sign in to comment.