Commit 35ea6c5
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 35ea6c5
8 files changed
Lines changed: 2139 additions & 4 deletions
File tree
- internal/controller/vm
- mocks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments