Skip to content

Commit

Permalink
Show VM's boot reason next to uptime
Browse files Browse the repository at this point in the history
This is only shown if the reason for boot was not a normal startup, e.g.
migration, snapshot revert...
  • Loading branch information
skobyda committed Jun 21, 2023
1 parent 0f349f5 commit a0487c8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
55 changes: 47 additions & 8 deletions src/components/vm/confirmDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useDialogs } from 'dialogs.jsx';
import { distanceToNow } from 'timeformat.js';

import { domainGetStartTime } from '../../libvirtApi/domain.js';
import { Enum } from '../../libvirtApi/helpers.js';

const _ = cockpit.gettext;

Expand Down Expand Up @@ -60,18 +61,56 @@ export const ConfirmDialog = ({ idPrefix, actionsList, title, titleIcon, vm }) =
</Button>
);

let body = (
<Bullseye>
<Spinner />
</Bullseye>
);
let body;
if (dialogLoading) {
body = (
<Bullseye>
<Spinner />
</Bullseye>
);
} else if (uptime) {
let uptimeStr = distanceToNow(new Date(uptime));

// https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRunningReason
switch (vm.stateReason) {
case Enum.VIR_DOMAIN_RUNNING_MIGRATED:
case Enum.VIR_DOMAIN_RUNNING_POSTCOPY: {
uptimeStr = cockpit.format(_("$0 since migration"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_FROM_SNAPSHOT: {
uptimeStr = cockpit.format(_("$0 since reverting to snapshot"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_RESTORED:
case Enum.VIR_DOMAIN_RUNNING_UNPAUSED: {
uptimeStr = cockpit.format(_("$0 since VM was resumed"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_MIGRATION_CANCELED:
case Enum.VIR_DOMAIN_RUNNING_POSTCOPY_FAILED: {
uptimeStr = cockpit.format(_("$0 since migration was cancelled"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_SAVE_CANCELED: {
uptimeStr = cockpit.format(_("$0 since failed save process"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_WAKEUP: {
uptimeStr = cockpit.format(_("$0 since wakeup event"), uptimeStr);
break;
}
case Enum.VIR_DOMAIN_RUNNING_CRASHED: {
uptimeStr = cockpit.format(_("$0 since resumed from crash"), uptimeStr);
break;
}
}

if (!dialogLoading) {
body = (uptime &&
body = (
<DescriptionList isHorizontal>
<DescriptionListGroup>
<DescriptionListTerm>{_("Uptime")}</DescriptionListTerm>
<DescriptionListDescription id="uptime">{distanceToNow(new Date(uptime))}</DescriptionListDescription>
<DescriptionListDescription id="uptime">{uptimeStr}</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
);
Expand Down
15 changes: 15 additions & 0 deletions test/check-machines-lifecycle
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class TestMachinesLifecycle(VirtualMachinesCase):
self.performAction("subVmTest2", "forceOff")

b.click("#vm-subVmTest2-system-run")
# wait for libvirt to update the internal state (reason) of VM
wait(lambda: "running (booted)" in m.execute("virsh domstate --reason subVmTest2"), delay=3)

# Check uptime
b.click("#vm-subVmTest2-system-shutdown-button")
Expand All @@ -244,6 +246,19 @@ class TestMachinesLifecycle(VirtualMachinesCase):
b.click(".pf-c-modal-box__footer button:contains(Cancel)")
b.wait_not_present("#vm-subVmTest2-system-confirm-action-modal")

# Check uptime with VM boot message
# Non-privileged user doesn't have access to system-connection VM's logs
if superuser:
m.execute("virsh managedsave --domain subVmTest2")
m.execute("virsh start --domain subVmTest2")
# wait for libvirt to update the internal state (reason) of VM
wait(lambda: "running (restored)" in m.execute("virsh domstate --reason subVmTest2"), delay=3)
b.click("#vm-subVmTest2-system-shutdown-button")
b.wait_visible("#vm-subVmTest2-system-confirm-action-modal")
b.wait_in_text("#vm-subVmTest2-system-confirm-action-modal #uptime", "since VM was resumed")
b.click(".pf-c-modal-box__footer button:contains(Cancel)")
b.wait_not_present("#vm-subVmTest2-system-confirm-action-modal")

b.set_input_text("#text-search", "subVmTest2")
self.waitVmRow("subVmTest2")
self.waitVmRow("subVmTest1", "system", False)
Expand Down

0 comments on commit a0487c8

Please sign in to comment.