| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2013 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import time |
| 9 |
|
| 10 |
import testlib |
| 11 |
|
| 12 |
|
| 13 |
class TestJournal(testlib.MachineCase): |
| 14 |
def setUp(self): |
| 15 |
super().setUp() |
| 16 |
self.test_start_time = self.machine.execute("date +%s").strip() |
| 17 |
|
| 18 |
def injectExtras(self): |
| 19 |
self.browser.eval_js(""" |
| 20 |
ph_get_log_lines = function () { |
| 21 |
var lines = [ ]; |
| 22 |
var panels = ph_find('.cockpit-log-panel').childNodes; |
| 23 |
for (var i = 0; i < panels.length; ++i) { |
| 24 |
var e = panels[i]; |
| 25 |
if (e.className === 'panel-heading') { |
| 26 |
lines.push (e.textContent); |
| 27 |
} else { |
| 28 |
var msg = e.querySelector('.cockpit-log-message'); |
| 29 |
msg = msg ? msg.textContent : ""; |
| 30 |
var ident = ''; |
| 31 |
var count = ''; |
| 32 |
if (e.querySelectorAll('.cockpit-log-service-container').length > 0) { |
| 33 |
ident = e.querySelector('.cockpit-log-service-reduced').textContent; |
| 34 |
count = e.querySelector('.pf-v6-c-badge').textContent; |
| 35 |
} else { |
| 36 |
ident = e.querySelector('.cockpit-log-service'); |
| 37 |
ident = ident ? ident.textContent : ""; |
| 38 |
} |
| 39 |
lines.push ([ ident, msg, count ]); |
| 40 |
} |
| 41 |
} |
| 42 |
var journal_start_text = ph_find('.journal-start').textContent; |
| 43 |
if (journal_start_text !== "") |
| 44 |
lines.push(journal_start_text); |
| 45 |
// console.log(JSON.stringify(lines)); |
| 46 |
return lines; |
| 47 |
} |
| 48 |
""") |
| 49 |
|
| 50 |
def testBasic(self): |
| 51 |
b = self.browser |
| 52 |
|
| 53 |
m = self.machine |
| 54 |
|
| 55 |
# Certain versions of journald won't set _SYSTEMD_UNIT |
| 56 |
# correctly for entries that are processed after the |
| 57 |
# originating process has already exited. So we keep the |
| 58 |
# process around for a bit longer after the last line has been |
| 59 |
# output. |
| 60 |
# |
| 61 |
self.write_file("/etc/systemd/system/log123.service", |
| 62 |
""" |
| 63 |
[Unit] |
| 64 |
Description=123 different log lines |
| 65 |
|
| 66 |
[Service] |
| 67 |
ExecStart=/bin/sh -c '/usr/bin/seq 123; sleep 10' |
| 68 |
""") |
| 69 |
|
| 70 |
self.write_file("/etc/systemd/system/slow10.service", |
| 71 |
""" |
| 72 |
[Unit] |
| 73 |
Description=Slowly log 10 identical lines |
| 74 |
|
| 75 |
[Service] |
| 76 |
ExecStart=/bin/sh -c 'sleep 5; for s in $(seq 10); do echo SLOW; sleep 0.1; done; sleep 10' |
| 77 |
""") |
| 78 |
self.addCleanup(m.execute, "systemctl daemon-reload") |
| 79 |
|
| 80 |
self.login_and_go("/system/logs") |
| 81 |
self.injectExtras() |
| 82 |
|
| 83 |
def wait_log_lines(expected): |
| 84 |
b.wait_visible(".cockpit-log-panel") |
| 85 |
b.wait_js_func("""(function (expected) { |
| 86 |
var lines = ph_get_log_lines (); |
| 87 |
|
| 88 |
// Ignore date |
| 89 |
if (lines.length > 1) |
| 90 |
lines.shift(); |
| 91 |
|
| 92 |
if (expected.length != lines.length) |
| 93 |
return false; |
| 94 |
for (i = 0; i < expected.length; i++) |
| 95 |
if (!new RegExp(JSON.stringify(expected[i])).test(JSON.stringify(lines[i]))) |
| 96 |
return false; |
| 97 |
return true; |
| 98 |
})""", expected) |
| 99 |
|
| 100 |
def wait_journal_empty(): |
| 101 |
b.wait_in_text(".pf-v6-c-empty-state__body", "Can not find any logs using the current combination of filters.") |
| 102 |
|
| 103 |
b.go("#/?priority=debug&service=log123.service") |
| 104 |
wait_journal_empty() |
| 105 |
|
| 106 |
def wait_log123(): |
| 107 |
b.wait_visible(".cockpit-log-panel") |
| 108 |
b.wait_js_func("""(function () { |
| 109 |
var lines = ph_get_log_lines(); |
| 110 |
|
| 111 |
var seq = 123; |
| 112 |
var seen_day = false; |
| 113 |
|
| 114 |
for (i = 1; i < lines.length; i++) { |
| 115 |
l = lines[i]; |
| 116 |
if (l[2] != "") { |
| 117 |
// console.log("repeat", l[2], "?"); |
| 118 |
return false; |
| 119 |
} |
| 120 |
if (l[0] == "systemd") { |
| 121 |
// console.log(l[1], "?"); |
| 122 |
i++; |
| 123 |
} else if (l[0] == "sh") { |
| 124 |
if (l[1] != seq.toString()) { |
| 125 |
// console.log(l[1], "?"); |
| 126 |
return false; |
| 127 |
} |
| 128 |
seq = seq - 1; |
| 129 |
} else { |
| 130 |
// console.log(l[0], "?"); |
| 131 |
return false; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
if (seq != 0) { |
| 136 |
// console.log("Didn't see all 'seq' lines.") |
| 137 |
return false; |
| 138 |
} |
| 139 |
|
| 140 |
return true; |
| 141 |
})""") |
| 142 |
|
| 143 |
m.execute("systemctl start log123") |
| 144 |
|
| 145 |
wait_log123() |
| 146 |
|
| 147 |
b.go("#/?priority=debug&service=nonexisting.service") |
| 148 |
wait_journal_empty() |
| 149 |
|
| 150 |
b.go("#/?priority=debug&service=log123") |
| 151 |
wait_log123() |
| 152 |
|
| 153 |
b.go("#/?priority=debug&service=slow10.service") |
| 154 |
wait_journal_empty() |
| 155 |
|
| 156 |
def wait_slow10(): |
| 157 |
with b.wait_timeout(30): |
| 158 |
wait_log_lines([["systemd", "slow10.service: Deactivated successfully.", ""], ["sh", "SLOW", "10"], |
| 159 |
["systemd", "Started.*Slowly log 10 identical lines.", ""]]) |
| 160 |
|
| 161 |
def wait_log_present(message): |
| 162 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{message}')") |
| 163 |
|
| 164 |
def wait_log_not_present(message): |
| 165 |
b.wait_not_present(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{message}')") |
| 166 |
|
| 167 |
m.execute("systemctl start slow10") |
| 168 |
|
| 169 |
wait_slow10() |
| 170 |
|
| 171 |
b.go("#/?priority=debug&service=nonexisting.service") |
| 172 |
wait_journal_empty() |
| 173 |
b.go("#/?priority=debug&service=slow10.service") |
| 174 |
wait_slow10() |
| 175 |
|
| 176 |
b.go("#/?priority=debug") |
| 177 |
|
| 178 |
m.execute("logger -p user.err --tag check-journal JUST ERROR") |
| 179 |
m.execute("logger -p 5 --tag just-a-service THE SERVICE") |
| 180 |
wait_log_present("THE SERVICE") |
| 181 |
wait_log_present("JUST ERROR") |
| 182 |
|
| 183 |
# We cannot open this select with tests but we need to wait until it gets loaded |
| 184 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", "just-a-service") |
| 185 |
wait_log_not_present("JUST ERROR") |
| 186 |
wait_log_present("THE SERVICE") |
| 187 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", "All") |
| 188 |
wait_log_present("JUST ERROR") |
| 189 |
wait_log_present("THE SERVICE") |
| 190 |
|
| 191 |
b.select_PF("#journal-prio-menu", "Error and above") |
| 192 |
wait_log_not_present("THE SERVICE") |
| 193 |
wait_log_present("JUST ERROR") |
| 194 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", "check-journal") |
| 195 |
b.wait_not_present("#journal-identifier-menu + ul button:contains('just-a-service')") |
| 196 |
|
| 197 |
b.go("#/?tag=test-stream&priority=notice") |
| 198 |
wait_journal_empty() |
| 199 |
|
| 200 |
# Verify the filter panel |
| 201 |
b.assert_pixels("#journal", "journal-filters-panel", skip_layouts=["mobile"]) |
| 202 |
|
| 203 |
# Test inline help |
| 204 |
b.click("#journal-grep button[aria-label='Open advanced search']") |
| 205 |
b.wait_val("#journal-cmd-copy input", "journalctl --no-tail --since=-24hours --priority=notice --reverse -- SYSLOG_IDENTIFIER=test-stream") |
| 206 |
b.click("#journal-grep button[aria-label='Open advanced search']") |
| 207 |
b.wait_not_present("#journal-cmd-copy") |
| 208 |
|
| 209 |
# Test popover in advanced search |
| 210 |
b.click("#journal-grep button[aria-label='Open advanced search']") |
| 211 |
b.assert_pixels(".pf-v6-c-panel", "logs-filter-panel", skip_layouts=["mobile"]) |
| 212 |
|
| 213 |
b.click("label[for='since_0'] button.log-text-filter-popover-button") |
| 214 |
b.wait_text(".pf-v6-c-popover__title-text", "Start showing entries on or newer than the specified date.") |
| 215 |
# FIXME: Closing the popover with the X button also closes the whole search form (just not with ph_mouse) |
| 216 |
# b.click(".pf-v6-c-popover__close button") |
| 217 |
# Thus close the popover the same way as we opened it, with the (i) icon |
| 218 |
b.click("label[for='since_0'] button.log-text-filter-popover-button") |
| 219 |
b.wait_not_present(".pf-v6-c-popover") |
| 220 |
b.click("#journal-grep button[aria-label='Open advanced search']") |
| 221 |
b.wait_not_present("#journal-cmd-copy") |
| 222 |
|
| 223 |
# Test following |
| 224 |
m.execute("logger --tag test-stream Message 1") |
| 225 |
m.execute("logger --tag test-stream Message 2") |
| 226 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 1')") |
| 227 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 2')") |
| 228 |
|
| 229 |
b.click("#journal-follow:contains('Pause')") |
| 230 |
b.wait_in_text("#journal-follow", "Resume") |
| 231 |
m.execute("logger --tag test-stream Message 3") |
| 232 |
time.sleep(3) |
| 233 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 3')") |
| 234 |
|
| 235 |
b.click("#journal-follow:contains('Resume')") |
| 236 |
b.wait_in_text("#journal-follow", "Pause") |
| 237 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 3')") |
| 238 |
# This fails if all logs are reloaded |
| 239 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 1')") |
| 240 |
m.execute("logger --tag test-stream Message 4") |
| 241 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 4')") |
| 242 |
|
| 243 |
# Test message filtering |
| 244 |
|
| 245 |
b.focus("#journal-grep input") |
| 246 |
|
| 247 |
b.input_text("1") |
| 248 |
b.click("#journal-grep button[aria-label=Search]") |
| 249 |
|
| 250 |
b.wait_js_cond('window.location.hash === "#/?grep=1&priority=notice&tag=test-stream"') |
| 251 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 2')") |
| 252 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 3')") |
| 253 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 1')") |
| 254 |
|
| 255 |
b.focus("#journal-grep input") |
| 256 |
b.key("Backspace") |
| 257 |
b.input_text("m.*[2-5]") |
| 258 |
b.click("#journal-grep button[aria-label=Search]") |
| 259 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 1')") |
| 260 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 2')") |
| 261 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 3')") |
| 262 |
|
| 263 |
m.execute(r"printf 'MESSAGE=Message 4\nPRIORITY=3\nFOO=bar\n' | logger --journald") |
| 264 |
m.execute(r"printf 'MESSAGE=Message 5\nPRIORITY=3\nFOO=bar\n' | logger --journald") |
| 265 |
m.execute(r"printf 'MESSAGE=Message 6\nPRIORITY=3\nBAR=foo\n' | logger --journald") |
| 266 |
|
| 267 |
b.go("#/?tag=logger") |
| 268 |
|
| 269 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 4')") |
| 270 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 5')") |
| 271 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 6')") |
| 272 |
|
| 273 |
b.focus("#journal-grep input") |
| 274 |
b.input_text("FOO=bar [5-6]") |
| 275 |
b.click("#journal-grep button[aria-label=Search]") |
| 276 |
b.wait_val("#journal-grep input", "priority:err identifier:logger FOO=bar [5-6]") |
| 277 |
|
| 278 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 4')") |
| 279 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 6')") |
| 280 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 5')") |
| 281 |
|
| 282 |
b.focus("#journal-grep input") |
| 283 |
b.key("Backspace", 13) |
| 284 |
b.input_text("[5-6]") |
| 285 |
b.click("#journal-grep button[aria-label=Search]") |
| 286 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 4')") |
| 287 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 6')") |
| 288 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 5')") |
| 289 |
|
| 290 |
# Test filters |
| 291 |
b.select_PF("#logs-predefined-filters", "Current boot") |
| 292 |
b.wait_val("#journal-grep input", "priority:err identifier:logger boot:0 [5-6]") |
| 293 |
|
| 294 |
b.select_PF("#logs-predefined-filters", "Previous boot") |
| 295 |
b.wait_val("#journal-grep input", "priority:err identifier:logger boot:-1 [5-6]") |
| 296 |
|
| 297 |
b.select_PF("#logs-predefined-filters", "Last 24 hours") |
| 298 |
b.wait_val("#journal-grep input", "priority:err identifier:logger since:-24hours [5-6]") |
| 299 |
|
| 300 |
b.select_PF("#logs-predefined-filters", "Last 7 days") |
| 301 |
b.wait_val("#journal-grep input", "priority:err identifier:logger since:-7days [5-6]") |
| 302 |
|
| 303 |
# Check that 'until' qualifier keeps streaming until given time |
| 304 |
b.focus("#journal-grep input") |
| 305 |
b.key("Backspace", 4) |
| 306 |
b.input_text("6-9] until:+15s") |
| 307 |
b.click("#journal-grep button[aria-label=Search]") |
| 308 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 5')") |
| 309 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 6')") |
| 310 |
m.execute(r"printf 'MESSAGE=Message 7\nPRIORITY=3\nBAR=foo\n' | logger --journald") |
| 311 |
b.wait_visible("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 7')") |
| 312 |
time.sleep(20) |
| 313 |
m.execute(r"printf 'MESSAGE=Message 8\nPRIORITY=3\nBAR=foo\n' | logger --journald") |
| 314 |
time.sleep(5) |
| 315 |
b.wait_not_present("#journal-box .cockpit-logline .cockpit-log-message:contains('Message 8')") |
| 316 |
|
| 317 |
# CVE-2026-4802 |
| 318 |
b.go("/system/logs#/?boot=0;touch${IFS}/tmp/pwned;&priority=err") |
| 319 |
b.wait_in_text("#journal-box", "No logs found") |
| 320 |
failed_to_parse = False |
| 321 |
for log in self.browser.get_js_log(): |
| 322 |
if "Failed to parse boot descriptor" in log: |
| 323 |
failed_to_parse = True |
| 324 |
|
| 325 |
self.assertTrue(failed_to_parse) |
| 326 |
m.execute("! test -f /tmp/pwned") |
| 327 |
|
| 328 |
self.allow_journal_messages(".*Data from the specified boot .* is not available: No such boot ID in journal.*") |
| 329 |
|
| 330 |
@testlib.nondestructive |
| 331 |
def testIdentifierReloading(self): |
| 332 |
""" |
| 333 |
Test verifies https://github.com/cockpit-project/cockpit/issues/20123 |
| 334 |
Updating Identifiers when changing priorities |
| 335 |
""" |
| 336 |
b = self.browser |
| 337 |
m = self.machine |
| 338 |
tag_error = "check-error-inside" |
| 339 |
tag_info = "check-info-inside" |
| 340 |
m.execute(f"logger -p user.err --tag {tag_error} {tag_error.upper()}") |
| 341 |
m.execute(f"logger -p 5 --tag {tag_info} {tag_info.upper()}") |
| 342 |
self.login_and_go("/system/logs") |
| 343 |
|
| 344 |
b.go(f"#/?priority=err&since=@{self.test_start_time}") |
| 345 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_error.upper()}')") |
| 346 |
b.wait_not_present(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_info.upper()}')") |
| 347 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", tag_error) |
| 348 |
b.wait_not_present(f"#journal-identifier-menu + ul button:contains('{tag_info}')") |
| 349 |
|
| 350 |
b.select_PF("#journal-prio-menu", "Debug and above") |
| 351 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", "All") |
| 352 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_error.upper()}')") |
| 353 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_info.upper()}')") |
| 354 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", tag_error) |
| 355 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", tag_info) |
| 356 |
|
| 357 |
b.select_PF("#journal-prio-menu", "Error and above") |
| 358 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", "All") |
| 359 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_error.upper()}')") |
| 360 |
b.wait_not_present(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{tag_info.upper()}')") |
| 361 |
b.select_PF("#journal-identifier-menu .pf-v6-c-menu-toggle__button", tag_error) |
| 362 |
b.wait_not_present(f"#journal-identifier-menu + ul button:contains('{tag_info}')") |
| 363 |
|
| 364 |
def testRebootAndTime(self): |
| 365 |
b = self.browser |
| 366 |
m = self.machine |
| 367 |
|
| 368 |
self.allow_journal_messages(".*Failed to get realtime timestamp: Cannot assign requested address.*") |
| 369 |
|
| 370 |
# HACK: pmie and pmlogger take a looooong time to shutdown (https://bugzilla.redhat.com/show_bug.cgi?id=1703348) |
| 371 |
# so disable them for this test, we don't test PCP here |
| 372 |
m.execute("systemctl disable --now pmie pmlogger || true") |
| 373 |
|
| 374 |
m.execute("""ntp=`timedatectl show --property NTP --value` |
| 375 |
if [ $ntp == "yes" ]; then |
| 376 |
timedatectl set-ntp off |
| 377 |
fi""") |
| 378 |
# this is asynchronous; must wait until timesyncd stops before the time can be set |
| 379 |
m.execute("while systemctl is-active systemd-timesyncd; do sleep 1; done") |
| 380 |
m.execute("timedatectl set-time 2037-01-01") |
| 381 |
|
| 382 |
def wait_log_lines(expected): |
| 383 |
b.wait_visible(".cockpit-log-panel") |
| 384 |
b.wait_js_func("""(function (expected) { |
| 385 |
var lines = ph_get_log_lines (); |
| 386 |
|
| 387 |
if (expected.length != lines.length) |
| 388 |
return false; |
| 389 |
for (i = 0; i < expected.length; i++) |
| 390 |
if (JSON.stringify(expected[i]) != JSON.stringify(lines[i])) |
| 391 |
return false; |
| 392 |
return true; |
| 393 |
})""", expected) |
| 394 |
|
| 395 |
self.login_and_go("/system/logs") |
| 396 |
|
| 397 |
self.injectExtras() |
| 398 |
b.eval_js(""" |
| 399 |
localTime = function(time) { |
| 400 |
var month_names = [ |
| 401 |
'January', |
| 402 |
'February', |
| 403 |
'March', |
| 404 |
'April', |
| 405 |
'May', |
| 406 |
'June', |
| 407 |
'July', |
| 408 |
'August', |
| 409 |
'September', |
| 410 |
'October', |
| 411 |
'November', |
| 412 |
'December' |
| 413 |
]; |
| 414 |
var d = new Date(time); |
| 415 |
return month_names[d.getMonth()] + ' ' + d.getDate().toFixed() + ', ' + d.getFullYear().toFixed(); |
| 416 |
} |
| 417 |
""") |
| 418 |
# January 1, 2037 00:00:00Z in browser time |
| 419 |
expected_date = b.eval_js("localTime(2114380800000)") |
| 420 |
|
| 421 |
# insert messages as errors because we know these will be shown by default |
| 422 |
m.execute("systemctl start systemd-journald.service") |
| 423 |
m.execute("logger -p user.err --tag check-journal BEFORE BOOT") |
| 424 |
b.go("#/?tag=check-journal") |
| 425 |
wait_log_lines([expected_date, ["check-journal", "BEFORE BOOT", ""]]) |
| 426 |
m.execute("systemctl stop systemd-journald.service") |
| 427 |
|
| 428 |
# Now reboot things |
| 429 |
self.reboot() |
| 430 |
m.execute("timedatectl set-time '2037-01-01 00:05:00'") |
| 431 |
m.execute("logger -p user.err --tag check-journal AFTER BOOT") |
| 432 |
|
| 433 |
m.start_cockpit() |
| 434 |
b.switch_to_top() |
| 435 |
b.relogin('/system/logs') |
| 436 |
self.injectExtras() |
| 437 |
|
| 438 |
b.go("#/?tag=check-journal") |
| 439 |
wait_log_lines([expected_date, |
| 440 |
["check-journal", "AFTER BOOT", ""], |
| 441 |
["", "Reboot", ""], |
| 442 |
["check-journal", "BEFORE BOOT", ""] |
| 443 |
]) |
| 444 |
|
| 445 |
b.go("#/?boot=0&tag=check-journal") |
| 446 |
wait_log_lines([expected_date, |
| 447 |
["check-journal", "AFTER BOOT", ""], |
| 448 |
"Load earlier entries", |
| 449 |
]) |
| 450 |
|
| 451 |
b.click('#start-box button:contains("Load earlier entries")') |
| 452 |
|
| 453 |
wait_log_lines([expected_date, |
| 454 |
["check-journal", "AFTER BOOT", ""], |
| 455 |
["", "Reboot", ""], |
| 456 |
["check-journal", "BEFORE BOOT", ""] |
| 457 |
]) |
| 458 |
|
| 459 |
# Check selecting of services |
| 460 |
b.go("#/?boot=-1&tag=check-journal") |
| 461 |
wait_log_lines([expected_date, |
| 462 |
["check-journal", "BEFORE BOOT", ""], |
| 463 |
"Load earlier entries" |
| 464 |
]) |
| 465 |
|
| 466 |
b.go("#/?boot=0&tag=check-journal") |
| 467 |
wait_log_lines([expected_date, |
| 468 |
["check-journal", "AFTER BOOT", ""], |
| 469 |
"Load earlier entries" |
| 470 |
]) |
| 471 |
|
| 472 |
# Check that 'until' qualifier shows only until some date |
| 473 |
b.go("#/?tag=check-journal") |
| 474 |
wait_log_lines([expected_date, |
| 475 |
["check-journal", "AFTER BOOT", ""], |
| 476 |
["", "Reboot", ""], |
| 477 |
["check-journal", "BEFORE BOOT", ""] |
| 478 |
]) |
| 479 |
|
| 480 |
b.focus("#journal-grep input") |
| 481 |
b.input_text("until:2037-01-01\\ 00:03") |
| 482 |
b.click("#journal-grep button[aria-label=Search]") |
| 483 |
wait_log_lines([expected_date, |
| 484 |
["check-journal", "BEFORE BOOT", ""], |
| 485 |
"Load earlier entries" |
| 486 |
]) |
| 487 |
|
| 488 |
b.click("#journal-identifier-menu .pf-v6-c-menu-toggle__button") |
| 489 |
b.wait_visible(".pf-v6-c-menu ul button:contains('check-journal')") |
| 490 |
|
| 491 |
# New messages are not streamed when 'until' is in the past |
| 492 |
m.execute("logger -p user.err --tag check-journal RIGHT NOW") |
| 493 |
time.sleep(5) |
| 494 |
wait_log_lines([expected_date, |
| 495 |
["check-journal", "BEFORE BOOT", ""], |
| 496 |
"Load earlier entries" |
| 497 |
]) |
| 498 |
|
| 499 |
@testlib.nondestructive |
| 500 |
def testBinary(self): |
| 501 |
b = self.browser |
| 502 |
m = self.machine |
| 503 |
bin_data_long = {"MSG": (r"Hel\01" * 250) + "a", "BIN": (r"Hel\01" * 250) + "a"} |
| 504 |
bin_data_short = {"MSG": "Hello \01 World", "BIN": "a\01b\02c\03"} |
| 505 |
|
| 506 |
def wait_field(name, value): |
| 507 |
b.wait_text(f"#log-details dd[data-label='{name}']", value) |
| 508 |
|
| 509 |
def check_entry(msg, bin_msg): |
| 510 |
b.click(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{msg}')") |
| 511 |
b.wait_text(".pf-v6-c-card__title", msg) |
| 512 |
wait_field("FOO", "bar") |
| 513 |
wait_field("BIN", bin_msg) |
| 514 |
b.click('.pf-v6-c-breadcrumb li:first-of-type') |
| 515 |
b.wait_visible(f"#journal-box .cockpit-logline .cockpit-log-message:contains('{msg}')") |
| 516 |
|
| 517 |
m.execute(fr"printf 'MESSAGE={bin_data_short['MSG']}\nPRIORITY=3\nFOO=bar\nBIN={bin_data_short['BIN']}\n' | logger --journald") |
| 518 |
self.login_and_go("/system/logs#/?tag=logger&since=@" + self.test_start_time) |
| 519 |
check_entry(bin_data_short["MSG"], "[binary data]") # Test when binary msg is <= 1000 bytes |
| 520 |
m.execute(fr"printf 'MESSAGE={bin_data_long['MSG']}\nPRIORITY=3\nFOO=bar\nBIN={bin_data_long['BIN']}\n' | logger --journald") |
| 521 |
b.go("/system/logs#/?tag=logger&since=@" + self.test_start_time) |
| 522 |
check_entry("[binary data]", "[binary data]") # Test when binary msg is > 1000 bytes |
| 523 |
|
| 524 |
@testlib.nondestructive |
| 525 |
def testNoMessage(self): |
| 526 |
b = self.browser |
| 527 |
m = self.machine |
| 528 |
|
| 529 |
m.execute(r"printf 'PRIORITY=3\nFOO=bar\n' | logger --journald") |
| 530 |
self.login_and_go("/system/logs#/?tag=logger&since=@" + self.test_start_time) |
| 531 |
b.click("#journal-box .cockpit-logline .cockpit-log-message:contains('[no data]')") |
| 532 |
b.wait_text(".pf-v6-c-card__title", "[no data]") |
| 533 |
|
| 534 |
@testlib.nondestructive |
| 535 |
def testLogLevel(self): |
| 536 |
|
| 537 |
b = self.browser |
| 538 |
m = self.machine |
| 539 |
|
| 540 |
m.execute("logger -p user.info --tag check-journal INFO_MESSAGE") |
| 541 |
m.execute("logger -p user.warn --tag check-journal WARNING_MESSAGE") |
| 542 |
m.execute("logger -p user.emerg --tag check-journal EMERGENCY_MESSAGE") |
| 543 |
|
| 544 |
self.login_and_go("/system/logs#/?tag=check-journal&since=@" + self.test_start_time) |
| 545 |
|
| 546 |
journal_line_selector = "#journal-box .cockpit-logline:has(span:contains('{0}'))" |
| 547 |
|
| 548 |
b.select_PF("#journal-prio-menu", "Only emergency") |
| 549 |
b.wait_visible(journal_line_selector.format("EMERGENCY_MESSAGE")) |
| 550 |
b.wait_not_present(journal_line_selector.format("WARNING_MESSAGE")) |
| 551 |
b.wait_not_present(journal_line_selector.format("INFO_MESSAGE")) |
| 552 |
|
| 553 |
b.select_PF("#journal-prio-menu", "Warning and above") |
| 554 |
b.wait_visible(journal_line_selector.format("EMERGENCY_MESSAGE")) |
| 555 |
b.wait_visible(journal_line_selector.format("WARNING_MESSAGE")) |
| 556 |
b.wait_not_present(journal_line_selector.format("INFO_MESSAGE")) |
| 557 |
|
| 558 |
b.select_PF("#journal-prio-menu", "Info and above") |
| 559 |
b.wait_visible(journal_line_selector.format("EMERGENCY_MESSAGE")) |
| 560 |
b.wait_visible(journal_line_selector.format("WARNING_MESSAGE")) |
| 561 |
b.wait_visible(journal_line_selector.format("INFO_MESSAGE")) |
| 562 |
|
| 563 |
|
| 564 |
if __name__ == '__main__': |
| 565 |
testlib.test_main() |