Skip to content

Commit c3960a8

Browse files
committed
test: Add some tests for AtomicUpdateCheck
See #1396
1 parent de1e415 commit c3960a8

2 files changed

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

0 commit comments

Comments
 (0)