Commit 1611cc8
Shreyansh Sancheti
controller/vm: add unit tests for VM Controller state machine
Defines per-platform vmLifetime and guestManager seam interfaces over
*vmmanager.UtilityVM and *guestmanager.Guest. Each interface is a superset
of the methods Controller invokes directly plus the device methods consumed
by the wired-in sub-controllers (vpci/network/plan9/scsi). *vmmanager and
*guestmanager satisfy these via Go structural typing; no concrete sister
fields needed.
The per-platform split is necessary because:
- AddPlan9 / RemovePlan9 are LCOW-only on *vmmanager.UtilityVM.
- Guest network signatures differ across LCOW and WCOW.
- vPCI guest and Plan9 guest methods are LCOW-only.
- UpdateHvSocketAddress is WCOW-only.
Guest() uses a type assertion to preserve its concrete return type.
30 tests covering:
Idempotency (3): duplicate StartVM no-op, TerminateVM from Terminated
and NotCreated.
State guards (8): StartVM rejects NotCreated/Terminated/Invalid,
ExecIntoHost rejects Terminated, terminal+stderr input validation,
Update methods reject non-Running (4 subtests), Stats rejects
Terminated, Wait rejects NotCreated, DumpStacks rejects Terminated,
UpdateCPUGroup rejects empty ID.
TerminateVM cleanup chain (6): full Terminate->CloseConnection->Close
ordering, guest close failure swallowed, uvm.Terminate failure
swallowed, uvm.Close failure -> StateInvalid, recovery from Invalid,
retry failure stays Invalid.
Error propagation (4): ExecIntoHost guest error, DumpStacks guest error,
UpdatePolicyFragment guest error, ExitStatus not-terminated error.
API delegation (4): ExecIntoHost exit code forwarding, DumpStacks
with and without capability, ExitStatus value assembly.
Wait + background goroutine (5): Wait from Terminated with log drain,
Wait context cancelled during log drain, Wait Running happy path,
waitForVMExit Running->Terminated transition, waitForVMExit
overwrites Invalid->Terminated (pins current behaviour).
Mocks generated per-platform (mocks/mock_lcow_vm.go, mock_wcow_vm.go)
with matching //go:build constraints.
Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>1 parent a4051da commit 1611cc8
7 files changed
Lines changed: 1726 additions & 3 deletions
File tree
- internal/controller/vm
- mocks
0 commit comments