Skip to content

Break down imgtestlib module and use log sections#2383

Merged
brlane-rht merged 15 commits into
osbuild:mainfrom
achilleas-k:breakdown/imgtestlib
May 29, 2026
Merged

Break down imgtestlib module and use log sections#2383
brlane-rht merged 15 commits into
osbuild:mainfrom
achilleas-k:breakdown/imgtestlib

Conversation

@achilleas-k
Copy link
Copy Markdown
Member

This PR splits out the commits from #2359 that do not change the test pipelines.

Changes

  • Break down imgtestlib into multiple files. The single file was getting a bit too big and harder to navigate.
  • Move the core of some test scripts into the library. Scripts like build-image and boot-image are now thin wrappers around functions in imgtestlib that handle command line arguments.
  • Use foldable log sections when running in Gitlab CI. This should make test logs easier to read.

- E252 missing whitespace around parameter equals
- E713 test for membership should be 'not in'
- E302 expected 2 blank lines, found 1
@achilleas-k achilleas-k requested review from a team and thozza as code owners May 28, 2026 14:41
@achilleas-k achilleas-k force-pushed the breakdown/imgtestlib branch 3 times, most recently from 8e1aa38 to 0e4f74c Compare May 28, 2026 17:18
@achilleas-k
Copy link
Copy Markdown
Member Author

The cross-arch test keeps build x86_64 images. Hang on...

Make the image building scaffolding reusable.
Add functions for printing a log section start and end line..  If
running in GitLab CI, use their custom collapsible sections escape
sequences [1] to create collapsible build logs.

[1] https://docs.gitlab.com/ci/jobs/job_logs/#custom-collapsible-sections
Move imgtestlib.py to an importable module directory by the same
(logical) name.
The module got too big for one file.

This commit only moves code around and adjusts imports.  Functions are
grouped into submodules by logical functionality.  Groups (submodule
boundaries) were chosen to avoid circular imports.

The .core module could still use some splitting or tidying up, but the
current state is already an improvement.

Importing everything into __init__.py might be unnecessary—we only
really need to import the functions that are used externally—but it's
not very important to reduce the API surface of this internal testing
library.
Make them easier to see in the log.
The boot-image script is now a thin wrapper around the new
imgtestlib.boot_image() function, so the general functionality is
reusable.  The boot-image script now simply handles argument parsing and
calls into the function.

The can_boot_test() function has been moved to imgtestlib/core to avoid
circular imports.  We might need to reorganise the module at a later
date.
The upload-results script is now a thin wrapper around the new
imgtestlib.upload_results() function, so the general functionality is
reusable.  The upload-results script now simply handles argument parsing
and calls into the function.
Let's test everything!
boto3 is only needed when interfacing with aws.  vmtest is imported by
imgtestlib, which we often use for a lot of other smaller tasks, like
setting up the osbuild repo.  We could install boto3 whenever we need
it, but it's simpler to allow importing without it.
Since we moved core parts of the test scripts into the imgtestlib
module, the boot_image function now needs to be importable by all the
distros we support and test on, including EL9 which only has Python 3.9.
This wasn't an issue before because boot-image was only ever run on the
CI runners, which are currently Fedora 42.  Now that the core
functionality is part of the importable module though, we need to
rewrite it to run on older Python versions.
Support decorating functions with a log section context.  This creates a
log section at the start of the function that exits automatically at the
end of the function.
Use the log_section decorator to print the section start and end lines
when entering and exiting certain functions.  This makes the names of
log sections static, where previously we could print specific values
like the name or configuration of the image being built.  While it would
be nice to have this kind of information in the names of sections, I
think the decorator solution is cleaner in code and the downside of
having static log section names overall isn't too bad.
The script reads environment variables to determine if it's running in
Gitlab, so we need to preserve the environment when running with sudo.
brlane-rht
brlane-rht previously approved these changes May 28, 2026
Copy link
Copy Markdown
Contributor

@brlane-rht brlane-rht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good!

lzap
lzap previously approved these changes May 29, 2026
Copy link
Copy Markdown
Contributor

@lzap lzap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, the context is quite important because unclosed sections mess up the output quite a bit. I would also recommend to make a unique ID because if someone logs Test section twice it is very messed up. I think you could use some internal Python thing maybe stackframe or something to calculate some hash or something.

@achilleas-k
Copy link
Copy Markdown
Member Author

achilleas-k commented May 29, 2026

I would also recommend to make a unique ID

It creates a UUID for each section / context.

@lzap
Copy link
Copy Markdown
Contributor

lzap commented May 29, 2026

Ah now I see it, my implementation was bash based, this has a context! Clever. Nice.

The beta repos are showing the same behaviour that was discovered before
with 10.1 and 10.2.

osbuild#2044 (comment)
@achilleas-k
Copy link
Copy Markdown
Member Author

RHEL 10.3 beta repos are experiencing the same issue we say when we first added the network-installer tests (#2044 (comment)).
Disabling 10.3 as well now. Will check back on them later: https://redhat.atlassian.net/browse/HMS-10750.

I'll also open a follow-up PR to enable testing on 10.1 and 10.2 since those should be working normally now.

Copy link
Copy Markdown
Member

@supakeen supakeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better.

@lzap lzap added this pull request to the merge queue May 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 29, 2026
@brlane-rht brlane-rht added this pull request to the merge queue May 29, 2026
Merged via the queue into osbuild:main with commit 8dcf4ff May 29, 2026
45 checks passed
@achilleas-k achilleas-k deleted the breakdown/imgtestlib branch May 29, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants