@@ -30,7 +30,10 @@ import (
3030 "github.com/openshift/origin/test/extended/util/image"
3131)
3232
33- const kvIPRequestsAnnot = "network.kubevirt.io/addresses"
33+ const (
34+ kvIPRequestsAnnot = "network.kubevirt.io/addresses"
35+ primaryUDNNetworkName = "overlay"
36+ )
3437
3538var _ = Describe ("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][Feature:Layer2LiveMigration] Kubevirt Virtual Machines" , func () {
3639 // disable automatic namespace creation, we need to add the required UDN label
@@ -570,14 +573,36 @@ func duplicateVM(cli *kubevirt.Client, vmNamespace, vmName string) {
570573 Expect (json .Unmarshal ([]byte (originalVMIRawAnnotations ), & originalVMIAnnotations )).To (Succeed ())
571574
572575 var vmiCreationOptions []kubevirt.Option
576+ var vmiExpectations []func ()
573577 if requestedIPs , hasIPRequests := originalVMIAnnotations [kvIPRequestsAnnot ]; hasIPRequests {
574578 vmiCreationOptions = append (
575579 vmiCreationOptions ,
576580 kubevirt .WithAnnotations (ipRequests (requestedIPs )),
577581 )
582+ vmiExpectations = append (vmiExpectations , func () {
583+ waitForVMPodEventWithMessage (
584+ cli ,
585+ vmNamespace ,
586+ duplicateVMName ,
587+ "IP is already allocated" ,
588+ 2 * time .Minute ,
589+ )
590+ })
591+ } else if hasMACAddressRequest (cli , vmName ) {
592+ vmiExpectations = append (vmiExpectations , func () {
593+ waitForVMPodEventWithMessage (
594+ cli ,
595+ vmNamespace ,
596+ duplicateVMName ,
597+ "MAC address conflict detected:" ,
598+ 2 * time .Minute ,
599+ )
600+ })
578601 }
579602 Expect (cli .CreateVMIFromSpec (vmNamespace , duplicateVMName , vmiSpec , vmiCreationOptions ... )).To (Succeed ())
580- waitForVMPodEventWithMessage (cli , vmNamespace , duplicateVMName , "IP is already allocated" , 2 * time .Minute )
603+ for _ , expectation := range vmiExpectations {
604+ expectation ()
605+ }
581606}
582607
583608func waitForVMPodEventWithMessage (vmClient * kubevirt.Client , vmNamespace , vmName , expectedEventMessage string , timeout time.Duration ) {
@@ -788,7 +813,6 @@ func networkName(netSpecConfig string) string {
788813
789814// formatAddressesAnnotation converts slice of IPs to the required JSON format for kubevirt addresses annotation
790815func formatAddressesAnnotation (preconfiguredIPs []string ) (string , error ) {
791- const primaryUDNNetworkName = "overlay"
792816 if len (preconfiguredIPs ) == 0 {
793817 return "" , nil
794818 }
@@ -811,3 +835,12 @@ func formatAddressesAnnotation(preconfiguredIPs []string) (string, error) {
811835func ipRequests (ips string ) map [string ]string {
812836 return map [string ]string {kvIPRequestsAnnot : ips }
813837}
838+
839+ func hasMACAddressRequest (cli * kubevirt.Client , vmName string ) bool {
840+ macAddress , err := cli .GetJSONPath ("vmi" , vmName , fmt .Sprintf ("{.spec.domain.devices.interfaces[?(@.name=='%s')].macAddress}" , primaryUDNNetworkName ))
841+ if err != nil {
842+ return false
843+ }
844+
845+ return strings .TrimSpace (macAddress ) != ""
846+ }
0 commit comments