1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
#!/usr/bin/python3
# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
import parent
from testlib import *
@skipImage("kexec-tools not installed", "fedora-coreos", "debian-stable",
"debian-testing", "ubuntu-2004", "ubuntu-stable")
@timeout(900)
@skipImage("Do not test BaseOS packages", "rhel-8-3-distropkg", "rhel-8-4-distropkg")
class TestKdump(MachineCase):
def rreplace(self, s, old, new, count):
li = s.rsplit(old, count)
return new.join(li)
def enableKdump(self):
if self.machine.image in ["rhel-8-3", "rhel-8-4"]:
# these images use BootLoaderSpec and grubenv
self.sed_file('/^kernelopts=/ { s/crashkernel=[^ ]*//; s/$/ crashkernel=256M/; }', '/boot/grub2/grubenv')
else:
lines = self.machine.execute(command="cat /etc/default/grub", quiet=True).split("\n")
lines = map(lambda line: self.rreplace(line, '"', ' crashkernel=256M"', 1)
if line.startswith("GRUB_CMDLINE_LINUX") else line, lines)
self.machine.write("/etc/default/grub", "\n".join(lines))
self.machine.execute("grub2-mkconfig -o /boot/grub2/grub.cfg")
self.machine.execute("mkdir -p /var/crash")
def enableLocalSsh(self):
self.machine.execute("[ -f /root/.ssh/id_rsa ] || ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa")
self.machine.execute("cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys")
self.machine.execute("ssh-keyscan -H localhost >> /root/.ssh/known_hosts")
def rebootMachine(self):
# Now reboot things
self.machine.spawn("sync && sync && sync && sleep 0.1 && reboot", "reboot")
self.machine.wait_reboot()
self.machine.start_cockpit()
self.browser.switch_to_top()
self.browser.relogin("/kdump")
def testBasic(self):
b = self.browser
m = self.machine
b.wait_timeout(120)
self.allow_restart_journal_messages()
m.execute("systemctl enable kdump && systemctl start kdump || true")
self.login_and_go("/kdump")
b.wait_visible("#app")
def assertActive(active):
b.wait_visible(".pf-c-switch__input" + (active and ":checked" or ":not(:checked)"))
if m.image in ["rhel-8-3", "rhel-8-4", "centos-8-stream"]:
# some OSes have kdump enabled by default (crashkernel=auto)
b.wait_in_text("#app", "Service is running")
assertActive(True)
else:
# right now we have no memory reserved
b.mouse("#app span.popover-ct-kdump", "mouseenter")
b.wait_in_text(".pf-c-tooltip", "No memory reserved.")
b.mouse("#app span.popover-ct-kdump", "mouseleave")
# newer kdump.service have `ConditionKernelCommandLine=crashkernel` which fails gracefully
unit = m.execute("systemctl cat kdump.service")
if 'ConditionKernelCommandLine=crashkernel' in unit:
# service should indicate that the unit is stopped
b.wait_in_text("#app", "Service is stopped")
else:
# service should indicate an error
b.wait_in_text("#app", "Service has an error")
# ... and the button should be off
assertActive(False)
# there shouldn't be any crash reports in the target directory
self.assertEqual(m.execute("""find "/var/crash" -maxdepth 1 -mindepth 1 -type d -exec echo {} \;"""), "")
self.enableKdump()
self.rebootMachine()
b.wait_visible("#app")
self.enableLocalSsh()
# minimal nfs validation
settingsLink = "button:contains('locally in /var/crash')"
b.click(settingsLink)
b.set_val("#kdump-settings-location", "nfs")
mountInput = "#kdump-settings-nfs-mount"
b.set_input_text(mountInput, ":/var/crash")
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
b.wait_visible("h4.pf-c-alert__title:contains('Unable to apply settings')")
b.set_input_text(mountInput, "localhost:")
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
b.wait_visible("h4.pf-c-alert__title:contains('Unable to apply settings')")
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
# test compression
b.click(settingsLink)
b.click("#kdump-settings-compression")
pathInput = "#kdump-settings-local-directory"
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
b.wait_not_present(pathInput)
m.execute("cat /etc/kdump.conf | grep -qE 'makedumpfile.*-c.*'")
# generate a valid kdump config with ssh target
b.click(settingsLink)
b.set_val("#kdump-settings-location", "ssh")
sshInput = "#kdump-settings-ssh-server"
b.set_input_text(sshInput, "root@localhost")
sshKeyInput = "#kdump-settings-ssh-key"
b.set_input_text(sshKeyInput, "/root/.ssh/id_rsa")
b.set_input_text(pathInput, "/var/crash")
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
b.wait_not_present(pathInput)
# we should have the amount of memory reserved that we indicated
b.wait_in_text("#app", "256 MiB")
# service should start up properly and the button should be on
b.wait_in_text("#app", "Service is running")
assertActive(True)
b.wait_in_text("#app", "Service is running")
# try to change the path to a directory that doesn't exist
customPath = "/var/crash2"
settingsLink = "button:contains('Remote over SSH')"
b.click(settingsLink)
b.set_val("#kdump-settings-location", "local")
pathInput = "#kdump-settings-local-directory"
b.set_input_text(pathInput, customPath)
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
# we should get an error
b.wait_visible("h4.pf-c-alert__title:contains('Unable to apply settings')")
# also allow the journal message about failed touch
self.allow_journal_messages(".*mktemp: failed to create file via template.*")
# create the directory and try again
m.execute("mkdir -p {0}".format(customPath))
b.click("button{}:contains('Apply')".format(self.primary_btn_class))
b.wait_not_present(pathInput)
b.wait_visible("button:contains('locally in {0}')".format(customPath))
# service has to restart after changing the config, wait for it to be running
# otherwise the button to test will be disabled
b.wait_in_text("#app", "Service is running")
assertActive(True)
# crash the kernel and make sure it wrote a report into the right directory
b.click("button{}".format(self.default_btn_class))
# we should get a warning dialog, confirm
crashButton = "button{}:contains('Crash system')".format(self.danger_btn_class)
b.click(crashButton)
# wait until we've actuall triggered a crash
b.wait_visible(".dialog-wait-ct")
# wait for disconnect and then try connecting again
b.switch_to_top()
b.wait_in_text("div.curtains-ct h1", "Disconnected")
m.disconnect()
m.wait_boot(timeout_sec=300)
#b.click("#machine-reconnect")
#b.expect_load()
#b.wait_visible("#login")
self.assertNotEqual(
m.execute("""find "{0}" -maxdepth 1 -mindepth 1 -type d -exec echo {{}} \;""".format(customPath)), "")
@nondestructive
def testConfiguration(self):
b = self.browser
m = self.machine
self.restore_file("/etc/kdump.conf")
m.execute("systemctl disable --now kdump")
self.login_and_go("/kdump")
b.wait_visible("#app")
# Check remote ssh location
b.click("#kdump-change-target")
b.wait_visible("#kdump-settings-dialog")
b.set_val("#kdump-settings-location", "ssh")
b.set_input_text("#kdump-settings-ssh-server", "admin@localhost")
b.set_input_text("#kdump-settings-ssh-key", "/home/admin/.ssh/id_rsa")
b.set_input_text("#kdump-settings-local-directory", "/var/tmp/crash")
b.click("button:contains('Apply')")
b.wait_not_present("#kdump-settings-dialog")
conf = m.execute("cat /etc/kdump.conf")
self.assertIn("path /var/tmp/crash", conf)
self.assertIn("ssh admin@localhost", conf)
self.assertIn("sshkey /home/admin/.ssh/id_rsa", conf)
# Check remote NFS location
b.click("#kdump-change-target")
b.wait_visible("#kdump-settings-dialog")
b.set_val("#kdump-settings-location", "nfs")
b.set_input_text("#kdump-settings-nfs-mount", "localhost:/var/tmp/crash")
b.click("button:contains('Apply')")
b.wait_not_present("#kdump-settings-dialog")
conf = m.execute("cat /etc/kdump.conf")
self.assertIn("nfs localhost:/var/tmp/crash", conf)
self.assertNotIn("path /var/tmp/crash", conf)
self.assertNotIn("ssh admin@localhost", conf)
self.assertNotIn("sshkey /home/admin/.ssh/id_rsa", conf)
# Check local location
b.click("#kdump-change-target")
b.wait_visible("#kdump-settings-dialog")
b.set_val("#kdump-settings-location", "local")
b.set_input_text("#kdump-settings-local-directory", "/var/tmp")
b.click("button:contains('Apply')")
b.wait_not_present("#kdump-settings-dialog")
conf = m.execute("cat /etc/kdump.conf")
self.assertIn("path /var/tmp", conf)
self.assertNotIn("nfs localhost:/var/tmp/crash", conf)
# Check compression
current = m.execute("grep '^core_collector' /etc/kdump.conf").strip()
b.click("#kdump-change-target")
b.wait_visible("#kdump-settings-dialog")
b.set_checked("#kdump-settings-compression", True)
b.click("button:contains('Apply')")
b.wait_not_present("#kdump-settings-dialog")
conf = m.execute("cat /etc/kdump.conf")
self.assertIn(current + " -c", conf)
if __name__ == '__main__':
test_main()
|