Skip to content

feat: add QEMU hard power cycle support#30

Open
bdegeeter wants to merge 1 commit into
spectrocloud:masterfrom
bdegeeter:pr/qemu-hard-power-cycle
Open

feat: add QEMU hard power cycle support#30
bdegeeter wants to merge 1 commit into
spectrocloud:masterfrom
bdegeeter:pr/qemu-hard-power-cycle

Conversation

@bdegeeter

Copy link
Copy Markdown
Contributor

Summary

Add a QEMU-specific hard power-cycle operation that simulates abrupt power loss by sending SIGKILL to the QEMU process and relaunching the VM with the same disks and machine configuration.

The new APIs are:

  • (*QEMU).HardPowerCycle(context.Context) (context.Context, error)
  • (matcher.VM).HardPowerCycle(context.Context, timeoutSeconds) (context.Context, error)

The operation is intentionally QEMU-specific and is not added to the generic Machine interface.

Behavior

A hard power cycle:

  1. Stops and synchronizes the existing process monitor.
  2. Sends SIGKILL directly to the running QEMU process.
  3. Waits for confirmed process termination.
  4. Removes stale PID and monitor socket state.
  5. Verifies that the existing disks are still available.
  6. Relaunches QEMU with the same disks and machine arguments.
  7. Waits for SSH to reconnect when invoked through matcher.VM.

Stopping the process monitor before SIGKILL prevents an intentional power cycle from invoking the configured OnFailure callback.

Error handling

Errors are returned when:

  • The machine is not a running QEMU instance.
  • The PID cannot be read or validated.
  • SIGKILL fails.
  • The process does not exit within the bounded timeout.
  • Stale process state cannot be removed.
  • A disk is unavailable.
  • QEMU cannot be relaunched.
  • SSH does not reconnect within the requested timeout.

Validation

The following checks pass with Go 1.24.2:

  • go test ./...
  • go test -race ./...
  • go vet ./...
  • git diff --check

Process-backed tests verify that:

  • The QEMU process PID changes.
  • Existing disk contents survive the power cycle.
  • The VM process is relaunched.
  • An intentional hard power cycle does not invoke OnFailure.
  • Invalid timeouts and non-QEMU backends return errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant