Skip to content

System tests: Update the journalctl function to ignore No entry message #26575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025

Conversation

ypu
Copy link
Contributor

@ypu ypu commented Jul 5, 2025

For currently version of journalctl, --user option only works when the persistent storage is enabled. So we need to check this option before we use it. Otherwise a set of tests will failed with can not find expected output from journalctl with rootless user.

Does this PR introduce a user-facing change?

NONE

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Jul 5, 2025
Copy link

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@ypu ypu force-pushed the journalctl branch 2 times, most recently from 2119a60 to 94fd8a6 Compare July 7, 2025 08:44
@ypu
Copy link
Contributor Author

ypu commented Jul 7, 2025

/release-note-none

@openshift-ci openshift-ci bot added release-note-none and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Jul 7, 2025
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

For currently version of journalctl, --user option only works when the persistent storage is enabled.

Do you have some docs for that? Because first of all my system uses Storage=auto which also works. In general config checks like that are a bad idea because systemd might change the behaviours. It is best to do a proper feature check.

Also why does --user-unit work but --user doesn't? I am a bit confused why you can read the system log but not the per user logs.

@@ -14,12 +14,44 @@ fi

mkdir -p $UNIT_DIR

journalctl_support_user() {
r_value=0
run systemd-analyze cat-config systemd/journald.conf | grep Storage
Copy link
Member

Choose a reason for hiding this comment

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

The pipe does not capture output here at all. $output is set by the run function and that does not output to stdout by default so the pipe cannot work.

Comment on lines 24 to 26
if [[ "$output" == "Storage=persistent" ]]; then
r_value=1
fi
Copy link
Member

Choose a reason for hiding this comment

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

If you actually have a drop in file cat-config prints all file outputs while this only catches one, so I am not sure this is is even correct.

I would suggest you do a proper function test instead by checking if journalctl --user returns logs and laso the result should be cached so we don't always run this command over and over again.

Lastly isn't this just inverse of what you are saying, 0 return should mean success but you return 1 instead which is super confusing for any caller.

systemctl() {
timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemctl $_DASHUSER "$@"
}

journalctl() {
timeout --foreground -v --kill=10 $PODMAN_TIMEOUT journalctl $_DASHUSER "$@"
if is_rootless and ! journalctl_support_user; then
Copy link
Member

Choose a reason for hiding this comment

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

you need to use && and not and, it would be news to me that and is accepted by bash and from a quick test it doesn't work for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for your reviewing. I am a little mess up with shell and python. And just test it with Fedora and RHEL 9.6 with should go to the if branch and didn’t find the problem in the code. Now the code is updated. Should work as expected.

@Luap99
Copy link
Member

Luap99 commented Jul 7, 2025

I still think checking the config file is the wrong approach, the default uses auto which also works fine. Your code cannot handle drop in files correctly either.

Would it not be much simpler to run something like journalctl --user -b -n1 -q and make sure the output is not empty, i.e. there is at least one log line logged?

Or maybe we should ask a different question. Is there any reason to use --user at all then if --user-unit works better? Could we not just use this all the time instead of complicating the code.

@ypu
Copy link
Contributor Author

ypu commented Jul 7, 2025

Hi @Luap99 Thanks for your reviewing. Actually this is found in our gating tests for 9.6. And I found this from the journactl man page:
`
SOURCE OPTIONS
The following options control where to read journal records from:

   --system, --user
       Show messages from system services and the kernel (with --system). Show messages from service of current user (with --user). If neither is specified, show all messages that the user can see.

       The --user option affects how --unit= arguments are treated. See --unit=.

       Note that --user only works if persistent logging is enabled, via the Storage= setting in journald.conf(5).

       Added in version 205.

`

And the systemd-analyze cat-config command is also pick from the journald.conf ‘s comments.

# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file (or a copy of it placed in
# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in
# the /etc/systemd/journald.conf.d/ directory. The latter is generally
# recommended. Defaults can be restored by simply deleting the main
# configuration file and all drop-ins located in /etc/.
#
# Use 'systemd-analyze cat-config systemd/journald.conf' to display the full config.

@ypu
Copy link
Contributor Author

ypu commented Jul 7, 2025

Just double confirmed that the journalctl --user actually works in Fedora even when the journald.conf is not set to any value. This may related with the systemd version in the system. Although this code will not failed, but will try to update the function for the support check.

@ypu ypu marked this pull request as draft July 7, 2025 16:42
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 7, 2025
@ypu ypu marked this pull request as ready for review July 8, 2025 09:39
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2025
@ypu
Copy link
Contributor Author

ypu commented Jul 8, 2025

Hi @Luap99
Updated the Pullreq based on your comments. Mainly changed in following items:

  1. Update the checking command by using “joruanlctl --user -b -n 1”
  2. Make the check only run once when we load the file and use a global variable JOURNALCTL_SUPPORT_USER for other functions to use it directly.

Test it with case “quadlet - basic” with both Fedora and RHEL 9.6 and test cases are passed in both host.

Can you help to review this again? Thanks a lot!

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Just small things but this is what I had in mind, thanks.

For currently version of journalctl, --user option only works when
the persistent storage is enabled. So we need to check this option
before we use it. Otherwise a set of tests will failed with can
not find expected output from journalctl with rootless user.

Signed-off-by: Yiqiao Pu <ypu@redhat.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

cc @timcoding1988

Copy link
Contributor

openshift-ci bot commented Jul 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, ypu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 8, 2025
@jankaluza
Copy link
Member

LGTM

Tested on my system where I could reproduce the issue without patch and it works correctly with patch.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit e28445e into containers:main Jul 11, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants