Skip to content

Commit

Permalink
watchdog: Detect permanent ones and adapt accordingly
Browse files Browse the repository at this point in the history
The "q35" machines have a watchdog by default, and it can not be
removed with Cockpit. Trying that will lead to an error or just do
nothing. Let's not show the "Remove" action for them.
  • Loading branch information
mvollmer authored and martinpitt committed May 3, 2024
1 parent d443387 commit 7d7a5b2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/components/vm/overview/watchdog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const WatchdogModalAlert = ({ dialogError }) => {
return <ModalError dialogError={dialogError.text} dialogErrorDetail={dialogError.detail} />;
};

export const WatchdogModal = ({ vm, isWatchdogAttached, idPrefix }) => {
export const WatchdogModal = ({ vm, isWatchdogAttached, isRemovable, idPrefix }) => {
const [dialogError, setDialogError] = useState();
const [watchdogAction, setWatchdogAction] = useState(vm.watchdog.action || SUPPORTEDACTIONS[0]); // use first option as default
const [inProgress, setInProgress] = useState(false);
Expand Down Expand Up @@ -182,7 +182,7 @@ export const WatchdogModal = ({ vm, isWatchdogAttached, idPrefix }) => {
isDisabled={inProgress}>
{_("Apply on next boot")}
</Button>}
{isWatchdogAttached &&
{isWatchdogAttached && isRemovable &&
<Button variant='secondary'
id="watchdog-dialog-detach"
onClick={detach}
Expand Down Expand Up @@ -228,8 +228,17 @@ export const WatchdogLink = ({ vm, idPrefix, onAddErrorNotification }) => {

const isWatchdogAttached = Object.keys(vm.watchdog).length > 0;

// The Q35 chipset has a "Intel TCO" watchdog built into the
// southbridge, and it can't be removed.

const isRemovable = (vm.watchdog.model !== "itco");

function open() {
Dialogs.show(<WatchdogModal vm={vm} isWatchdogAttached={isWatchdogAttached} idPrefix={idPrefix} onAddErrorNotification={onAddErrorNotification} />);
Dialogs.show(<WatchdogModal vm={vm}
isWatchdogAttached={isWatchdogAttached}
isRemovable={isRemovable}
idPrefix={idPrefix}
onAddErrorNotification={onAddErrorNotification} />);
}

return (
Expand Down
38 changes: 35 additions & 3 deletions test/check-machines-settings
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):
virsh_output = m.execute("virsh dumpxml subVmTest1 | xmllint --xpath '/domain/devices/watchdog/@action' -").strip()
self.assertEqual(virsh_output, f'action="{action}"')

def setWatchdogActionLive(action, previous_action=None, reboot_machine=False):
def setWatchdogActionLive(action, previous_action=None, reboot_machine=False, add=False, removable=True):
openWatchDogDialog()

b.click(f"#{action}")
Expand All @@ -556,6 +556,16 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):
# When attaching adding a new watchdog, no message should be present
b.wait_not_present("#vm-subVmTest1-watchdog-modal #vm-subVmTest1-idle-message")

if add:
b.wait_in_text("#watchdog-dialog-apply", "Add")
else:
b.wait_in_text("#watchdog-dialog-apply", "Save")

if removable and not add:
b.wait_visible("#watchdog-dialog-detach")
else:
b.wait_not_present("#watchdog-dialog-detach")

closeWatchDogDialog("#watchdog-dialog-apply")

if previous_action:
Expand Down Expand Up @@ -643,13 +653,13 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):
b.wait_in_text("#vm-subVmTest1-system-state", "Running")

# Test configuring watchdog for running VM
setWatchdogActionLive(action="reset")
setWatchdogActionLive(action="reset", add=True)
setWatchdogActionLive(action="pause", previous_action="reset")
# Make sure that the VM booted normally before attempting to hotunplug
self.waitGuestBooted(args['logfile'])
removeWatchdogDevice(live=True)
# Check rebooting machine will not unexpectedly affect watchdog configuration
setWatchdogActionLive(action="poweroff", reboot_machine=True)
setWatchdogActionLive(action="poweroff", reboot_machine=True, add=True)

m.execute("virsh destroy subVmTest1")

Expand Down Expand Up @@ -705,6 +715,28 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):
b.wait_visible("#watchdog-dialog-apply[aria-disabled=true]")
b.mouse("#watchdog-dialog-apply", "mouseenter")
b.wait_visible("#watchdog-live-edit-tooltip")
b.click("#vm-subVmTest2-watchdog-modal button[aria-label=Close]")
b.wait_not_present("#vm-subVmTest2-watchdog-modal")

self.goToMainPage()
self.waitPageInit()

m.execute("virsh destroy subVmTest2")

# Create a Q35 machine, which has a permanent watchdog that
# can't be removed. (Some older versions of libvirt don't add
# a watchdog.)

m.execute("virsh destroy subVmTest1; virsh undefine subVmTest1")
args = self.createVm("subVmTest1", os="linux2022")
has_watchdog = m.image not in ["debian-stable", "ubuntu-2204", "rhel-8-10"]

self.goToVmPage("subVmTest1")
if has_watchdog:
b.wait_in_text("#vm-subVmTest1-watchdog-state", "Reset")
setWatchdogActionLive(action="pause", previous_action="reset", reboot_machine=True, removable=False)
else:
b.wait_in_text("#vm-subVmTest1-watchdog-state", "none")

def testVsock(self):
b = self.browser
Expand Down

0 comments on commit 7d7a5b2

Please sign in to comment.