@@ -30,7 +30,10 @@ import (
30
30
"github.com/openshift/origin/test/extended/util/image"
31
31
)
32
32
33
- const kvIPRequestsAnnot = "network.kubevirt.io/addresses"
33
+ const (
34
+ kvIPRequestsAnnot = "network.kubevirt.io/addresses"
35
+ primaryUDNNetworkName = "overlay"
36
+ )
34
37
35
38
var _ = Describe ("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][Feature:Layer2LiveMigration] Kubevirt Virtual Machines" , func () {
36
39
// disable automatic namespace creation, we need to add the required UDN label
@@ -584,14 +587,36 @@ func duplicateVM(cli *kubevirt.Client, vmNamespace, vmName string) {
584
587
Expect (json .Unmarshal ([]byte (originalVMIRawAnnotations ), & originalVMIAnnotations )).To (Succeed ())
585
588
586
589
var vmiCreationOptions []kubevirt.Option
590
+ var vmiExpectations []func ()
587
591
if requestedIPs , hasIPRequests := originalVMIAnnotations [kvIPRequestsAnnot ]; hasIPRequests {
588
592
vmiCreationOptions = append (
589
593
vmiCreationOptions ,
590
594
kubevirt .WithAnnotations (ipRequests (requestedIPs )),
591
595
)
596
+ vmiExpectations = append (vmiExpectations , func () {
597
+ waitForVMPodEventWithMessage (
598
+ cli ,
599
+ vmNamespace ,
600
+ duplicateVMName ,
601
+ "IP is already allocated" ,
602
+ 2 * time .Minute ,
603
+ )
604
+ })
605
+ } else if hasMACAddressRequest (cli , vmName ) {
606
+ vmiExpectations = append (vmiExpectations , func () {
607
+ waitForVMPodEventWithMessage (
608
+ cli ,
609
+ vmNamespace ,
610
+ duplicateVMName ,
611
+ "MAC address conflict detected:" ,
612
+ 2 * time .Minute ,
613
+ )
614
+ })
592
615
}
593
616
Expect (cli .CreateVMIFromSpec (vmNamespace , duplicateVMName , vmiSpec , vmiCreationOptions ... )).To (Succeed ())
594
- waitForVMPodEventWithMessage (cli , vmNamespace , duplicateVMName , "IP is already allocated" , 2 * time .Minute )
617
+ for _ , expectation := range vmiExpectations {
618
+ expectation ()
619
+ }
595
620
}
596
621
597
622
func waitForVMPodEventWithMessage (vmClient * kubevirt.Client , vmNamespace , vmName , expectedEventMessage string , timeout time.Duration ) {
@@ -802,7 +827,6 @@ func networkName(netSpecConfig string) string {
802
827
803
828
// formatAddressesAnnotation converts slice of IPs to the required JSON format for kubevirt addresses annotation
804
829
func formatAddressesAnnotation (preconfiguredIPs []string ) (string , error ) {
805
- const primaryUDNNetworkName = "overlay"
806
830
if len (preconfiguredIPs ) == 0 {
807
831
return "" , nil
808
832
}
@@ -825,3 +849,12 @@ func formatAddressesAnnotation(preconfiguredIPs []string) (string, error) {
825
849
func ipRequests (ips string ) map [string ]string {
826
850
return map [string ]string {kvIPRequestsAnnot : ips }
827
851
}
852
+
853
+ func hasMACAddressRequest (cli * kubevirt.Client , vmName string ) bool {
854
+ macAddress , err := cli .GetJSONPath ("vmi" , vmName , fmt .Sprintf ("{.spec.domain.devices.interfaces[?(@.name=='%s')].macAddress}" , primaryUDNNetworkName ))
855
+ if err != nil {
856
+ return false
857
+ }
858
+
859
+ return strings .TrimSpace (macAddress ) != ""
860
+ }
0 commit comments