Skip to content

Commit c7114bd

Browse files
committed
test/imgtestlib: capture the build log output
Now that we're building all images on the same runner, the log becomes too long and noisy and hits the limits of the CI log length. Capture build log output and errors and store them in a path that will be used as a CI artifact we can review. Note that runcmd() will print stdout and stderr when a command fails.
1 parent ba18f7e commit c7114bd

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

test/scripts/imgtestlib/build.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from typing import Dict
44

55
from .gitlab import log_section
6-
from .run import runcmd, runcmd_nc
6+
from .run import runcmd
77
from .testenv import get_host_distro, get_osbuild_commit, rng_seed_env
88

9+
BUILD_LOG_PATH = "/tmp/logs"
10+
911

1012
@log_section("Building image")
1113
def build_image(distro, arch, image_type, config_path):
@@ -21,7 +23,10 @@ def build_image(distro, arch, image_type, config_path):
2123

2224
cmd = ["sudo", "-E", "./bin/build", "--output", "./build", "--checkpoints", "build",
2325
"--distro", distro, "--arch", arch, "--type", image_type, "--config", config_path]
24-
runcmd_nc(cmd, extra_env=rng_seed_env())
26+
stdout, stderr = runcmd(cmd, extra_env=rng_seed_env())
27+
28+
build_name = gen_build_name(distro, arch, image_type, config_name)
29+
save_logs(build_name, stdout, stderr)
2530

2631
# Build artifacts are owned by root. Make them world accessible.
2732
runcmd(["sudo", "chmod", "a+rwX", "-R", "./build"])
@@ -85,3 +90,14 @@ def gen_build_name(distro, arch, image_type, config_name):
8590

8691
def _u(s):
8792
return s.replace("-", "_")
93+
94+
95+
def save_logs(build_name, out, err):
96+
"""
97+
Save stdout and stderr output for a job to the BUILD_LOG_PATH.
98+
"""
99+
os.makedirs(BUILD_LOG_PATH, exist_ok=True)
100+
with open(os.path.join(BUILD_LOG_PATH, f"{build_name}.out"), mode="w", encoding="utf-8") as log:
101+
log.write(out.decode())
102+
with open(os.path.join(BUILD_LOG_PATH, f"{build_name}.err"), mode="w", encoding="utf-8") as log:
103+
log.write(err.decode())

0 commit comments

Comments
 (0)