feat(agent): preserve VPC ports during migration
parent
a0861247e0
commit
a1ae5e6b62
@ -0,0 +1,53 @@
|
||||
package hypervisor
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func validReceivePeerMigrationRequest(t *testing.T) ReceivePeerMigrationRequest {
|
||||
t.Helper()
|
||||
create := validIntentCreateRequest(t)
|
||||
create.Source = ""
|
||||
create.TemplateID = ""
|
||||
create.TemplateRevision = 0
|
||||
create.TemplateGenerationToken = ""
|
||||
create.StartupScript = ""
|
||||
create.GuestSSHPublicKey = ""
|
||||
create.RootPassword = ""
|
||||
create.OperationID = "operation-peer-migration-receive"
|
||||
port := validVPCPortMetadata()
|
||||
return ReceivePeerMigrationRequest{
|
||||
CreateVMRequest: create,
|
||||
MigrationID: strings.Repeat("1", 32),
|
||||
Ticket: strings.Repeat("2", 64),
|
||||
SourceEndpoints: []string{"https://10.20.0.11:9443"},
|
||||
SourceIdentitySHA256: strings.Repeat("3", 64),
|
||||
SourceUUID: "123e4567-e89b-42d3-a456-426614174001",
|
||||
ManifestDigest: strings.Repeat("4", 64),
|
||||
VPCPort: &port,
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReceivePeerMigrationBindsOptionalVPCPort(t *testing.T) {
|
||||
request := validReceivePeerMigrationRequest(t)
|
||||
if err := ValidateReceivePeerMigrationRequest(request); err != nil {
|
||||
t.Fatalf("valid VPC migration receive rejected: %v", err)
|
||||
}
|
||||
|
||||
invalid := request
|
||||
port := *request.VPCPort
|
||||
port.Bridge = "wrong-bridge"
|
||||
invalid.VPCPort = &port
|
||||
if err := ValidateReceivePeerMigrationRequest(invalid); err == nil {
|
||||
t.Fatal("migration receive accepted a VPC port with a forged bridge")
|
||||
}
|
||||
|
||||
conflicting := request
|
||||
port = *request.VPCPort
|
||||
port.MAC = vmMACAddress(request.UUID)
|
||||
conflicting.VPCPort = &port
|
||||
if err := ValidateReceivePeerMigrationRequest(conflicting); err == nil {
|
||||
t.Fatal("migration receive accepted one MAC for public and VPC interfaces")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue