Skip to content

Commit 2079abb

Browse files
committed
test/infamy: add Transport.log(), log messages using RPC
Wrap the infix-syslog:log RPC so tests can leave markers in a DUT's system log over the management API instead of SSH and logger(1). Facility names are module-qualified in the helper, and structured data is given as a dict of dicts to keep call sites short. The RESTCONF backend's call_dict() only tracked coverage and returned without sending anything, so RPCs with input silently did nothing over RESTCONF. POST to /restconf/operations/MODULE:NAME with the input wrapped per RFC 8040, like call_action() does. Convert the tests that logged via SSH. The remote and hostname_filter tests keep using logger(1), they deliberately exercise the remote client path. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 53c1d46 commit 2079abb

6 files changed

Lines changed: 57 additions & 14 deletions

File tree

‎test/case/services/mdns/mdns_allow_deny/test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def mdns_scan():
2222
pcap3 = ns3.pcap("host 10.0.3.1 and port 5353")
2323

2424
with pcap1, pcap2, pcap3:
25-
ssh.runsh("logger -t scan 'calling avahi-browse ...'")
25+
dut.log("calling avahi-browse ...", app_name="scan")
2626
ssh.runsh("avahi-browse -lat")
2727

2828
def has_packets(output):

‎test/case/syslog/advanced_compare/test.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
from infamy.util import parallel, until
1212

1313
TEST_MESSAGES = [
14-
("daemon.emerg", "Emergency: system is unusable"),
15-
("daemon.alert", "Alert: immediate action required"),
16-
("daemon.crit", "Critical: critical condition"),
17-
("daemon.err", "Error: error condition"),
18-
("daemon.warning", "Warning: warning condition"),
19-
("daemon.notice", "Notice: normal but significant"),
20-
("daemon.info", "Info: informational message"),
21-
("daemon.debug", "Debug: debug-level message"),
14+
("emergency", "Emergency: system is unusable"),
15+
("alert", "Alert: immediate action required"),
16+
("critical", "Critical: critical condition"),
17+
("error", "Error: error condition"),
18+
("warning", "Warning: warning condition"),
19+
("notice", "Notice: normal but significant"),
20+
("info", "Info: informational message"),
21+
("debug", "Debug: debug-level message"),
2222
]
2323

2424
with infamy.Test() as test:
@@ -76,8 +76,8 @@
7676
until(lambda: tgtssh.runsh("test -f /var/log/exact-errors").returncode == 0, attempts=10)
7777

7878
with test.step("Send test messages at all severity levels"):
79-
for priority, message in TEST_MESSAGES:
80-
tgtssh.runsh(f"logger -t advtest -p {priority} '{message}'")
79+
for severity, message in TEST_MESSAGES:
80+
target.log(message, severity=severity, facility="daemon", app_name="advtest")
8181
until(lambda: "Error: error condition" in tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null").stdout, attempts=10)
8282

8383
with test.step("Verify exact-errors log contains only error messages"):

‎test/case/syslog/pattern_match/test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
with test.step("Send test messages with various patterns"):
6868
for message in TEST_MESSAGES:
69-
tgtssh.runsh(f"logger -t test -p daemon.info '{message}'")
69+
target.log(message, severity="info", facility="daemon", app_name="test")
7070
time.sleep(2)
7171

7272
with test.step("Verify errors log contains ERROR and CRITICAL messages"):

‎test/case/syslog/property_filter/test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595
with test.step("Send test messages"):
9696
for tag, msg in TEST_MESSAGES:
97-
tgtssh.runsh(f"logger -t {tag} -p daemon.info '{msg}'")
97+
target.log(msg, severity="info", facility="daemon", app_name=tag)
9898
until(lambda: "Application startup" in tgtssh.runsh("cat /var/log/baseline 2>/dev/null").stdout, attempts=10)
9999

100100
with test.step("Verify myapp log contains only myapp messages"):

‎test/infamy/restconf.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,24 @@ def patch_config(self, xpath, edit, retries=3):
411411
raise last_error
412412

413413
def call_dict(self, model, call):
414+
"""Call RPC, Python dictionary version: {"rpc-name": {input leaves}}"""
414415
coverage.track_dict(model, call)
415-
pass # Need implementation
416+
if len(call) != 1:
417+
raise ValueError("call_dict() expects a single RPC: {name: input}")
418+
419+
(name, data), = call.items()
420+
url = f"{self.rpc_url}/{model}:{name}"
421+
body = {f"{model}:input": data} if data else None
422+
response = requests_workaround_post(
423+
url,
424+
json=body,
425+
headers=self.headers,
426+
auth=self.auth,
427+
verify=False
428+
)
429+
response.raise_for_status()
430+
431+
return response.content
416432

417433
def call_rpc(self, rpc):
418434
"""Actually send a POST to RESTCONF server"""

‎test/infamy/transport.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,30 @@ def test_reset(self):
107107

108108
def startup_override(self):
109109
self.call_action("/infix-test:test/override-startup")
110+
111+
def log(self, message, severity=None, facility=None, app_name=None,
112+
msgid=None, sd=None):
113+
"""Log a message on the target, using the infix-syslog:log RPC.
114+
115+
Defaults to user.notice with app-name set to the calling user.
116+
`facility` is a plain name, e.g. "daemon", the module prefix is
117+
added here. `sd` is RFC 5424 structured data, given as a dict
118+
of dicts: {"sd-id": {"name": "value", ...}}.
119+
"""
120+
rpc = {"message": message}
121+
if severity:
122+
rpc["severity"] = severity
123+
if facility:
124+
module = "infix-syslog" if facility in ("rauc", "container", "web") else "ietf-syslog"
125+
rpc["facility"] = f"{module}:{facility}"
126+
if app_name:
127+
rpc["app-name"] = app_name
128+
if msgid:
129+
rpc["msgid"] = msgid
130+
if sd:
131+
rpc["structured-data"] = [{
132+
"id": sdid,
133+
"param": [{"name": name, "value": value} for name, value in params.items()]
134+
} for sdid, params in sd.items()]
135+
136+
return self.call_dict("infix-syslog", {"log": rpc})

0 commit comments

Comments
 (0)