Debian Codegraph @

test/verify/check-kdump

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2016 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import time
9
10 import testlib
11 from lib.constants import TEST_OS_DEFAULT
12 from machine import testvm
13
14
15 class KdumpHelpers(testlib.MachineCase):
16 def setUp(self):
17 super().setUp()
18 self.allow_restart_journal_messages()
19
20 def enableLocalSsh(self, machine: testvm.Machine | None = None) -> None:
21 machine = machine or self.machine
22 machine.execute("[ -f /root/.ssh/id_rsa ] || ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa")
23 machine.execute("cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys")
24 machine.execute("ssh-keyscan -H localhost >> /root/.ssh/known_hosts")
25 machine.execute("cat /root/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys; chown admin: /home/admin/.ssh/authorized_keys")
26
27 def assertActive(self, active: bool, browser: testlib.Browser | None = None) -> None:
28 browser = browser or self.browser
29 browser.wait_visible(".pf-v6-c-switch__input" + (":checked" if active else ":not(:checked)"))
30
31 def enableKdump(self):
32 if self.machine.image.startswith("fedora"):
33 self.machine.execute("systemctl enable kdump; kdumpctl reset-crashkernel")
34 self.machine.reboot()
35
36 def crashKernel(self, message: str, cancel: bool = False, machine: testvm.Machine | None = None,
37 browser: testlib.Browser | None = None) -> None:
38 browser = browser or self.browser
39 machine = machine or self.machine
40
41 browser.click("button:contains('Test configuration')")
42 browser.wait_in_text(".pf-v6-c-modal-box__body", message)
43 if cancel:
44 browser.click(".pf-v6-c-modal-box button:contains('Cancel')")
45 else:
46 # we should get a warning dialog, confirm
47 browser.click(f".pf-v6-c-modal-box button{self.danger_btn_class}")
48 # wait until we've actually triggered a crash
49 browser.wait_visible("button.pf-m-in-progress")
50
51 # wait for disconnect and then try connecting again
52 browser.switch_to_top()
53 with browser.wait_timeout(120):
54 browser.wait_in_text("div.curtains-ct h1", "Disconnected")
55 machine.disconnect()
56 machine.wait_boot(timeout_sec=300)
57
58 def enableNFSServer(self, machine: testvm.Machine | None = None) -> None:
59 machine = machine or self.machine
60 # set up NFS server
61 self.machines["nfs"].write("/etc/exports", "/srv/kdump 10.111.113.0/24(rw,no_root_squash)\n")
62 self.machines["nfs"].execute("mkdir -p /srv/kdump/var/crash; firewall-cmd --add-service nfs; systemctl restart nfs-server")
63
64 # there shouldn't be any crash reports in the target directory
65 self.assertEqual(machine.execute("find /var/crash -maxdepth 1 -mindepth 1 -type d"), "")
66
67 def run_ansible_playbook(self, browser: testlib.Browser, machine: testvm.Machine,
68 allow_failure: bool = False) -> None:
69 browser.click("#kdump-automation-script")
70 ansible_script_sel = ".automation-script-modal .pf-v6-c-modal-box__body section:nth-child(2) textarea"
71 machine.execute("mkdir -p roles/kdump/tasks")
72 ansible_script = browser.text(ansible_script_sel)
73 # show role for debugging
74 print("---- generated Ansible role -----")
75 print(ansible_script)
76 print("---------------------------------")
77 machine.write("roles/kdump/tasks/main.yml", ansible_script)
78 # Show stdout as this can fail, if so we want logs
79 machine.execute("ansible -vv -m include_role -a name=kdump localhost", check=not allow_failure, stdout=None)
80 browser.click(".pf-v6-c-modal-box__footer button:contains('Close')")
81 browser.wait_not_present(".automation-script-modal")
82
83
84 @testlib.skipOstree("kexec-tools not installed")
85 # Kdump page is hidden on Arch as it lacks the necessary kdump packages and grub infra
86 @testlib.skipImage("kexec-tools not installed", "debian-*", "ubuntu-*", "arch")
87 @testlib.skipImage("kdump not compatible with separate /var btrfs subvolume https://bugzilla.redhat.com/show_bug.cgi?id=2270423", "fedora-*")
88 @testlib.timeout(900)
89 class TestKdump(KdumpHelpers):
90 provision = {
91 "0": {"memory_mb": 2048},
92 }
93
94 def testBasic(self):
95 b = self.browser
96 m = self.machine
97
98 self.login_and_go("/kdump")
99
100 b.wait_visible("#app")
101
102 if m.image.startswith("fedora"):
103 # crashkernel command line not set, needs to be explicitly enabled in Fedora
104 b.wait_in_text(".pf-v6-c-alert__title", "Kernel did not boot with the crashkernel setting")
105 # no service on/off button
106 b.wait_not_present(".pf-v6-c-switch__input")
107
108 # disabled "Test configuration" button should have a tooltip
109 b.wait_visible("button:contains('Test configuration')[aria-disabled=true]")
110 b.mouse("button:contains('Test configuration')", "mouseenter")
111 b.wait_in_text(".pf-v6-c-tooltip", "kdump service")
112 b.mouse("button:contains('Test configuration')", "mouseleave")
113
114 # enable it
115 self.enableKdump()
116 self.login_and_go("/kdump")
117 else:
118 # enabled by default in RHEL
119 m.execute("until systemctl is-active kdump; do sleep 1; done")
120 self.assertActive(active=True)
121
122 # no alert about configuration
123 b.wait_not_present(".pf-v6-c-alert__title")
124
125 # there shouldn't be any crash reports in the target directory
126 self.assertEqual(m.execute("find /var/crash -maxdepth 1 -mindepth 1 -type d"), "")
127
128 b.wait_visible("#app")
129 self.enableLocalSsh()
130
131 # minimal nfs validation
132 b.wait_text("#kdump-target-info", "Local, /var/crash")
133
134 b.click("#kdump-change-target")
135 b.wait_visible("#kdump-settings-dialog")
136 b.set_val("#kdump-settings-location", "nfs")
137 serverInput = "#kdump-settings-nfs-server"
138 b.set_input_text(serverInput, "")
139 b.wait_visible(f"#kdump-settings-dialog button{self.primary_btn_class}:disabled")
140 b.set_input_text(serverInput, "localhost")
141 b.wait_visible(f"#kdump-settings-dialog button{self.primary_btn_class}:disabled")
142 b.click("#kdump-settings-dialog button.cancel")
143 b.wait_not_present("#kdump-settings-dialog")
144
145 # test compression
146 b.click("#kdump-change-target")
147 b.click("#kdump-settings-compression")
148 pathInput = "#kdump-settings-local-directory"
149 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
150 with b.wait_timeout(120): # needs to rebuild initrd
151 b.wait_not_present(pathInput)
152 m.execute("cat /etc/kdump.conf | grep -qE 'makedumpfile.*-c.*'")
153
154 # generate a valid kdump config with ssh target
155 b.click("#kdump-change-target")
156 b.set_val("#kdump-settings-location", "ssh")
157 sshInput = "#kdump-settings-ssh-server"
158 b.set_input_text(sshInput, "root@localhost")
159 sshKeyInput = "#kdump-settings-ssh-key"
160 pathInput = "#kdump-settings-ssh-directory"
161 b.set_input_text(sshKeyInput, "/root/.ssh/id_rsa")
162 b.set_input_text(pathInput, "/var/crash")
163 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
164 # rebuilding initrd might take a while on busy CI machines
165 with b.wait_timeout(120):
166 b.wait_not_present(pathInput)
167 self.crashKernel("copied through SSH to root@localhost:/var/crash as vmcore", cancel=True)
168
169 # we should have the amount of memory reserved that crashkernel=auto defaults to for our VM RAM size on RHEL-8-10.
170 # On RHEL-9 and upper there are fixed memory limits based fixed limits from crashkernel, ie. 2G-64G:256M
171 if m.image == "rhel-8-10":
172 b.wait_in_text("#app", "192 MiB")
173 else:
174 b.wait_in_text("#app", "256 MiB")
175 # service should start up properly and the button should be on
176 self.assertActive(active=True)
177 b.wait_text("#kdump-target-info", "Remote over SSH, root@localhost:/var/crash")
178
179 # try to change the path to a directory that doesn't exist
180 customPath = "/crash2"
181 b.click("#kdump-change-target")
182 b.set_val("#kdump-settings-location", "local")
183 pathInput = "#kdump-settings-local-directory"
184 b.set_input_text(pathInput, customPath)
185 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
186 # we should get an error
187 b.wait_in_text("#kdump-settings-dialog h4.pf-v6-c-alert__title",
188 f"Unable to save settings: Directory {customPath} isn't writable or doesn't exist")
189 # also allow the journal message about failed touch
190 self.allow_journal_messages(".*mktemp: failed to create file via template.*")
191 # create the directory and try again
192 m.execute(f"mkdir -p {customPath}")
193 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
194 with b.wait_timeout(120):
195 b.wait_not_present(pathInput)
196 b.wait_text("#kdump-target-info", f"Local, {customPath}")
197
198 # service has to restart after changing the config, wait for it to be running
199 # otherwise the button to test will be disabled
200 self.assertActive(active=True)
201
202 # crash the kernel and make sure it wrote a report into the right directory
203 self.crashKernel(f"stored in {customPath} as vmcore")
204 m.execute(f"until test -e {customPath}/127.0.0.1*/vmcore; do sleep 1; done", timeout=180)
205 self.assertIn("Kdump compressed dump", m.execute(f"file {customPath}/127.0.0.1*/vmcore"))
206
207 self.login_and_go("/kdump")
208 b.wait_visible("#app")
209
210 m.execute("cp /etc/kdump.conf /etc/kdump.conf.orig")
211 b.click("#kdump-automation-script")
212 b.click("button:contains('Shell script')")
213 shell_script_sel = ".automation-script-modal .pf-v6-c-modal-box__body section:nth-child(3) textarea"
214 # Change the kdump.conf while the dialog is open as changing it before does not allow us to open the dialog
215 m.write("/etc/kdump.conf", "invalid")
216 m.execute(b.text(shell_script_sel))
217 b.click(".pf-v6-c-modal-box__footer button:contains('Close')")
218 b.wait_not_present(".automation-script-modal")
219 m.execute("diff /etc/kdump.conf /etc/kdump.conf.orig", stdout=None)
220
221 # service errors
222
223 m.execute("systemctl disable --now kdump.service")
224 self.assertActive(active=False)
225 b.wait_not_present(".pf-v6-c-alert__title")
226
227 # service is absent (not installed)
228 m.execute("mv /usr/lib/systemd/system/kdump.service /usr/lib/systemd/system/kdump.service.disabled")
229 m.execute("systemctl daemon-reload")
230 b.wait_in_text(".pf-v6-c-alert__title", "Kdump service is not installed")
231
232 # put it back, but cause error on startup
233 m.execute("mv /usr/lib/systemd/system/kdump.service.disabled /usr/lib/systemd/system/kdump.service")
234 m.write("/etc/systemd/system/kdump.service.d/break.conf",
235 "[Service]\nExecStart=\nExecStart=/bin/false\n")
236 m.execute("systemctl daemon-reload")
237 b.wait_not_present(".pf-v6-c-alert__title")
238 b.click(".pf-v6-c-switch__input")
239 b.wait_in_text(".pf-v6-c-alert__title", "Service has an error")
240 self.assertActive(active=False)
241 # "more details" leads to services page
242 b.click(".pf-v6-c-alert__title button")
243 b.switch_to_top()
244 b.wait_js_cond('window.location.pathname === "/system/services"')
245 b.wait_js_cond('window.location.hash === "#/kdump.service"')
246 # revert breakage and start kdump again
247 m.execute("rm /etc/systemd/system/kdump.service.d/break.conf")
248 m.execute("systemctl daemon-reload; systemctl start kdump")
249
250 # lack of kexec_crash_size does not crash the kdump page
251 tmp_sys_kernel = "/tmp/kernel_sys/"
252 m.execute(f"mkdir {tmp_sys_kernel}")
253 m.execute(f"mount -o bind {tmp_sys_kernel} /sys/kernel")
254 b.go("/kdump")
255 b.reload()
256 b.enter_page("/kdump")
257 b.wait_visible("#app")
258 b.wait_in_text(".pf-v6-c-alert__title", "Kernel did not boot with the crashkernel setting")
259 # no memory detected and no page crash
260 b.wait_in_text(".pf-v6-c-card__body .pf-v6-c-description-list div.pf-v6-c-description-list__group:first-child",
261 "None")
262 m.execute("umount /sys/kernel")
263
264
265 @testlib.skipOstree("kexec-tools not installed")
266 @testlib.skipImage("kexec-tools not installed", "debian-*", "ubuntu-*", "arch")
267 @testlib.nondestructive
268 class TestKdumpConfiguration(KdumpHelpers):
269 def testBasic(self):
270 b = self.browser
271 m = self.machine
272
273 self.restore_file("/etc/kdump.conf")
274
275 m.execute("systemctl disable --now kdump")
276
277 self.login_and_go("/kdump")
278 b.wait_visible("#app")
279
280 # Check defaults
281 current = m.execute("grep '^core_collector' /etc/kdump.conf").strip()
282 m.execute("sed -i /^core_collector/d /etc/kdump.conf")
283 # Drop the custom path so we can make sure our changes are synced to JavaScript
284 m.execute("sed -i 's#^path /var/crash#path /var/tmp#' /etc/kdump.conf")
285 last_modified = m.execute("stat /etc/kdump.conf")
286 b.wait_text("#kdump-target-info", "Local, /var/tmp")
287 b.click("#kdump-change-target")
288 b.wait_visible("#kdump-settings-dialog")
289 b.set_input_text("#kdump-settings-local-directory", "/var/crash")
290 b.click("button:contains('Save')")
291 b.wait_not_present("#kdump-settings-dialog")
292 new = m.execute("grep '^core_collector' /etc/kdump.conf").strip()
293 self.assertEqual(current, new)
294 self.assertNotEqual(last_modified, m.execute("stat /etc/kdump.conf"))
295
296 # Check remote ssh location
297 b.click("#kdump-change-target")
298 b.wait_visible("#kdump-settings-dialog")
299 b.set_val("#kdump-settings-location", "ssh")
300 b.set_input_text("#kdump-settings-ssh-server", "admin@localhost")
301 b.set_input_text("#kdump-settings-ssh-key", "/home/admin/.ssh/id_rsa")
302 b.set_input_text("#kdump-settings-ssh-directory", "/var/tmp/crash")
303 b.click("button:contains('Save')")
304 b.wait_not_present("#kdump-settings-dialog")
305 conf = m.execute("cat /etc/kdump.conf")
306 self.assertIn("path /var/tmp/crash", conf)
307 self.assertIn("ssh admin@localhost", conf)
308 self.assertIn("sshkey /home/admin/.ssh/id_rsa", conf)
309
310 # Check remote NFS location
311 b.click("#kdump-change-target")
312 b.wait_visible("#kdump-settings-dialog")
313 b.set_val("#kdump-settings-location", "nfs")
314 b.set_input_text("#kdump-settings-nfs-server", "someserver")
315 b.set_input_text("#kdump-settings-nfs-export", "/srv")
316 b.click("button:contains('Save')")
317 b.wait_not_present("#kdump-settings-dialog")
318 conf = m.execute("cat /etc/kdump.conf")
319 self.assertIn("nfs someserver:/srv", conf)
320 # directory unspecified, using default path
321 self.assertNotIn("\npath ", conf)
322 self.assertNotIn("\nssh ", conf)
323
324 # NFS with custom path
325 b.click("#kdump-change-target")
326 b.wait_visible("#kdump-settings-dialog")
327 b.set_input_text("#kdump-settings-nfs-directory", "dumps")
328 b.click("button:contains('Save')")
329 b.wait_not_present("#kdump-settings-dialog")
330 conf = m.execute("cat /etc/kdump.conf")
331 self.assertIn("nfs someserver:/srv", conf)
332 self.assertIn("\npath dumps", conf)
333
334 # Check local location
335 b.click("#kdump-change-target")
336 b.wait_visible("#kdump-settings-dialog")
337 b.set_val("#kdump-settings-location", "local")
338 b.set_input_text("#kdump-settings-local-directory", "/var/tmp")
339 b.click("button:contains('Save')")
340 b.wait_not_present("#kdump-settings-dialog")
341 conf = m.execute("cat /etc/kdump.conf")
342 self.assertIn("path /var/tmp", conf)
343 self.assertNotIn("\nnfs ", conf)
344
345 # Check compression
346 current = m.execute("grep '^core_collector' /etc/kdump.conf").strip()
347 b.click("#kdump-change-target")
348 b.wait_visible("#kdump-settings-dialog")
349 b.set_checked("#kdump-settings-compression", val=True)
350 b.click("button:contains('Save')")
351 b.wait_not_present("#kdump-settings-dialog")
352 conf = m.execute("cat /etc/kdump.conf")
353 self.assertIn(current + " -c", conf)
354
355 def testConfigurationSUSE(self):
356 b = self.browser
357 m = self.machine
358
359 testConfig = [
360 "# some comment",
361 "KDUMP_DUMPFORMAT=compressed # suffix",
362 "KDUMP_SSH_IDENTITY=\"\"",
363 "skip this line",
364 "BAD_QUOTES=unquoted value # suffix",
365 "BAD_SPACES = 42 # comment",
366 "MORE_BAD_SPACES = 4 2 # long comment",
367 "KDUMP_SAVEDIR=ssh//missing/colon",
368 ]
369
370 # clean default config to trigger SUSE config mode
371 self.write_file("/etc/kdump.conf", "")
372 # write initial SUSE config (append to keep original contents as well)
373 self.write_file("/etc/sysconfig/kdump", "\n".join(testConfig), append=True)
374
375 m.execute("systemctl disable --now kdump")
376
377 self.login_and_go("/kdump")
378 b.wait_visible("#app")
379
380 # Check malformed lines
381 b.wait_text("#kdump-target-info", "No configuration found")
382 b.wait(lambda: "Malformed kdump config line: skip this line in /etc/sysconfig/kdump" in
383 '/'.join(self.browser.get_js_log()))
384 b.wait(lambda: "Malformed KDUMP_SAVEDIR entry: ssh//missing/colon in /etc/sysconfig/kdump" in
385 '/'.join(self.browser.get_js_log()))
386
387 # Remove malformed KDUMP_SAVEDIR to check default if nothing specified
388 m.execute("sed -i '/KDUMP_SAVEDIR=.*/d' /etc/sysconfig/kdump")
389 b.wait_text("#kdump-target-info", "Local, /var/crash")
390
391 # Check fixing of (some) malformed lines and local target without file://
392 m.execute("echo KDUMP_SAVEDIR=/tmp >> /etc/sysconfig/kdump")
393 b.wait_text("#kdump-target-info", "Local, /tmp")
394 b.click("#kdump-change-target")
395 b.wait_visible("#kdump-settings-dialog")
396 b.click("button:contains('Save')")
397 b.wait_not_present("#kdump-settings-dialog")
398 conf = m.execute("cat /etc/sysconfig/kdump")
399 self.assertIn('KDUMP_SAVEDIR=file:///tmp', conf)
400 self.assertIn('BAD_QUOTES="unquoted value" # suffix', conf)
401 self.assertIn('BAD_SPACES=42 # comment', conf)
402 self.assertIn('MORE_BAD_SPACES="4 2" # long comment', conf)
403
404 # Check remote ssh location
405 b.click("#kdump-change-target")
406 b.wait_visible("#kdump-settings-dialog")
407 b.set_val("#kdump-settings-location", "ssh")
408 b.set_input_text("#kdump-settings-ssh-server", "admin@localhost")
409 b.set_input_text("#kdump-settings-ssh-key", "/home/admin/.ssh/id_rsa")
410 b.set_input_text("#kdump-settings-ssh-directory", "/var/tmp/crash")
411 b.click("button:contains('Save')")
412 b.wait_not_present("#kdump-settings-dialog")
413 b.wait_text("#kdump-target-info", "Remote over SSH, admin@localhost:/var/tmp/crash")
414 conf = m.execute("cat /etc/sysconfig/kdump")
415 self.assertIn('KDUMP_SAVEDIR=ssh://admin@localhost/var/tmp/crash', conf)
416 self.assertIn('KDUMP_SSH_IDENTITY="/home/admin/.ssh/id_rsa"', conf)
417
418 # Check remote NFS location
419 b.click("#kdump-change-target")
420 b.wait_visible("#kdump-settings-dialog")
421 b.set_val("#kdump-settings-location", "nfs")
422 b.set_input_text("#kdump-settings-nfs-server", "someserver")
423 b.set_input_text("#kdump-settings-nfs-export", "/srv")
424 b.click("button:contains('Save')")
425 b.wait_not_present("#kdump-settings-dialog")
426 b.wait_text("#kdump-target-info", "Remote over NFS, someserver:/srv/")
427 conf = m.execute("cat /etc/sysconfig/kdump")
428 self.assertIn('KDUMP_SAVEDIR=nfs://someserver/srv', conf)
429 self.assertNotIn("ssh://", conf)
430
431 # Check local location
432 b.click("#kdump-change-target")
433 b.wait_visible("#kdump-settings-dialog")
434 b.set_val("#kdump-settings-location", "local")
435 b.set_input_text("#kdump-settings-local-directory", "/var/tmp")
436 b.click("button:contains('Save')")
437 b.wait_not_present("#kdump-settings-dialog")
438 b.wait_text("#kdump-target-info", "Local, /var/tmp")
439 conf = m.execute("cat /etc/sysconfig/kdump")
440 self.assertIn('KDUMP_SAVEDIR=file:///var/tmp', conf)
441 self.assertNotIn("nfs://", conf)
442
443 # Check compression
444 conf = m.execute("cat /etc/sysconfig/kdump")
445 self.assertIn('KDUMP_DUMPFORMAT=compressed', conf)
446 b.click("#kdump-change-target")
447 b.wait_visible("#kdump-settings-dialog")
448 b.set_checked("#kdump-settings-compression", val=False)
449 b.click("button:contains('Save')")
450 b.wait_not_present("#kdump-settings-dialog")
451 conf = m.execute("cat /etc/sysconfig/kdump")
452 self.assertIn('KDUMP_DUMPFORMAT=ELF', conf)
453 b.click("#kdump-change-target")
454 b.wait_visible("#kdump-settings-dialog")
455 b.set_checked("#kdump-settings-compression", val=True)
456 b.click("button:contains('Save')")
457 b.wait_not_present("#kdump-settings-dialog")
458 conf = m.execute("cat /etc/sysconfig/kdump")
459 self.assertIn('KDUMP_DUMPFORMAT=compressed', conf)
460
461 # Check remote FTP location (no config dialog)
462 m.execute("sed -i 's/KDUMP_SAVEDIR=.*/KDUMP_SAVEDIR=ftp:\\/\\/user@ftpserver\\/dumps1/g' /etc/sysconfig/kdump")
463 b.wait_text("#kdump-target-info", "Remote over FTP")
464
465 # Check remote SFTP location (no config dialog)
466 m.execute("sed -i 's/KDUMP_SAVEDIR=.*/KDUMP_SAVEDIR=sftp:\\/\\/sftpserver\\/dumps2/g' /etc/sysconfig/kdump")
467 b.wait_text("#kdump-target-info", "Remote over SFTP")
468
469 # Check remote CIFS location (no config dialog)
470 m.execute("sed -i 's/KDUMP_SAVEDIR=.*/KDUMP_SAVEDIR=cifs:\\/\\/user:pass@smbserver\\/dumps3/g' /etc/sysconfig/kdump")
471 b.wait_text("#kdump-target-info", "Remote over CIFS/SMB")
472
473
474 @testlib.skipOstree("kexec-tools not installed")
475 @testlib.skipImage("kexec-tools not installed", "debian-*", "ubuntu-*", "arch")
476 @testlib.skipImage("kdump not compatible with separate /var btrfs subvolume https://bugzilla.redhat.com/show_bug.cgi?id=2270423", "fedora-*")
477 @testlib.timeout(900)
478 class TestKdumpNFS(KdumpHelpers):
479 provision = {
480 "0": {"address": "10.111.113.1/24", "memory_mb": 2048, "capture_console": True},
481 "nfs": {"image": TEST_OS_DEFAULT, "address": "10.111.113.2/24"}
482 }
483
484 def testBasic(self):
485 m = self.machine
486 b = self.browser
487
488 self.enableNFSServer()
489
490 # set up client machine
491 self.enableKdump()
492 self.login_and_go("/kdump")
493 with b.wait_timeout(120): # needs to rebuild initrd
494 b.wait_visible(".pf-v6-c-switch__input:checked")
495
496 # Wait a few seconds so that the newly written kdump.conf is
497 # guaranteed to look older to kdump.service than the just
498 # created initrd.
499 #
500 time.sleep(5)
501
502 # switch to NFS
503 b.click("#kdump-change-target")
504 b.wait_visible("#kdump-settings-dialog")
505 b.set_val("#kdump-settings-location", "nfs")
506 b.set_input_text("#kdump-settings-nfs-server", "10.111.113.2")
507 b.set_input_text("#kdump-settings-nfs-export", "/srv/kdump")
508 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
509 # rebuilding initrd might take a while on busy CI machines
510 with b.wait_timeout(300):
511 b.wait_not_present("#kdump-settings-dialog")
512
513 # explicit nfs option, unset path
514 conf = m.execute("cat /etc/kdump.conf")
515 self.assertIn("\nnfs 10.111.113.2:/srv/kdump\n", conf)
516 self.assertNotIn("\npath", conf)
517
518 try:
519 self.crashKernel("copied through NFS to 10.111.113.2:/srv/kdump/var/crash")
520
521 # dump is done during boot, so should exist now
522 self.assertIn("Kdump compressed dump",
523 self.machines["nfs"].execute("file /srv/kdump/var/crash/10.111.113.1*/vmcore"))
524 except (testlib.Error, AssertionError):
525 self.machine.print_console_log()
526 raise
527
528 # set custom path
529 self.login_and_go("/kdump")
530 b.wait_visible(".pf-v6-c-switch__input:checked")
531 b.click("#kdump-change-target")
532 b.wait_visible("#kdump-settings-dialog")
533 b.set_input_text("#kdump-settings-nfs-directory", "dumps")
534 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
535 # dumps directory does not exist, error
536 b.wait_in_text("#kdump-settings-dialog h4.pf-v6-c-alert__title", "Unable to save settings")
537 # also shows error details
538 b.click("#kdump-settings-dialog div.pf-v6-c-alert__toggle button")
539 b.wait_in_text("#kdump-settings-dialog .pf-v6-c-code-block__code", 'does not exist in dump target "10.111.113.2:/srv/kdump"')
540 # create the directory on the NFS server
541 self.machines["nfs"].execute("mkdir /srv/kdump/dumps")
542 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
543 with b.wait_timeout(300):
544 b.wait_not_present("#kdump-settings-dialog")
545 conf = m.execute("cat /etc/kdump.conf")
546 self.assertIn("\nnfs 10.111.113.2:/srv/kdump\n", conf)
547 self.assertIn("\npath dumps\n", conf)
548
549 b.wait_visible(".pf-v6-c-switch__input:checked")
550
551 try:
552 self.crashKernel("copied through NFS to 10.111.113.2:/srv/kdump/dumps")
553 self.assertIn("Kdump compressed dump",
554 self.machines["nfs"].execute("file /srv/kdump/dumps/10.111.113.1*/vmcore"))
555 except (testlib.Error, AssertionError):
556 self.machine.print_console_log()
557 raise
558
559
560 @testlib.skipOstree("kexec-tools not installed")
561 @testlib.onlyImage("Only Fedora/RHEL has ansible on the image", "fedora-*", "rhel-9-*")
562 @testlib.skipImage("kdump not compatible with separate /var btrfs subvolume https://bugzilla.redhat.com/show_bug.cgi?id=2270423", "fedora-*")
563 @testlib.timeout(900)
564 class TestKdumpNFSAnsible(KdumpHelpers):
565 provision = {
566 "cockpit": {},
567 "kdump_ansible_machine": {"address": "10.111.113.1/24", "memory_mb": 2048, "capture_console": True},
568 "nfs": {"image": TEST_OS_DEFAULT, "address": "10.111.113.2/24"},
569 }
570
571 def testBasic(self):
572 b = self.browser
573 kdump_machine = self.machines["kdump_ansible_machine"]
574
575 # Drop rpm repos as otherwise dnf will hang when we run the ansible role
576 kdump_machine.execute("rm -rf /etc/yum.repos.d/* /var/cache/yum/* /var/cache/dnf/*")
577
578 self.enableNFSServer(kdump_machine)
579 self.machine.execute("systemctl disable --now kdump")
580
581 # switch to NFS
582 self.login_and_go("/kdump")
583 b.click("#kdump-change-target")
584 b.wait_visible("#kdump-settings-dialog")
585 b.set_val("#kdump-settings-location", "nfs")
586 b.set_input_text("#kdump-settings-nfs-server", "10.111.113.2")
587 b.set_input_text("#kdump-settings-nfs-export", "/srv/kdump")
588 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
589 b.wait_not_present("#kdump-settings-dialog")
590
591 # This requires a reboot
592 self.run_ansible_playbook(browser=b, machine=kdump_machine, allow_failure=True)
593 conf = kdump_machine.execute("cat /etc/kdump.conf")
594 self.assertIn("\n# Ansible managed\n", conf)
595 self.assertIn("\nnfs 10.111.113.2:/srv/kdump\n", conf)
596
597 kdump_machine.reboot()
598 kdump_machine.start_cockpit()
599 kdump_browser = self.new_browser(kdump_machine)
600
601 # Verify that kdump runs and crashkernel is configured
602 kdump_machine.execute("until systemctl is-active kdump; do sleep 1; done")
603 kdump_browser.login_and_go("/kdump")
604 kdump_browser.wait_visible(".pf-v6-c-switch__input:checked")
605 kdump_browser.wait_in_text("#app", "256 MiB")
606 self.assertActive(active=True, browser=kdump_browser)
607
608 try:
609 self.crashKernel("copied through NFS to 10.111.113.2:/srv/kdump/var/crash", machine=kdump_machine, browser=kdump_browser)
610
611 # dump is done during boot, so should exist now
612 self.assertIn("Kdump compressed dump",
613 self.machines["nfs"].execute("file /srv/kdump/var/crash/10.111.113.1*/vmcore"))
614 except (testlib.Error, AssertionError):
615 kdump_machine.print_console_log()
616 raise
617
618
619 @testlib.skipOstree("kexec-tools not installed")
620 @testlib.onlyImage("Only Fedora/RHEL has ansible on the image", "fedora-*", "rhel-9-*")
621 @testlib.skipImage("kdump not compatible with separate /var btrfs subvolume https://bugzilla.redhat.com/show_bug.cgi?id=2270423", "fedora-*")
622 @testlib.timeout(900)
623 class TestKdumpAnsible(KdumpHelpers):
624 provision = {
625 "cockpit": {},
626 "kdump_ansible_machine": {"memory_mb": 2048},
627 }
628
629 def testBasic(self):
630 m = self.machine
631 b = self.browser
632
633 kdump_machine = self.machines['kdump_ansible_machine']
634
635 # Drop rpm repos as otherwise dnf will hang when we run the ansible role
636 kdump_machine.execute("rm -rf /etc/yum.repos.d/* /var/cache/yum/* /var/cache/dnf/*")
637
638 m.execute("systemctl disable --now kdump")
639
640 self.login_and_go("/kdump")
641 customPath = "/crash2"
642
643 m.execute(f"mkdir -p {customPath}")
644 b.click("#kdump-change-target")
645 b.set_val("#kdump-settings-location", "local")
646 pathInput = "#kdump-settings-local-directory"
647 b.set_input_text(pathInput, customPath)
648 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
649 b.wait_text("#kdump-target-info", f"Local, {customPath}")
650
651 # HACK: workaround ansible role not creating /var/crash2 https://github.com/linux-system-roles/kdump/issues/8
652 kdump_machine.execute(f"mkdir -p {customPath}")
653
654 # This requires a reboot
655 self.run_ansible_playbook(browser=b, machine=kdump_machine, allow_failure=True)
656 kdump_machine.reboot()
657
658 kdump_machine.start_cockpit()
659 kdump_browser = self.new_browser(kdump_machine)
660
661 kdump_machine.execute("until systemctl is-active kdump; do sleep 1; done")
662 kdump_browser.login_and_go("/kdump")
663
664 # Verify that kdump runs and crashkernel is configured
665 kdump_browser.wait_in_text("#app", "256 MiB")
666 self.assertActive(active=True, browser=kdump_browser)
667
668 # Second run should be succeed as crashkernel is now set in the kernel cmdline
669 self.run_ansible_playbook(browser=b, machine=kdump_machine)
670
671 conf = kdump_machine.execute("cat /etc/kdump.conf")
672 self.assertIn("\n# Ansible managed\n", conf)
673 self.assertIn(f"\npath {customPath}\n", conf)
674
675 self.crashKernel(f"stored in {customPath} as vmcore", machine=kdump_machine, browser=kdump_browser)
676 kdump_machine.execute(f"until test -e {customPath}/127.0.0.1*/vmcore; do sleep 1; done", timeout=180)
677 self.assertIn("Kdump compressed dump", kdump_machine.execute(f"file {customPath}/127.0.0.1*/vmcore"))
678
679 # Test SSH without a username, for this we first need to first change
680 # to local not run into a race to detect that the generated kdump.conf
681 # was changed. As the #kdump-change-target does not show the remote ssh user/server.
682 b.click("#kdump-change-target")
683 b.set_val("#kdump-settings-location", "local")
684 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
685 b.wait_not_present("#kdump-settings-dialog")
686 b.wait_text("#kdump-target-info", "Local, /var/crash")
687
688 b.click("#kdump-change-target")
689 b.set_val("#kdump-settings-location", "ssh")
690 sshInput = "#kdump-settings-ssh-server"
691 b.set_input_text(sshInput, "admin@localhost")
692 sshKeyInput = "#kdump-settings-ssh-key"
693 pathInput = "#kdump-settings-ssh-directory"
694 b.set_input_text(sshKeyInput, "/root/.ssh/id_rsa")
695 b.set_input_text(pathInput, "/var/crash")
696 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
697 b.wait_not_present(pathInput)
698 b.wait_text("#kdump-target-info", "Remote over SSH, admin@localhost:/var/crash")
699
700 self.enableLocalSsh()
701 # running the role starts kdump.service which verifies if /var/crash is readable for the admin
702 kdump_machine.start_cockpit()
703 kdump_machine.execute("chown admin: /var/crash")
704 self.run_ansible_playbook(browser=b, machine=kdump_machine)
705 conf = kdump_machine.execute("cat /etc/kdump.conf")
706 self.assertIn("\n# Ansible managed\n", conf)
707 self.assertIn("\nssh admin@localhost\n", conf)
708 self.assertIn("\nsshkey /root/.ssh/id_rsa\n", conf)
709 self.assertIn("\npath /var/crash\n", conf)
710
711 kdump_browser.login_and_go("/kdump")
712 kdump_browser.wait_text("#kdump-target-info", "Remote over SSH, admin@localhost:/var/crash")
713 self.crashKernel("copied through SSH to admin@localhost:/var/crash as vmcore", cancel=True,
714 browser=kdump_browser, machine=kdump_machine)
715
716 b.click("#kdump-change-target")
717 sshInput = "#kdump-settings-ssh-server"
718 b.set_input_text(sshInput, "localhost")
719 b.set_input_text(pathInput, "/var/crash2")
720 b.click(f"#kdump-settings-dialog button{self.primary_btn_class}")
721 b.wait_not_present(sshInput)
722 b.wait_text("#kdump-target-info", "Remote over SSH, localhost:/var/crash2")
723
724 self.run_ansible_playbook(browser=b, machine=kdump_machine)
725 conf = kdump_machine.execute("cat /etc/kdump.conf")
726 self.assertIn("\nssh root@localhost\n", conf)
727 self.assertIn("\npath /var/crash2\n", conf)
728
729
730 if __name__ == '__main__':
731 testlib.test_main()