Skip to content

Commit 3b5fa42

Browse files
committed
add Github CI for waiver syntax check, fix waivers
Signed-off-by: Jiri Jaburek <[email protected]>
1 parent d1e767d commit 3b5fa42

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

.github/workflows/sanity.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Sanity self-tests
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
waivers-syntax-check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
- name: Install Contest deps
13+
run: sudo apt-get install -y python3-rpm
14+
- name: Collect waivers
15+
run: |
16+
python3 <<'EOF'
17+
import sys
18+
from lib import waive
19+
try:
20+
list(waive.collect_waivers())
21+
sys.exit(0)
22+
except waive.WaiveParseError as e:
23+
print(str(e))
24+
sys.exit(1)
25+
EOF

conf/waivers/30-permanent

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# we don't control partitions on the host OS
1919
/hardening/host-os/oscap/.+/mount_option_(home|opt|srv|var|var_log|var_log_audit|tmp)_(noexec|nosuid|nodev|usrquota|grpquota)
2020
/hardening/host-os/oscap/.+/mount_option_boot_efi_nosuid
21+
Match(True, sometimes=True)
2122

2223
# Beaker-specific, possibly;
2324
# same for dnf-automatic and rsyslog (??), is this fully random?

lib/waive.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ class WaiveParseError(SyntaxError):
4646
Easy waiver file syntax error reporting, with line numbers derived
4747
from _PushbackIterator style counter.
4848
"""
49-
def __init__(self, meta, msg):
50-
super().__init__(f"waiver line {meta.counter}: {msg}")
49+
def __init__(self, filedesc, msg):
50+
file, line = filedesc
51+
super().__init__(f"waiver {file}:{line}: {msg}")
5152

5253

5354
def _compile_eval(meta, code):
@@ -59,7 +60,7 @@ def _compile_eval(meta, code):
5960
raise WaiveParseError(meta, "compiling waiver python code failed")
6061

6162

62-
def _parse_waiver_file(stream):
63+
def _parse_waiver_file(stream, filename):
6364
sections = []
6465
regexes = set()
6566
python_code = ''
@@ -70,6 +71,7 @@ def _parse_waiver_file(stream):
7071
if line.startswith('#'):
7172
continue
7273
line = line.rstrip('\n')
74+
filedesc = (filename, lines.counter)
7375

7476
# between regex+python blocks
7577
if state == 'skipping_empty_lines':
@@ -82,19 +84,19 @@ def _parse_waiver_file(stream):
8284
# collecting adjacent/subsequent regex lines
8385
elif state == 'reading_regex':
8486
if not line:
85-
raise WaiveParseError(lines, "unexpected empty line between regexes")
87+
raise WaiveParseError(filedesc, "unexpected empty line between regexes")
8688

8789
# until we see an indented line (beginning with space), just collect
8890
# regex lines into a buffer
8991
if not line.startswith((' ', '\t')):
9092
try:
9193
regexes.add(re.compile(line))
9294
except re.error as e:
93-
raise WaiveParseError(lines, f"regex failed: {e}")
95+
raise WaiveParseError(filedesc, f"regex failed: {e}")
9496
else:
9597
# indented line found, which means it's a python code - parse it
9698
if not regexes:
97-
raise WaiveParseError(lines, "python block without a preceding regexp")
99+
raise WaiveParseError(filedesc, "python block without a preceding regexp")
98100
state = 'reading_python'
99101
lines.pushback()
100102

@@ -114,7 +116,7 @@ def _parse_waiver_file(stream):
114116
lines.pushback()
115117

116118
if regexes and not python_code:
117-
raise WaiveParseError(lines, "no python block follows the regexp")
119+
raise WaiveParseError(filedesc, "no python block follows the regexp")
118120

119121
# still inside last python block - the append & cleanup section did not
120122
# get to run because the iterator stopped because there was nothing left
@@ -126,7 +128,7 @@ def _parse_waiver_file(stream):
126128
return sections
127129

128130

129-
def _collect_waivers():
131+
def collect_waivers():
130132
"""
131133
Recursively walk a directory of waiver files/directories,
132134
yielding waiver sections.
@@ -148,8 +150,9 @@ def _collect_files(in_dir):
148150
yield item
149151

150152
for file in _collect_files(dir_path):
153+
relative = file.relative_to(dir_path)
151154
with open(file) as f:
152-
yield from _parse_waiver_file(f)
155+
yield from _parse_waiver_file(f, str(relative))
153156

154157

155158
class Match:
@@ -168,7 +171,7 @@ def __bool__(self):
168171
def match_result(status, name, note):
169172
global _sections_cache
170173
if _sections_cache is None:
171-
_sections_cache = list(_collect_waivers())
174+
_sections_cache = list(collect_waivers())
172175

173176
# make sure "'someting' in name" always works
174177
if name is None:

0 commit comments

Comments
 (0)