diff --git a/agent/hypervisor/libvirt_operation_admin.go b/agent/hypervisor/libvirt_operation_admin.go index 4fe23638..269d3c5a 100644 --- a/agent/hypervisor/libvirt_operation_admin.go +++ b/agent/hypervisor/libvirt_operation_admin.go @@ -1951,6 +1951,7 @@ type operationVMEffectProjection struct { Machine string `json:"machine"` Firmware string `json:"firmware"` SecureBoot bool `json:"secure_boot"` + VPCPort *VPCPortMetadata `json:"vpc_port,omitempty"` SettingsChanged bool `json:"settings_changed,omitempty"` NetworkChanged bool `json:"network_changed,omitempty"` ReinstallCommitted bool `json:"reinstall_committed,omitempty"` @@ -1964,6 +1965,7 @@ func vmEffectProjection(value VMMetadata) operationVMEffectProjection { BandwidthMbps: value.BandwidthMbps, Hostname: value.Hostname, PublicNetwork: value.PublicNetwork, TemplateID: value.TemplateID, Machine: value.Machine, Firmware: value.Firmware, SecureBoot: value.SecureBoot, + VPCPort: value.VPCPort, SettingsChanged: value.SettingsChanged, NetworkChanged: value.NetworkChanged, ReinstallCommitted: value.ReinstallCommitted, CleanupPending: value.CleanupPending, } diff --git a/agent/hypervisor/libvirt_operation_admin_test.go b/agent/hypervisor/libvirt_operation_admin_test.go index 5431157e..30c20054 100644 --- a/agent/hypervisor/libvirt_operation_admin_test.go +++ b/agent/hypervisor/libvirt_operation_admin_test.go @@ -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{ diff --git a/web/app/Services/Cloud/CloudAdminOperationRecoveryService.php b/web/app/Services/Cloud/CloudAdminOperationRecoveryService.php index c0c606b2..2c58ec2f 100644 --- a/web/app/Services/Cloud/CloudAdminOperationRecoveryService.php +++ b/web/app/Services/Cloud/CloudAdminOperationRecoveryService.php @@ -67,6 +67,7 @@ final class CloudAdminOperationRecoveryService 'machine' => 'string', 'firmware' => 'string', 'secure_boot' => 'boolean', + 'vpc_port' => 'vpc_port', 'settings_changed' => 'boolean', 'network_changed' => 'boolean', 'reinstall_committed' => 'boolean', @@ -1289,7 +1290,8 @@ final class CloudAdminOperationRecoveryService 'source_autostart_enabled', 'source_autostart_disabled', ], 'instance_migration_transfer' => [ - 'uuid', 'public_ip_cidr', 'public_pool_key', 'migration_id', + 'uuid', 'status', 'vcpu', 'memory_mib', 'disk_gib', + 'bandwidth_mbps', 'public_network', 'migration_id', 'manifest_digest', 'artifacts', 'staged_powered_off', ], 'snapshot_restore' => ['snapshot_key', 'restored'], diff --git a/web/tests/CloudOperationRecoveryMatrixTest.php b/web/tests/CloudOperationRecoveryMatrixTest.php index f1cbca68..fd3090d9 100644 --- a/web/tests/CloudOperationRecoveryMatrixTest.php +++ b/web/tests/CloudOperationRecoveryMatrixTest.php @@ -1456,8 +1456,17 @@ namespace { $migrationTargetUuid, [ 'uuid' => $migrationTargetUuid, - 'public_ip_cidr' => '203.0.113.30/24', - 'public_pool_key' => str_repeat('b', 32), + 'name' => 'matrix-vm', + 'status' => 'shutoff', + 'vcpu' => 2, + 'memory_mib' => 2048, + 'disk_gib' => 20, + 'bandwidth_mbps' => 100, + 'public_network' => + $migrationTargetIdentity->publicNetwork()->toArray(), + 'machine' => 'q35', + 'firmware' => 'uefi', + 'secure_boot' => false, 'migration_id' => $migrationKey, 'manifest_digest' => $migrationDigest, 'artifacts' => [$migrationArtifact],