Skip to content

Commit 2ad2348

Browse files
committed
test: syslog: new test, rpc_log, verify infix-syslog:log RPC
Log to an RFC 5424 formatted file and check app-name, msgid, and structured data land in the header, and that a bare message gets the default app-name with empty msgid and structured data. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 2079abb commit 2ad2348

6 files changed

Lines changed: 170 additions & 0 deletions

File tree

‎test/case/syslog/all.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
- name: Syslog Property Filtering
1818
case: property_filter/test.py
19+
20+
- name: Syslog Log RPC
21+
case: rpc_log/test.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc

‎test/case/syslog/rpc_log/test.adoc‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== Syslog Log RPC
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/syslog/rpc_log]
4+
5+
==== Description
6+
7+
Verify the infix-syslog:log RPC, used by the test system to inject
8+
markers in a DUT's system log. A message logged with the full RFC 5424
9+
header must show up in an RFC 5424 formatted log file with the given
10+
app-name, msgid, and structured data. A message logged with only the
11+
mandatory text must fall back to the documented defaults.
12+
13+
==== Topology
14+
15+
image::topology.svg[Syslog Log RPC topology, align=center, scaledwidth=75%]
16+
17+
==== Sequence
18+
19+
. Set up topology and attach to target DUT
20+
. Clean up old log file from previous test runs
21+
. Configure an RFC 5424 formatted log file for all facilities
22+
. Log message with severity, facility, app-name, msgid, and structured data
23+
. Verify RFC 5424 header fields of the logged message
24+
. Log message with only the mandatory text
25+
. Verify default app-name is set and msgid and structured data are empty
26+
27+

‎test/case/syslog/rpc_log/test.py‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
"""Syslog Log RPC
3+
4+
Verify the infix-syslog:log RPC, used by the test system to inject
5+
markers in a DUT's system log. A message logged with the full RFC 5424
6+
header must show up in an RFC 5424 formatted log file with the given
7+
app-name, msgid, and structured data. A message logged with only the
8+
mandatory text must fall back to the documented defaults.
9+
10+
"""
11+
12+
import re
13+
14+
import infamy
15+
from infamy.util import parallel, until
16+
17+
LOG_FILE = "/var/log/rpc-log"
18+
19+
20+
def logfile():
21+
"""Return contents of the RFC 5424 test log file, or empty string"""
22+
rc = tgtssh.runsh(f"cat {LOG_FILE} 2>/dev/null")
23+
return rc.stdout if rc.returncode == 0 else ""
24+
25+
26+
with infamy.Test() as test:
27+
with test.step("Set up topology and attach to target DUT"):
28+
env = infamy.Env()
29+
target, tgtssh = parallel(lambda: env.attach("target", "mgmt"),
30+
lambda: env.attach("target", "mgmt", "ssh"))
31+
32+
with test.step("Clean up old log file from previous test runs"):
33+
tgtssh.runsh(f"sudo rm -f {LOG_FILE}")
34+
35+
with test.step("Configure an RFC 5424 formatted log file for all facilities"):
36+
target.put_config_dicts({
37+
"ietf-syslog": {
38+
"syslog": {
39+
"actions": {
40+
"file": {
41+
"log-file": [{
42+
"name": f"file:{LOG_FILE}",
43+
"infix-syslog:log-format": "rfc5424",
44+
"facility-filter": {
45+
"facility-list": [{
46+
"facility": "all",
47+
"severity": "info"
48+
}]
49+
}
50+
}]
51+
}
52+
}
53+
}
54+
}
55+
})
56+
until(lambda: tgtssh.runsh(f"test -f {LOG_FILE}").returncode == 0, attempts=10)
57+
58+
with test.step("Log message with severity, facility, app-name, msgid, and structured data"):
59+
target.log("Kilroy was here", severity="warning", facility="daemon",
60+
app_name="infamy", msgid="test-start",
61+
sd={"test@32473": {"name": "rpc_log", "step": "3"}})
62+
until(lambda: "Kilroy was here" in logfile(), attempts=10)
63+
64+
with test.step("Verify RFC 5424 header fields of the logged message"):
65+
line = [ln for ln in logfile().splitlines() if "Kilroy was here" in ln][0]
66+
if not re.search(r"\binfamy - test-start \[test@32473 [^]]*\] Kilroy was here$", line):
67+
test.fail(f"Unexpected app-name, msgid, or structured data: {line}")
68+
for param in ('name="rpc_log"', 'step="3"'):
69+
if param not in line:
70+
test.fail(f"Missing structured data param {param}: {line}")
71+
72+
with test.step("Log message with only the mandatory text"):
73+
target.log("Plain message, no frills")
74+
until(lambda: "Plain message" in logfile(), attempts=10)
75+
76+
with test.step("Verify default app-name is set and msgid and structured data are empty"):
77+
line = [ln for ln in logfile().splitlines() if "Plain message" in ln][0]
78+
if not re.search(r" \S+ - - - Plain message, no frills$", line):
79+
test.fail(f"Unexpected header for default message: {line}")
80+
if re.search(r" - - - - Plain message", line):
81+
test.fail(f"Default app-name should not be empty: {line}")
82+
83+
test.succeed()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
graph "1x1" {
2+
layout="neato";
3+
overlap="false";
4+
esep="+80";
5+
6+
node [shape=record, fontname="DejaVu Sans Mono, Book"];
7+
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];
8+
9+
host [
10+
label="host | { <mgmt> mgmt }",
11+
pos="0,12!",
12+
requires="controller",
13+
];
14+
15+
target [
16+
label="{ <mgmt> mgmt } | target",
17+
pos="10,12!",
18+
19+
requires="infix",
20+
];
21+
22+
host:mgmt -- target:mgmt [requires="mgmt", color="lightgray"]
23+
}
Lines changed: 33 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)