| 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 testlib |
| 9 |
|
| 10 |
|
| 11 |
@testlib.skipBeiboot("host switching disabled in beiboot mode") |
| 12 |
class TestShutdownRestart(testlib.MachineCase): |
| 13 |
provision = { |
| 14 |
"machine1": {"address": "10.111.113.1/20"}, |
| 15 |
"machine2": {"address": "10.111.113.2/20"} |
| 16 |
} |
| 17 |
|
| 18 |
def setUp(self): |
| 19 |
super().setUp() |
| 20 |
self.setup_provisioned_hosts() |
| 21 |
|
| 22 |
def testBasic(self): |
| 23 |
m = self.machine |
| 24 |
b = self.browser |
| 25 |
|
| 26 |
m2 = self.machines['machine2'] |
| 27 |
b2 = self.new_browser(m2) |
| 28 |
|
| 29 |
# Disable pre-loading packagekit, dnf needs-restarting (dnf 4) consumes tons of cpu/memory on RHEL-10-1 |
| 30 |
self.disable_preload("packagekit") |
| 31 |
self.disable_preload("packagekit", machine=m2) |
| 32 |
|
| 33 |
self.enable_multihost(m2) |
| 34 |
|
| 35 |
m.start_cockpit() |
| 36 |
|
| 37 |
self.login_and_go("/system") |
| 38 |
|
| 39 |
# Reboot |
| 40 |
b.click("#reboot-button") |
| 41 |
b.wait_popup("shutdown-dialog") |
| 42 |
b.wait_in_text(f"#shutdown-dialog button{self.danger_btn_class}", 'Reboot') |
| 43 |
b.set_input_text("#message", "Rebooting for maintenance") |
| 44 |
b.click("#delay") |
| 45 |
b.click("button:contains('No delay')") |
| 46 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 47 |
b.click(f"#shutdown-dialog button{self.danger_btn_class}") |
| 48 |
b.switch_to_top() |
| 49 |
|
| 50 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 51 |
|
| 52 |
self.wait_reboot() |
| 53 |
m.start_cockpit() |
| 54 |
b.click("#machine-reconnect") |
| 55 |
b.wait_visible("#login") |
| 56 |
|
| 57 |
self.allow_journal_messages("Shutdown scheduled for .*") |
| 58 |
self.check_journal_messages() |
| 59 |
|
| 60 |
m2.start_cockpit() |
| 61 |
b2.login_and_go("/system") |
| 62 |
|
| 63 |
# Add machine with static IP to m2 |
| 64 |
b2.add_machine("10.111.113.1") |
| 65 |
b2.wait_text("#system_information_hostname_text", "machine1") |
| 66 |
|
| 67 |
# Check auto reconnect on reboot |
| 68 |
b2.become_superuser() |
| 69 |
b2.click("#reboot-button") |
| 70 |
b2.wait_popup("shutdown-dialog") |
| 71 |
b2.wait_in_text(f"#shutdown-dialog button{self.danger_btn_class}", 'Reboot') |
| 72 |
b2.click("#delay") |
| 73 |
b2.click("button:contains('No delay')") |
| 74 |
b2.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 75 |
b2.click(f"#shutdown-dialog button{self.danger_btn_class}") |
| 76 |
b2.switch_to_top() |
| 77 |
|
| 78 |
b2.wait_visible(".curtains-ct") |
| 79 |
b2.wait_visible(".curtains-ct .pf-v6-c-spinner") |
| 80 |
b2.wait_in_text(".curtains-ct h1", "rebooting") |
| 81 |
|
| 82 |
self.wait_reboot() |
| 83 |
|
| 84 |
with b2.wait_timeout(30): |
| 85 |
b2.wait_visible("#machine-troubleshoot") |
| 86 |
b2.start_machine_troubleshoot(password="foobar", expect_warning=False) |
| 87 |
|
| 88 |
b2.enter_page("/system", host="10.111.113.1", reconnect=False) |
| 89 |
|
| 90 |
# Try to insert an invalid time |
| 91 |
self.login_and_go("/system") |
| 92 |
b.enter_page("/system") |
| 93 |
b.click("#shutdown-group") # caret |
| 94 |
b.click("#shutdown") |
| 95 |
b.wait_popup("shutdown-dialog") |
| 96 |
b.wait_not_present("#delay-helper") |
| 97 |
b.click("#delay") |
| 98 |
b.click("button:contains('Specific time')") |
| 99 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "Specific time") |
| 100 |
b.wait_not_val("#shutdown-time-input", "") |
| 101 |
b.wait_not_present("#delay-helper") |
| 102 |
old = b.val("#shutdown-time-input") |
| 103 |
b.set_input_text("#shutdown-time-input", "blah") |
| 104 |
b.wait_text("#delay-helper", "Invalid time format") |
| 105 |
b.wait_visible(f"#shutdown-dialog button{self.danger_btn_class}:disabled") |
| 106 |
|
| 107 |
# Now set a correct time |
| 108 |
b.set_input_text("#shutdown-time-input", old) |
| 109 |
b.wait_visible(f"#shutdown-dialog button{self.danger_btn_class}:not(disabled)") |
| 110 |
b.wait_not_present("#delay-helper") |
| 111 |
|
| 112 |
# Try to insert an invalid date |
| 113 |
old_date = b.val(".shutdown-date-picker input") |
| 114 |
b.set_input_text(".shutdown-date-picker input", "20/0x/2021") |
| 115 |
b.wait_val(".shutdown-date-picker input", "20/0x/2021") |
| 116 |
b.wait_text("#delay-helper", "Invalid date format") |
| 117 |
b.wait_visible(f"#shutdown-dialog button{self.danger_btn_class}:disabled") |
| 118 |
|
| 119 |
# Restore the valid date before opening the picker, to avoid |
| 120 |
# https://github.com/cockpit-project/cockpit/issues/23205 |
| 121 |
b.set_input_text(".shutdown-date-picker input", old_date) |
| 122 |
b.wait_not_present("#delay-helper") |
| 123 |
|
| 124 |
# Insert a date using the widget dropdown |
| 125 |
b.click("button[aria-label='Toggle date picker']") |
| 126 |
today_label = m.execute("date +'%-d %B %Y'").strip() |
| 127 |
today_format = m.execute("date +'%Y-%m-%d'").strip() |
| 128 |
b.click(f".pf-v6-c-calendar-month__dates-cell:not(.pf-m-adjacent-month) button[aria-label='{today_label}']") |
| 129 |
b.wait_val(".shutdown-date-picker input", today_format) |
| 130 |
b.blur(".shutdown-date-picker input") |
| 131 |
|
| 132 |
# Power off |
| 133 |
b.click(f"#shutdown-dialog button{self.danger_btn_class}") |
| 134 |
b.switch_to_top() |
| 135 |
|
| 136 |
# we don't need to wait for the dialog to close here, just the disconnect |
| 137 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 138 |
|
| 139 |
m.wait_poweroff() |
| 140 |
|
| 141 |
|
| 142 |
class TestUncleanShutdownStatus(testlib.MachineCase): |
| 143 |
|
| 144 |
def _cleanReboot(self): |
| 145 |
m = self.machine |
| 146 |
b = self.browser |
| 147 |
b.click("#reboot-button") |
| 148 |
b.wait_popup("shutdown-dialog") |
| 149 |
b.wait_in_text(f"#shutdown-dialog button{self.danger_btn_class}", 'Reboot') |
| 150 |
b.set_input_text("#message", "Rebooting for maintenance") |
| 151 |
b.click("#delay") |
| 152 |
b.click("button:contains('No delay')") |
| 153 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 154 |
b.click(f"#shutdown-dialog button{self.danger_btn_class}") |
| 155 |
|
| 156 |
b.switch_to_top() |
| 157 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 158 |
|
| 159 |
self.wait_reboot() |
| 160 |
m.start_cockpit() |
| 161 |
b.click("#machine-reconnect") |
| 162 |
b.wait_visible("#login") |
| 163 |
self.login_and_go("/system") |
| 164 |
|
| 165 |
def _uncleanReboot(self): |
| 166 |
m = self.machine |
| 167 |
b = self.browser |
| 168 |
m.spawn("reboot -f", "reboot") |
| 169 |
|
| 170 |
b.switch_to_top() |
| 171 |
with b.wait_timeout(30): |
| 172 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 173 |
|
| 174 |
self.wait_reboot() |
| 175 |
m.start_cockpit() |
| 176 |
b.click("#machine-reconnect") |
| 177 |
b.wait_visible("#login") |
| 178 |
self.login_and_go("/system") |
| 179 |
|
| 180 |
def testBasic(self): |
| 181 |
m = self.machine |
| 182 |
b = self.browser |
| 183 |
|
| 184 |
# Disable pre-loading packagekit, dnf needs-restarting (dnf 4) consumes tons of cpu/memory on RHEL-10-1 |
| 185 |
self.disable_preload("packagekit") |
| 186 |
|
| 187 |
m.start_cockpit() |
| 188 |
self.login_and_go("/system") |
| 189 |
b.wait_visible('#system_information_os_text') |
| 190 |
b.wait_not_present("#unclean-shutdown-status") |
| 191 |
|
| 192 |
# Unclean reboot |
| 193 |
self._uncleanReboot() |
| 194 |
b.wait_visible("#unclean-shutdown-status") |
| 195 |
b.wait_in_text("#unclean-shutdown-status", "Unclean shutdown") |
| 196 |
|
| 197 |
# Link to logs page |
| 198 |
b.click("#unclean-shutdown-status button:contains('View logs')") |
| 199 |
b.switch_to_top() |
| 200 |
b.wait_js_cond('window.location.pathname == "/system/logs"') |
| 201 |
b.wait_js_cond('window.location.hash == "#/?boot=-1"') |
| 202 |
|
| 203 |
# Dismiss |
| 204 |
b.go("/system") |
| 205 |
b.enter_page("/system") |
| 206 |
b.click("#unclean-shutdown-status-dismiss") |
| 207 |
b.wait_not_present("#unclean-shutdown-status") |
| 208 |
|
| 209 |
# Clean reboot |
| 210 |
self._cleanReboot() |
| 211 |
b.wait_not_present("#unclean-shutdown-status") |
| 212 |
|
| 213 |
|
| 214 |
if __name__ == '__main__': |
| 215 |
testlib.test_main() |