Skip to content

Commit b99e42b

Browse files
committed
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. Because behave fails to execute multiple no_installroot scenarios from one feature file, it moves them into separate files. For: rpm-software-management/dnf5#1820 For: rpm-software-management/dnf5#2487
1 parent 65d81fb commit b99e42b

File tree

5 files changed

+47
-16
lines changed

5 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))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Log rotation and ACL
2+
3+
# Log rotation cannot work within installroot
4+
@no_installroot
5+
# https://github.com/rpm-software-management/dnf5/issues/2487
6+
Scenario: Log rotation keeps ACL
7+
Given I use repository "dnf-ci-fedora-updates"
8+
And I successfully execute dnf with args "install flac"
9+
# Set non-default ACL
10+
And I successfully execute "setfacl -m user:root:r /var/log/dnf5.log"
11+
# Run dnf again, so that files are rotated
12+
When I execute dnf with args "--setopt=log_size=1 --setopt=log_rotate=2 remove flac"
13+
Then the exit code is 0
14+
And file "/var/log/dnf5.log" has ACL entry "user:root:r--"
15+
And file "/var/log/dnf5.log.1" has ACL entry "user:root:r--"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: Log rotation and file mode
2+
3+
# Log rotation cannot work within installroot
4+
@no_installroot
5+
# https://github.com/rpm-software-management/dnf5/issues/1820
6+
@bz1910084
7+
Scenario: Log rotation keeps file permissions
8+
Given I use repository "dnf-ci-fedora-updates"
9+
And I successfully execute dnf with args "install flac"
10+
# Set permissions to 600
11+
And I successfully execute "chmod 600 /var/log/dnf5.log"
12+
# Run dnf again, so that files are rotated
13+
When I execute dnf with args "--setopt=log_size=1 --setopt=log_rotate=2 remove flac"
14+
Then the exit code is 0
15+
And file "/var/log/dnf5.log" has mode "600"
16+
And file "/var/log/dnf5.log.1" has mode "600"

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)