mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-06 23:43:20 +02:00
test/case: simplify and add load-bearing sleep(2)
This (new) test sometimes fail on HW, so let's hold off a while before sending our log messages. Ths should allow the DUTs to settle. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -10,6 +10,17 @@ actions (log vs block/stop).
|
||||
import infamy
|
||||
import time
|
||||
|
||||
TEST_MESSAGES = [
|
||||
("daemon.emerg", "Emergency: system is unusable"),
|
||||
("daemon.alert", "Alert: immediate action required"),
|
||||
("daemon.crit", "Critical: critical condition"),
|
||||
("daemon.err", "Error: error condition"),
|
||||
("daemon.warning", "Warning: warning condition"),
|
||||
("daemon.notice", "Notice: normal but significant"),
|
||||
("daemon.info", "Info: informational message"),
|
||||
("daemon.debug", "Debug: debug-level message"),
|
||||
]
|
||||
|
||||
with infamy.Test() as test:
|
||||
with test.step("Set up topology and attach to target DUT"):
|
||||
env = infamy.Env()
|
||||
@@ -62,51 +73,53 @@ with infamy.Test() as test:
|
||||
}
|
||||
})
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
with test.step("Send test messages at all severity levels"):
|
||||
tgtssh.runsh("logger -t advtest -p daemon.emerg 'Emergency: system is unusable'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.alert 'Alert: immediate action required'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.crit 'Critical: critical condition'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.err 'Error: error condition'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.warning 'Warning: warning condition'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.notice 'Notice: normal but significant'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.info 'Info: informational message'")
|
||||
tgtssh.runsh("logger -t advtest -p daemon.debug 'Debug: debug-level message'")
|
||||
time.sleep(1)
|
||||
for priority, message in TEST_MESSAGES:
|
||||
tgtssh.runsh(f"logger -t advtest -p {priority} '{message}'")
|
||||
time.sleep(2)
|
||||
|
||||
with test.step("Verify exact-errors log contains only error messages"):
|
||||
rc = tgtssh.runsh("grep -c 'advtest' /var/log/exact-errors 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 1:
|
||||
test.fail(f"Expected 1 message in /var/log/exact-errors (error only), got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
rc = tgtssh.runsh("grep -q 'Error: error condition' /var/log/exact-errors 2>/dev/null")
|
||||
if rc.returncode != 0:
|
||||
test.fail("Expected error message in /var/log/exact-errors")
|
||||
# Should contain only the error message
|
||||
error_messages = [msg for prio, msg in TEST_MESSAGES if "err" in prio]
|
||||
missing = [msg for msg in error_messages if msg not in log_content]
|
||||
if missing:
|
||||
test.fail(f"Missing error messages in /var/log/exact-errors: {missing}")
|
||||
|
||||
rc = tgtssh.runsh("grep -c 'Emergency\\|Alert\\|Critical' /var/log/exact-errors 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 0:
|
||||
test.fail(f"Expected 0 higher severity messages in /var/log/exact-errors, got {count}")
|
||||
# Should NOT contain higher severity (emerg, alert, crit) or lower
|
||||
unwanted_messages = [msg for prio, msg in TEST_MESSAGES if "err" not in prio]
|
||||
found = [msg for msg in unwanted_messages if msg in log_content]
|
||||
if found:
|
||||
test.fail(f"Found unwanted messages in /var/log/exact-errors: {found}")
|
||||
|
||||
with test.step("Verify no-debug log blocks all messages"):
|
||||
rc = tgtssh.runsh("grep -c 'advtest' /var/log/no-debug 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 0:
|
||||
test.fail(f"Expected 0 messages in /var/log/no-debug (all blocked), got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/no-debug 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
# Should be empty (all messages blocked)
|
||||
all_messages = [msg for _, msg in TEST_MESSAGES]
|
||||
found = [msg for msg in all_messages if msg in log_content]
|
||||
if found:
|
||||
test.fail(f"Expected empty log, found messages in /var/log/no-debug: {found}")
|
||||
|
||||
with test.step("Verify baseline log contains info and higher"):
|
||||
rc = tgtssh.runsh("grep -c 'advtest' /var/log/baseline 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 7:
|
||||
test.fail(f"Expected 7 messages in /var/log/baseline (info and higher), got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/baseline 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
rc = tgtssh.runsh("grep -c 'Debug: debug-level' /var/log/baseline 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 0:
|
||||
test.fail(f"Expected 0 debug messages in /var/log/baseline, got {count}")
|
||||
# Should contain info and higher (all except debug)
|
||||
expected_messages = [msg for prio, msg in TEST_MESSAGES if "debug" not in prio]
|
||||
missing = [msg for msg in expected_messages if msg not in log_content]
|
||||
if missing:
|
||||
test.fail(f"Missing messages in /var/log/baseline: {missing}")
|
||||
|
||||
rc = tgtssh.runsh("grep -q 'Info: informational' /var/log/baseline 2>/dev/null")
|
||||
if rc.returncode != 0:
|
||||
test.fail("Expected info message in /var/log/baseline")
|
||||
# Should NOT contain debug
|
||||
debug_messages = [msg for prio, msg in TEST_MESSAGES if "debug" in prio]
|
||||
found = [msg for msg in debug_messages if msg in log_content]
|
||||
if found:
|
||||
test.fail(f"Found debug messages in /var/log/baseline: {found}")
|
||||
|
||||
test.succeed()
|
||||
|
||||
@@ -10,6 +10,15 @@ substring matching and complex regex patterns.
|
||||
import infamy
|
||||
import time
|
||||
|
||||
TEST_MESSAGES = [
|
||||
"ERROR: Connection failed on interface eth0",
|
||||
"CRITICAL: System temperature high",
|
||||
"Status update from router1: link up",
|
||||
"Status update from router42: link down",
|
||||
"INFO: Normal operation message",
|
||||
"DEBUG: Verbose logging enabled",
|
||||
]
|
||||
|
||||
with infamy.Test() as test:
|
||||
with test.step("Set up topology and attach to target DUT"):
|
||||
env = infamy.Env()
|
||||
@@ -52,52 +61,49 @@ with infamy.Test() as test:
|
||||
}
|
||||
})
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
with test.step("Send test messages with various patterns"):
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'ERROR: Connection failed on interface eth0'")
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'CRITICAL: System temperature high'")
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router1: link up'")
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router42: link down'")
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'INFO: Normal operation message'")
|
||||
tgtssh.runsh("logger -t test -p daemon.info 'DEBUG: Verbose logging enabled'")
|
||||
time.sleep(1)
|
||||
for message in TEST_MESSAGES:
|
||||
tgtssh.runsh(f"logger -t test -p daemon.info '{message}'")
|
||||
time.sleep(2)
|
||||
|
||||
with test.step("Verify errors log contains ERROR and CRITICAL messages"):
|
||||
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL' /var/log/errors 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 2:
|
||||
test.fail(f"Expected 2 ERROR/CRITICAL messages in /var/log/errors, got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/errors 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
error_messages = [msg for msg in TEST_MESSAGES if "ERROR" in msg or "CRITICAL" in msg]
|
||||
missing = [msg for msg in error_messages if msg not in log_content]
|
||||
if missing:
|
||||
test.fail(f"Missing error messages in /var/log/errors: {missing}")
|
||||
|
||||
# Verify it does NOT contain other messages
|
||||
rc = tgtssh.runsh("grep -c 'router1\\|Normal operation\\|Verbose' /var/log/errors 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 0:
|
||||
test.fail(f"Expected 0 non-error messages in /var/log/errors, got {count}")
|
||||
non_error_messages = [msg for msg in TEST_MESSAGES if "ERROR" not in msg and "CRITICAL" not in msg]
|
||||
found = [msg for msg in non_error_messages if msg in log_content]
|
||||
if found:
|
||||
test.fail(f"Found unwanted messages in /var/log/errors: {found}")
|
||||
|
||||
with test.step("Verify routers log contains matching router[0-9]+ pattern"):
|
||||
rc = tgtssh.runsh("grep -c 'router[0-9]\\+' /var/log/routers 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 2:
|
||||
test.fail(f"Expected 2 router messages in /var/log/routers, got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/routers 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
# Verify both router1 and router42 are present
|
||||
rc = tgtssh.runsh("grep -q 'router1' /var/log/routers 2>/dev/null")
|
||||
if rc.returncode != 0:
|
||||
test.fail("Expected router1 message in /var/log/routers")
|
||||
|
||||
rc = tgtssh.runsh("grep -q 'router42' /var/log/routers 2>/dev/null")
|
||||
if rc.returncode != 0:
|
||||
test.fail("Expected router42 message in /var/log/routers")
|
||||
router_messages = [msg for msg in TEST_MESSAGES if "router1" in msg or "router42" in msg]
|
||||
missing = [msg for msg in router_messages if msg not in log_content]
|
||||
if missing:
|
||||
test.fail(f"Missing router messages in /var/log/routers: {missing}")
|
||||
|
||||
# Verify it does NOT contain error or normal messages
|
||||
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL\\|Normal operation\\|Verbose' /var/log/routers 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 0:
|
||||
test.fail(f"Expected 0 non-router messages in /var/log/routers, got {count}")
|
||||
non_router_messages = [msg for msg in TEST_MESSAGES if "router" not in msg]
|
||||
found = [msg for msg in non_router_messages if msg in log_content]
|
||||
if found:
|
||||
test.fail(f"Found unwanted messages in /var/log/routers: {found}")
|
||||
|
||||
with test.step("Verify all-messages log contains all test messages"):
|
||||
rc = tgtssh.runsh("grep -c 'test' /var/log/all-messages 2>/dev/null")
|
||||
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
|
||||
if count != 6:
|
||||
test.fail(f"Expected 6 total messages in /var/log/all-messages, got {count}")
|
||||
rc = tgtssh.runsh("cat /var/log/all-messages 2>/dev/null")
|
||||
log_content = rc.stdout if rc.returncode == 0 else ""
|
||||
|
||||
missing = [msg for msg in TEST_MESSAGES if msg not in log_content]
|
||||
if missing:
|
||||
test.fail(f"Missing messages in /var/log/all-messages: {missing}")
|
||||
|
||||
test.succeed()
|
||||
|
||||
Reference in New Issue
Block a user