|
|
|
|
@ -13,6 +13,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"git.luoli.live/root/virt/agent/operation"
|
|
|
|
|
"git.luoli.live/root/virt/agent/peermigration"
|
|
|
|
|
"libvirt.org/go/libvirt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -659,6 +660,58 @@ func TestPeerMigrationStateProjectionProvesPowerAndAutostart(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPeerMigrationReceiveProjectionPreservesCanonicalNetworkAndVPC(t *testing.T) {
|
|
|
|
|
resourceID := "123e4567-e89b-42d3-a456-426614174000"
|
|
|
|
|
migrationID := strings.Repeat("a", 32)
|
|
|
|
|
artifact := peermigration.Artifact{
|
|
|
|
|
ID: strings.Repeat("b", 32), Role: "root", Consistency: "crash",
|
|
|
|
|
SizeBytes: 1, VirtualSizeBytes: 1, SHA256: strings.Repeat("c", 64),
|
|
|
|
|
CreatedAt: time.Now().Unix(),
|
|
|
|
|
}
|
|
|
|
|
definition := validDomainDefinition()
|
|
|
|
|
for _, withVPC := range []bool{false, true} {
|
|
|
|
|
var port *VPCPortMetadata
|
|
|
|
|
if withVPC {
|
|
|
|
|
value := validVPCPortMetadata()
|
|
|
|
|
port = &value
|
|
|
|
|
}
|
|
|
|
|
result := ReceivePeerMigrationResult{
|
|
|
|
|
VMMetadata: VMMetadata{
|
|
|
|
|
UUID: resourceID, Name: "migration-target", Status: VMStateShutoff,
|
|
|
|
|
VCPUs: 2, MemoryMiB: 2048, DiskGiB: 20, BandwidthMbps: 100,
|
|
|
|
|
PublicNetwork: definition.PublicNetwork, Machine: "q35",
|
|
|
|
|
Firmware: "uefi", VPCPort: port,
|
|
|
|
|
},
|
|
|
|
|
MigrationID: migrationID, ManifestDigest: strings.Repeat("d", 64),
|
|
|
|
|
Artifacts: []peermigration.Artifact{artifact}, StagedPoweredOff: true,
|
|
|
|
|
}
|
|
|
|
|
raw, err := json.Marshal(result)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
projected := operationEffectProjection(operation.Record{
|
|
|
|
|
ResourceID: resourceID,
|
|
|
|
|
Action: "receive-peer-migration:" + migrationID,
|
|
|
|
|
}, raw)
|
|
|
|
|
var proof struct {
|
|
|
|
|
operationVMEffectProjection
|
|
|
|
|
MigrationID string `json:"migration_id"`
|
|
|
|
|
ManifestDigest string `json:"manifest_digest"`
|
|
|
|
|
Artifacts []peermigration.Artifact `json:"artifacts"`
|
|
|
|
|
StagedPoweredOff bool `json:"staged_powered_off"`
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(projected, &proof); err != nil {
|
|
|
|
|
t.Fatalf("decode receive projection (VPC=%v): %v (%s)", withVPC, err, projected)
|
|
|
|
|
}
|
|
|
|
|
if proof.UUID != resourceID || proof.Status != VMStateShutoff ||
|
|
|
|
|
proof.MigrationID != migrationID || !proof.StagedPoweredOff ||
|
|
|
|
|
!reflect.DeepEqual(proof.PublicNetwork, definition.PublicNetwork) ||
|
|
|
|
|
!reflect.DeepEqual(proof.VPCPort, port) {
|
|
|
|
|
t.Fatalf("receive projection lost canonical identity (VPC=%v): %#v", withVPC, proof)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSuccessfulBackupCleanupPendingRetainsImmutableObjectProjection(t *testing.T) {
|
|
|
|
|
key := "0123456789abcdef0123456789abcdef"
|
|
|
|
|
record := operation.Record{
|
|
|
|
|
|