In SQLite state, use defaults for empty-string checks

As part of our database init, we perform a check of the current
values for a few fields (graph driver, graph root, static dir,
and a few more) to validate that Libpod is being started with a
sane & sensible config, and the user's containers can actually be
expected to work. Basically, we take the current runtime config
and compare against values cached in the database from the first
time Podman was run.

We've had some issues with this logic before this year around
symlink resolution, but this is a new edge case. Somehow, the
database is being loaded with the empty string for some fields
(at least graph driver) which is causing comparisons to fail
because we will never compare against "" for those fields - we
insert the default value instead, assuming we have one.

Having a value of "" in the database largely invalidates the
check so arguably we could just drop it, but what BoltDB did -
and what SQLite does after this patch - is to use the default
value for comparison instead of "". This should still catch some
edge cases, and shouldn't be too harmful.

What this does not do is identify or solve the reason that we are
seeing the empty string in the database at all. From my read on
the logic, it must mean that the graph driver is explicitly set
to "" in the c/storage config at the time Podman is first run and
I'm not precisely sure how that happens.

Fixes #24738

Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
Matt Heon
2024-12-05 08:35:36 -05:00
parent 1d06a1f8d5
commit cb53abca28
2 changed files with 47 additions and 0 deletions

View File

@@ -305,4 +305,27 @@ EOF
run_podman $safe_opts system reset --force
}
@test "podman - empty string defaults for certain values" {
skip_if_remote "Test uses nonstandard paths for c/storage directories"
# We just want this to be empty - so graph driver will be set to the empty string
touch $PODMAN_TMPDIR/storage.conf
safe_opts=$(podman_isolation_opts ${PODMAN_TMPDIR})
# Force all custom directories so we don't pick up an existing database
CONTAINERS_STORAGE_CONF=$PODMAN_TMPDIR/storage.conf run_podman 0+w $safe_opts info
require_warning "The storage 'driver' option should be set" \
"c/storage should warn on empty storage driver"
# Now add a valid graph driver to storage.conf
cat >$PODMAN_TMPDIR/storage.conf <<EOF
[storage]
driver="$(podman_storage_driver)"
EOF
# Second run of Podman should still succeed after editing the graph driver.
CONTAINERS_STORAGE_CONF=$PODMAN_TMPDIR/storage.conf run_podman $safe_opts info
}
# vim: filetype=sh