mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 08:03:40 +00:00
* feat: add Firecracker API client methods for VM pause/resume and snapshots
Add PatchVm, GetVm, PutSnapshotCreate, and PutSnapshotLoad methods to the
API client, along with supporting types (VmState, SnapshotCreateParams,
SnapshotLoadParams, MemBackend).
* feat: add snapshot data layer - contract types, model, store, config
Add SnapshotID and snapshot contract types, SnapshotRecord model,
store interface CRUD methods with file store implementation,
snapshot paths helper, SnapshotsDir config, and directory creation.
* feat: add runtime methods for VM pause, resume, snapshot, and restore
Implement Pause, Resume, CreateSnapshot, and RestoreBoot on the
firecracker Runtime. RestoreBoot launches a jailer, stages snapshot
files into the chroot, loads the snapshot, and resumes the VM.
* feat: add daemon snapshot create, restore, and reconciliation logic
Implement CreateSnapshot (pause, snapshot, COW-copy disk, resume),
RestoreSnapshot (COW-copy disk, RestoreBoot, wait for guest),
GetSnapshot, ListSnapshots, DeleteSnapshotByID, and crash recovery
reconciliation for snapshot and restore operations.
* feat: add HTTP endpoints for snapshot create, get, list, delete, restore
Wire 5 snapshot routes: POST /machines/{id}/snapshots (create),
GET /machines/{id}/snapshots (list), GET /snapshots/{id} (get),
DELETE /snapshots/{id} (delete), POST /snapshots/{id}/restore (restore).
* fix: cross-device rename, restore network, and snapshot cleanup
- Replace os.Rename with copy+remove for moving snapshot files out of
/proc/<pid>/root/ (cross-device link error on Linux)
- Reconfigure network interface after snapshot load so the restored VM
uses its own tap device instead of the source VM's
- Clean partial snapshot dirs immediately on failure instead of only
via reconcile
- Reject snapshot requests while a machine operation is already pending
* fix: test and modify snapshot runtime
* feat: snapshot lifecycle update, align runtime issues between host image
and daemon
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package firecracker
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestPutSnapshotLoadIncludesNetworkOverrides(t *testing.T) {
|
|
var (
|
|
gotPath string
|
|
gotBody string
|
|
)
|
|
|
|
socketPath, shutdown := startUnixSocketServer(t, func(w http.ResponseWriter, r *http.Request) {
|
|
body, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
t.Fatalf("read request body: %v", err)
|
|
}
|
|
gotPath = r.URL.Path
|
|
gotBody = string(body)
|
|
w.WriteHeader(http.StatusNoContent)
|
|
})
|
|
defer shutdown()
|
|
|
|
client := newAPIClient(socketPath)
|
|
err := client.PutSnapshotLoad(context.Background(), SnapshotLoadParams{
|
|
SnapshotPath: "vmstate.bin",
|
|
MemBackend: &MemBackend{
|
|
BackendType: "File",
|
|
BackendPath: "memory.bin",
|
|
},
|
|
ResumeVm: false,
|
|
NetworkOverrides: []NetworkOverride{
|
|
{
|
|
IfaceID: "net0",
|
|
HostDevName: "fctap7",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("put snapshot load: %v", err)
|
|
}
|
|
|
|
if gotPath != "/snapshot/load" {
|
|
t.Fatalf("request path mismatch: got %q want %q", gotPath, "/snapshot/load")
|
|
}
|
|
|
|
want := "{\"snapshot_path\":\"vmstate.bin\",\"mem_backend\":{\"backend_type\":\"File\",\"backend_path\":\"memory.bin\"},\"resume_vm\":false,\"network_overrides\":[{\"iface_id\":\"net0\",\"host_dev_name\":\"fctap7\"}]}"
|
|
if gotBody != want {
|
|
t.Fatalf("request body mismatch:\n got: %s\nwant: %s", gotBody, want)
|
|
}
|
|
}
|