|
10 | 10 | import infamy |
11 | 11 | import time |
12 | 12 |
|
| 13 | +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"), |
| 22 | +] |
| 23 | + |
13 | 24 | with infamy.Test() as test: |
14 | 25 | with test.step("Set up topology and attach to target DUT"): |
15 | 26 | env = infamy.Env() |
|
62 | 73 | } |
63 | 74 | }) |
64 | 75 |
|
| 76 | + time.sleep(2) |
| 77 | + |
65 | 78 | 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) |
| 79 | + for priority, message in TEST_MESSAGES: |
| 80 | + tgtssh.runsh(f"logger -t advtest -p {priority} '{message}'") |
| 81 | + time.sleep(2) |
75 | 82 |
|
76 | 83 | 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}") |
| 84 | + rc = tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null") |
| 85 | + log_content = rc.stdout if rc.returncode == 0 else "" |
81 | 86 |
|
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") |
| 87 | + # Should contain only the error message |
| 88 | + error_messages = [msg for prio, msg in TEST_MESSAGES if "err" in prio] |
| 89 | + missing = [msg for msg in error_messages if msg not in log_content] |
| 90 | + if missing: |
| 91 | + test.fail(f"Missing error messages in /var/log/exact-errors: {missing}") |
85 | 92 |
|
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}") |
| 93 | + # Should NOT contain higher severity (emerg, alert, crit) or lower |
| 94 | + unwanted_messages = [msg for prio, msg in TEST_MESSAGES if "err" not in prio] |
| 95 | + found = [msg for msg in unwanted_messages if msg in log_content] |
| 96 | + if found: |
| 97 | + test.fail(f"Found unwanted messages in /var/log/exact-errors: {found}") |
90 | 98 |
|
91 | 99 | 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}") |
| 100 | + rc = tgtssh.runsh("cat /var/log/no-debug 2>/dev/null") |
| 101 | + log_content = rc.stdout if rc.returncode == 0 else "" |
| 102 | + |
| 103 | + # Should be empty (all messages blocked) |
| 104 | + all_messages = [msg for _, msg in TEST_MESSAGES] |
| 105 | + found = [msg for msg in all_messages if msg in log_content] |
| 106 | + if found: |
| 107 | + test.fail(f"Expected empty log, found messages in /var/log/no-debug: {found}") |
96 | 108 |
|
97 | 109 | 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") |
| 110 | + rc = tgtssh.runsh("cat /var/log/baseline 2>/dev/null") |
| 111 | + log_content = rc.stdout if rc.returncode == 0 else "" |
| 112 | + |
| 113 | + # Should contain info and higher (all except debug) |
| 114 | + expected_messages = [msg for prio, msg in TEST_MESSAGES if "debug" not in prio] |
| 115 | + missing = [msg for msg in expected_messages if msg not in log_content] |
| 116 | + if missing: |
| 117 | + test.fail(f"Missing messages in /var/log/baseline: {missing}") |
| 118 | + |
| 119 | + # Should NOT contain debug |
| 120 | + debug_messages = [msg for prio, msg in TEST_MESSAGES if "debug" in prio] |
| 121 | + found = [msg for msg in debug_messages if msg in log_content] |
| 122 | + if found: |
| 123 | + test.fail(f"Found debug messages in /var/log/baseline: {found}") |
111 | 124 |
|
112 | 125 | test.succeed() |
0 commit comments