Skip to content

Commit f71755d

Browse files
committed
test: new syslog tests to verify regexp and comparison ops
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent c1b57c1 commit f71755d

File tree

11 files changed

+341
-0
lines changed

11 files changed

+341
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== Syslog Advanced Compare
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/ietf_syslog/advanced_compare]
4+
5+
==== Description
6+
7+
Verify the select-adv-compare feature: filtering syslog messages based on
8+
severity with advanced comparison operators (equals vs equals-or-higher) and
9+
actions (log vs block/stop).
10+
11+
==== Topology
12+
13+
image::topology.svg[Syslog Advanced Compare topology, align=center, scaledwidth=75%]
14+
15+
==== Sequence
16+
17+
. Set up topology and attach to target DUT
18+
. Clean up old log files from previous test runs
19+
. Configure syslog with advanced-compare
20+
. Send test messages at all severity levels
21+
. Verify exact-errors log contains only error messages
22+
. Verify no-debug log blocks all messages
23+
. Verify baseline log contains info and higher
24+
25+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python3
2+
"""Syslog Advanced Compare
3+
4+
Verify the select-adv-compare feature: filtering syslog messages based on
5+
severity with advanced comparison operators (equals vs equals-or-higher) and
6+
actions (log vs block/stop).
7+
8+
"""
9+
10+
import infamy
11+
import time
12+
13+
with infamy.Test() as test:
14+
with test.step("Set up topology and attach to target DUT"):
15+
env = infamy.Env()
16+
target = env.attach("target", "mgmt")
17+
tgtssh = env.attach("target", "mgmt", "ssh")
18+
19+
with test.step("Clean up old log files from previous test runs"):
20+
tgtssh.runsh("sudo rm -f /var/log/{exact-errors,no-debug,baseline}")
21+
22+
with test.step("Configure syslog with advanced-compare"):
23+
target.put_config_dicts({
24+
"ietf-syslog": {
25+
"syslog": {
26+
"actions": {
27+
"file": {
28+
"log-file": [{
29+
"name": "file:exact-errors",
30+
"facility-filter": {
31+
"facility-list": [{
32+
"facility": "daemon",
33+
"severity": "error",
34+
"advanced-compare": {
35+
"compare": "equals"
36+
}
37+
}]
38+
}
39+
}, {
40+
"name": "file:no-debug",
41+
"facility-filter": {
42+
"facility-list": [{
43+
"facility": "daemon",
44+
"severity": "debug",
45+
"advanced-compare": {
46+
"action": "block"
47+
}
48+
}]
49+
}
50+
}, {
51+
"name": "file:baseline",
52+
"facility-filter": {
53+
"facility-list": [{
54+
"facility": "daemon",
55+
"severity": "info"
56+
}]
57+
}
58+
}]
59+
}
60+
}
61+
}
62+
}
63+
})
64+
65+
with test.step("Send test messages at all severity levels"):
66+
tgtssh.runsh("logger -t advtest -p daemon.emerg 'Emergency: system is unusable'")
67+
tgtssh.runsh("logger -t advtest -p daemon.alert 'Alert: immediate action required'")
68+
tgtssh.runsh("logger -t advtest -p daemon.crit 'Critical: critical condition'")
69+
tgtssh.runsh("logger -t advtest -p daemon.err 'Error: error condition'")
70+
tgtssh.runsh("logger -t advtest -p daemon.warning 'Warning: warning condition'")
71+
tgtssh.runsh("logger -t advtest -p daemon.notice 'Notice: normal but significant'")
72+
tgtssh.runsh("logger -t advtest -p daemon.info 'Info: informational message'")
73+
tgtssh.runsh("logger -t advtest -p daemon.debug 'Debug: debug-level message'")
74+
time.sleep(1)
75+
76+
with test.step("Verify exact-errors log contains only error messages"):
77+
rc = tgtssh.runsh("grep -c 'advtest' /var/log/exact-errors 2>/dev/null")
78+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
79+
if count != 1:
80+
test.fail(f"Expected 1 message in /var/log/exact-errors (error only), got {count}")
81+
82+
rc = tgtssh.runsh("grep -q 'Error: error condition' /var/log/exact-errors 2>/dev/null")
83+
if rc.returncode != 0:
84+
test.fail("Expected error message in /var/log/exact-errors")
85+
86+
rc = tgtssh.runsh("grep -c 'Emergency\\|Alert\\|Critical' /var/log/exact-errors 2>/dev/null")
87+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
88+
if count != 0:
89+
test.fail(f"Expected 0 higher severity messages in /var/log/exact-errors, got {count}")
90+
91+
with test.step("Verify no-debug log blocks all messages"):
92+
rc = tgtssh.runsh("grep -c 'advtest' /var/log/no-debug 2>/dev/null")
93+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
94+
if count != 0:
95+
test.fail(f"Expected 0 messages in /var/log/no-debug (all blocked), got {count}")
96+
97+
with test.step("Verify baseline log contains info and higher"):
98+
rc = tgtssh.runsh("grep -c 'advtest' /var/log/baseline 2>/dev/null")
99+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
100+
if count != 7:
101+
test.fail(f"Expected 7 messages in /var/log/baseline (info and higher), got {count}")
102+
103+
rc = tgtssh.runsh("grep -c 'Debug: debug-level' /var/log/baseline 2>/dev/null")
104+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
105+
if count != 0:
106+
test.fail(f"Expected 0 debug messages in /var/log/baseline, got {count}")
107+
108+
rc = tgtssh.runsh("grep -q 'Info: informational' /var/log/baseline 2>/dev/null")
109+
if rc.returncode != 0:
110+
test.fail("Expected info message in /var/log/baseline")
111+
112+
test.succeed()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../infamy/topologies/1x1.dot
Lines changed: 33 additions & 0 deletions
Loading

test/case/ietf_syslog/all.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44

55
- name: Remote syslog
66
case: remote/test.py
7+
8+
- name: Syslog Pattern Matching
9+
case: pattern_match/test.py
10+
11+
- name: Syslog Advanced Compare
12+
case: advanced_compare/test.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== Syslog Pattern Matching
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/ietf_syslog/pattern_match]
4+
5+
==== Description
6+
7+
Verify the select-match feature: filtering syslog messages based on
8+
pattern-match (POSIX regex) on message content. Tests both simple
9+
substring matching and complex regex patterns.
10+
11+
==== Topology
12+
13+
image::topology.svg[Syslog Pattern Matching topology, align=center, scaledwidth=75%]
14+
15+
==== Sequence
16+
17+
. Set up topology and attach to target DUT
18+
. Clean up old log files from previous test runs
19+
. Configure syslog with pattern-match filters
20+
. Send test messages with various patterns
21+
. Verify errors log contains ERROR and CRITICAL messages
22+
. Verify routers log contains matching router[0-9]+ pattern
23+
. Verify all-messages log contains all test messages
24+
25+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Syslog Pattern Matching
4+
5+
Verify the select-match feature: filtering syslog messages based on
6+
pattern-match (POSIX regex) on message content. Tests both simple
7+
substring matching and complex regex patterns.
8+
"""
9+
10+
import infamy
11+
import time
12+
13+
with infamy.Test() as test:
14+
with test.step("Set up topology and attach to target DUT"):
15+
env = infamy.Env()
16+
target = env.attach("target", "mgmt")
17+
tgtssh = env.attach("target", "mgmt", "ssh")
18+
19+
with test.step("Clean up old log files from previous test runs"):
20+
tgtssh.runsh("sudo rm -f /var/log/{errors,routers,all-messages}")
21+
22+
with test.step("Configure syslog with pattern-match filters"):
23+
target.put_config_dicts({
24+
"ietf-syslog": {
25+
"syslog": {
26+
"actions": {
27+
"file": {
28+
"log-file": [{
29+
"name": "file:errors",
30+
"pattern-match": "ERROR|CRITICAL",
31+
}, {
32+
"name": "file:routers",
33+
"pattern-match": "router[0-9]+",
34+
"facility-filter": {
35+
"facility-list": [{
36+
"facility": "all",
37+
"severity": "info"
38+
}]
39+
}
40+
}, {
41+
"name": "file:all-messages",
42+
"facility-filter": {
43+
"facility-list": [{
44+
"facility": "all",
45+
"severity": "info"
46+
}]
47+
}
48+
}]
49+
}
50+
}
51+
}
52+
}
53+
})
54+
55+
with test.step("Send test messages with various patterns"):
56+
tgtssh.runsh("logger -t test -p daemon.info 'ERROR: Connection failed on interface eth0'")
57+
tgtssh.runsh("logger -t test -p daemon.info 'CRITICAL: System temperature high'")
58+
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router1: link up'")
59+
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router42: link down'")
60+
tgtssh.runsh("logger -t test -p daemon.info 'INFO: Normal operation message'")
61+
tgtssh.runsh("logger -t test -p daemon.info 'DEBUG: Verbose logging enabled'")
62+
time.sleep(1)
63+
64+
with test.step("Verify errors log contains ERROR and CRITICAL messages"):
65+
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL' /var/log/errors 2>/dev/null")
66+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
67+
if count != 2:
68+
test.fail(f"Expected 2 ERROR/CRITICAL messages in /var/log/errors, got {count}")
69+
70+
# Verify it does NOT contain other messages
71+
rc = tgtssh.runsh("grep -c 'router1\\|Normal operation\\|Verbose' /var/log/errors 2>/dev/null")
72+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
73+
if count != 0:
74+
test.fail(f"Expected 0 non-error messages in /var/log/errors, got {count}")
75+
76+
with test.step("Verify routers log contains matching router[0-9]+ pattern"):
77+
rc = tgtssh.runsh("grep -c 'router[0-9]\\+' /var/log/routers 2>/dev/null")
78+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
79+
if count != 2:
80+
test.fail(f"Expected 2 router messages in /var/log/routers, got {count}")
81+
82+
# Verify both router1 and router42 are present
83+
rc = tgtssh.runsh("grep -q 'router1' /var/log/routers 2>/dev/null")
84+
if rc.returncode != 0:
85+
test.fail("Expected router1 message in /var/log/routers")
86+
87+
rc = tgtssh.runsh("grep -q 'router42' /var/log/routers 2>/dev/null")
88+
if rc.returncode != 0:
89+
test.fail("Expected router42 message in /var/log/routers")
90+
91+
# Verify it does NOT contain error or normal messages
92+
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL\\|Normal operation\\|Verbose' /var/log/routers 2>/dev/null")
93+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
94+
if count != 0:
95+
test.fail(f"Expected 0 non-router messages in /var/log/routers, got {count}")
96+
97+
with test.step("Verify all-messages log contains all test messages"):
98+
rc = tgtssh.runsh("grep -c 'test' /var/log/all-messages 2>/dev/null")
99+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
100+
if count != 6:
101+
test.fail(f"Expected 6 total messages in /var/log/all-messages, got {count}")
102+
103+
test.succeed()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../infamy/topologies/1x1.dot

0 commit comments

Comments
 (0)