Skip to content

Commit 8d6eae4

Browse files
committed
test: Add some tests for AtomicUpdateCheck
See #1396
1 parent c2c5126 commit 8d6eae4

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

rpmlint/configdefaults.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Filters = []
3636
BlockedFilters = []
3737
# Treshold where we should error out, by default single error is enough
3838
BadnessThreshold = -1
39+
# Set to true to issue a warning for ghost entries outside snapshots
40+
# when checking for atomic update compatibility
41+
AtomicCheckGhosts = false
3942
# When checking that various files that should be compressed are
4043
# indeed compressed, look for this filename extension
4144
CompressExtension = "bz2"
@@ -213,6 +216,26 @@ DisallowedDirs = [
213216
"/var/run",
214217
"/var/tmp",
215218
]
219+
220+
# Only these directories may be used by packages compatible with
221+
# atomic updates
222+
AtomicAllowedDirs = [
223+
"/etc/",
224+
"/usr/",
225+
"/bin/",
226+
"/lib/",
227+
"/lib64/",
228+
"/sbin/",
229+
"/boot/",
230+
]
231+
232+
# List of subdirectories which are disallowed for atomic updates
233+
# despite being within otherwise allowed directories
234+
AtomicDisallowedSubdirs = [
235+
"/usr/local/",
236+
"/boot/efi/",
237+
]
238+
216239
# Standard OS groups
217240
StandardGroups = [
218241
"root",

test/test_atomic_update.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import pytest
2+
import rpm
3+
from rpmlint.checks.AtomicUpdateCheck import AtomicUpdateCheck
4+
from rpmlint.filter import Filter
5+
6+
from Testing import CONFIG, get_tested_mock_package
7+
8+
9+
@pytest.fixture(scope='function', autouse=True)
10+
def atomiccheck():
11+
CONFIG.info = True
12+
CONFIG.configuration['AtomicCheckGhosts'] = True
13+
output = Filter(CONFIG)
14+
test = AtomicUpdateCheck(CONFIG, output)
15+
yield output, test
16+
17+
18+
@pytest.fixture
19+
def output(atomiccheck):
20+
output, _test = atomiccheck
21+
yield output
22+
23+
24+
@pytest.fixture
25+
def test(atomiccheck):
26+
_output, test = atomiccheck
27+
yield test
28+
29+
30+
@pytest.mark.parametrize('package', [
31+
get_tested_mock_package(files=('/var/lib/pipewire',)),
32+
get_tested_mock_package(files=('/opt/bin/test',)),
33+
get_tested_mock_package(files=('/usr/local/bin/test',)),
34+
get_tested_mock_package(files=('/boot/efi/test',)),
35+
])
36+
def test_not_atomic(package, output, test):
37+
test.check(package)
38+
out = output.print_results(output.results)
39+
assert 'E: dir-or-file-outside-snapshot' in out
40+
41+
42+
@pytest.mark.parametrize('package', [
43+
get_tested_mock_package(files=('/etc/custom.config',)),
44+
get_tested_mock_package(files=('/usr/lib64/libc.so',)),
45+
get_tested_mock_package(files=('/usr/etc/nfs.conf',)),
46+
get_tested_mock_package(files=('/bin/test',)),
47+
get_tested_mock_package(files=('/sbin/test',)),
48+
get_tested_mock_package(files=('/lib/libc.so',)),
49+
get_tested_mock_package(files=('/lib64/libc.so',)),
50+
get_tested_mock_package(files=('/boot/grub2/grub.cfg',)),
51+
])
52+
def test_atomic(package, output, test):
53+
test.check(package)
54+
out = output.print_results(output.results)
55+
assert 'E: dir-or-file-outside-snapshot' not in out
56+
assert 'W: ghost-outside-snapshot' not in out
57+
58+
59+
@pytest.mark.parametrize('package', [
60+
get_tested_mock_package(files={
61+
'/var/lib/pipewire/ghost_file': {'metadata': {'flags': rpm.RPMFILE_GHOST}},
62+
}),
63+
])
64+
def test_not_atomic_ghost(package, output, test):
65+
test.check(package)
66+
out = output.print_results(output.results)
67+
assert 'W: ghost-outside-snapshot' in out

0 commit comments

Comments
 (0)