Skip to content

Commit

Permalink
wrappers: journal namespaces did not honor journal.persistent
Browse files Browse the repository at this point in the history
* wrappers: journal namespaces did not honor journal.persistent as the default value for 'Storage=' varies

* tests/core/persistent-journal-namespace: change a bit how we retried the command

* tests/core/persistent-journal-namespace: move cleanup to restore

* tests/core/persistent-journal-namespace: review feedback
  • Loading branch information
Meulengracht authored and mvo5 committed Sep 15, 2022
1 parent b6f5b6d commit d82fb99
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/core/persistent-journal-namespace/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
summary: Test journal.persistent core config option is honored by journal namespaces

# these systems do not support journal quota groups due to their old systemd versions.
# requires systemd v245+
systems:
- -ubuntu-core-16-*
- -ubuntu-core-18-*

prepare: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-journal-quota
snap set system experimental.quota-groups=true
tests.cleanup defer snap unset system experimental.quota-groups
restore: |
# Stop test service and cleanup
snap stop test-snapd-journal-quota.logger
snap remove-quota group-one
# disable persistent journal and reload the journal
rm -rf /var/log/journal
systemctl kill --signal=SIGUSR1 systemd-journald
execute: |
echo "Wait for first boot to be done"
snap wait system seed.loaded
echo "Precondition check, persistent journal is not available by default"
not test -e /var/log/journal
echo "Check that persistent journal can be enabled"
snap set core journal.persistent=true
test -e /var/log/journal/
test -e /var/log/journal/.snapd-created
# Create a journal quota group and set arbitrary limits
echo "Create a journal namespace with the logger snap in it"
snap set-quota group-one --journal-size=16MB --journal-rate-limit=100/10ms test-snapd-journal-quota
# this check relies on *anything* getting logged; enabling persistent
# journal writes an entry about journal size, which should be sufficient.
MACHINE_ID=$(cat /etc/machine-id)
retry -n 30 --wait 1 test -e "/var/log/journal/$MACHINE_ID"
echo "Starting service to fill namespace with logs"
snap start test-snapd-journal-quota.logger
# Verify the presence of the namespace log, and do this with retries as
# the logger writes onces every second
retry -n 5 sh -c "test -e /var/log/journal/$MACHINE_ID.snap-group-one"
echo "Check that persistent journal can be disabled"
snap set core journal.persistent=false
not test -e /var/log/journal
# Verify that, over a few seconds, nothing is created
# to make sure the namespace is not recreating the path
if retry -n 2 sh -c "test -e /var/log/journal"; then
echo "Journal path was recreated, it shouldn't have happened"
exit 1
fi
7 changes: 7 additions & 0 deletions wrappers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,15 @@ func generateJournaldConfFile(grp *quota.Group) []byte {

sizeOptions := formatJournalSizeConf(grp)
rateOptions := formatJournalRateConf(grp)
// Set Storage=auto for all journal namespaces we create. This is
// the setting for the default namespace, and 'persistent' is the default
// setting for all namespaces. However we want namespaces to honor the
// journal.persistent setting, and this only works if Storage is set
// to 'auto'.
// See https://www.freedesktop.org/software/systemd/man/journald.conf.html#Storage=
template := `# Journald configuration for snap quota group %[1]s
[Journal]
Storage=auto
`
buf := bytes.Buffer{}
fmt.Fprintf(&buf, template, grp.Name)
Expand Down
3 changes: 3 additions & 0 deletions wrappers/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ WantedBy=multi-user.target
)
jconfTempl := `# Journald configuration for snap quota group %s
[Journal]
Storage=auto
`

sliceTempl := `[Unit]
Expand Down Expand Up @@ -663,6 +664,7 @@ WantedBy=multi-user.target
)
jconfTempl := `# Journald configuration for snap quota group %s
[Journal]
Storage=auto
SystemMaxUse=10485760
RuntimeMaxUse=10485760
RateLimitIntervalSec=5000000us
Expand Down Expand Up @@ -769,6 +771,7 @@ WantedBy=multi-user.target
)
jconfTempl := `# Journald configuration for snap quota group %s
[Journal]
Storage=auto
RateLimitIntervalSec=0us
RateLimitBurst=0
`
Expand Down

0 comments on commit d82fb99

Please sign in to comment.