Skip to content

Commit f467a2d

Browse files
ppisarkontura
authored andcommitted
Rotating logger preserves file mode and ACL
This checks that the rotating logger preserves file mode and file access control list which a user set on the log file before executing dnf. It enables a test for the file mode and adds a new test for ACL. Because log rotation only works outside of installroot, it adds no_installroot tag to the tests. For: rpm-software-management/dnf5#1820 For: rpm-software-management/dnf5#2487
1 parent a2989c8 commit f467a2d

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

dnf-behave-tests/common/cmd.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import glob
88
import os
99

10-
from common.lib.cmd import assert_exitcode, run_in_context
10+
from common.lib.cmd import assert_exitcode, run, run_in_context
1111
from common.lib.file import prepend_installroot
1212

1313

@@ -59,3 +59,17 @@ def file_has_mode(context, filepath, octal_mode_str):
5959
octal_file_mode = os.stat(matched_files[0]).st_mode & 0o777
6060
assert oct(octal_mode) == oct(octal_file_mode), \
6161
"File \"{}\" has mode \"{}\"".format(matched_files[0], oct(octal_file_mode))
62+
63+
64+
@behave.step("file \"{filepath}\" has ACL entry \"{entry}\"")
65+
def file_has_acl_entry(context, filepath, entry):
66+
filepath = prepend_installroot(context, filepath)
67+
command = ["/usr/bin/getfacl", "-c", filepath]
68+
ret, out, err = run(command, shell=False)
69+
if ret != 0:
70+
raise AssertionError("Could not retrieve ACL: Command \"{}\" failed: "
71+
"{}".format(command.join(" "), err))
72+
for line in out.split("\n"):
73+
if line == entry:
74+
return
75+
raise AssertionError("File \"{}\" has ACL:\n{}".format(filepath, out))

dnf-behave-tests/dnf/log-rotate.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,34 @@ Scenario: Size and number of log files respects log_size and log_rotate options
2626
Then size of file "var/log/dnf5.log" is at most "1024"
2727
Then size of file "var/log/dnf5.log.1" is at most "1024"
2828
Then size of file "var/log/dnf5.log.2" is at most "1024"
29+
30+
31+
# Log rotation cannot work within installroot
32+
@no_installroot
33+
# https://github.com/rpm-software-management/dnf5/issues/1820
34+
@bz1910084
35+
Scenario: Log rotation keeps file permissions
36+
Given I use repository "dnf-ci-fedora-updates"
37+
And I successfully execute dnf with args "install flac"
38+
# Set permissions to 600
39+
And I successfully execute "chmod 600 /var/log/dnf5.log"
40+
# Run dnf again, so that files are rotated
41+
When I execute dnf with args "--setopt=log_size=1 --setopt=log_rotate=2 remove flac"
42+
Then the exit code is 0
43+
And file "/var/log/dnf5.log" has mode "600"
44+
And file "/var/log/dnf5.log.1" has mode "600"
45+
46+
47+
# Log rotation cannot work within installroot
48+
@no_installroot
49+
# https://github.com/rpm-software-management/dnf5/issues/2487
50+
Scenario: Log rotation keeps ACL
51+
Given I use repository "dnf-ci-fedora-updates"
52+
And I successfully execute dnf with args "install flac"
53+
# Set non-default ACL
54+
And I successfully execute "setfacl -m user:root:r /var/log/dnf5.log"
55+
# Run dnf again, so that files are rotated
56+
When I execute dnf with args "--setopt=log_size=1 --setopt=log_rotate=2 remove flac"
57+
Then the exit code is 0
58+
And file "/var/log/dnf5.log" has ACL entry "user:root:r--"
59+
And file "/var/log/dnf5.log.1" has ACL entry "user:root:r--"

dnf-behave-tests/dnf/logs.feature

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,3 @@ Given I use repository "dnf-ci-fedora-updates"
4646
Then the exit code is 0
4747
And file "/var/log/dnf5.log" has mode "600"
4848
Given I set umask to "0022"
49-
50-
51-
@xfail
52-
# https://github.com/rpm-software-management/dnf5/issues/1820
53-
@bz1910084
54-
Scenario: Log rotation keeps file permissions
55-
Given I use repository "dnf-ci-fedora-updates"
56-
And I successfully execute dnf with args "install flac"
57-
# Set permissions to 600
58-
And I successfully execute "chmod 600 {context.dnf.installroot}/var/log/dnf5.log"
59-
# Run dnf again, so that files are rotated
60-
When I execute dnf with args "--setopt=log_size=100 --setopt=log_rotate=2 remove flac"
61-
Then the exit code is 0
62-
And file "/var/log/dnf5.log" has mode "600"
63-
And file "/var/log/dnf5.log.1" has mode "600"

dnf-behave-tests/requirements.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ License: GPLv3
1616

1717

1818
# test suite dependencies
19+
BuildRequires: acl
1920
BuildRequires: attr
2021
BuildRequires: createrepo_c
2122
BuildRequires: fakeuname

0 commit comments

Comments
 (0)