@@ -137,6 +137,9 @@ var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][F
137137 vmCreationParams .PreconfiguredIP , err = formatAddressesAnnotation (workloadConfig .preconfiguredIPs )
138138 Expect (err ).NotTo (HaveOccurred ())
139139 }
140+ if workloadConfig .preconfiguredMAC != "" {
141+ vmCreationParams .PreconfiguredMAC = workloadConfig .preconfiguredMAC
142+ }
140143 Expect (virtClient .CreateVM (vmResource , vmCreationParams )).To (Succeed ())
141144 waitForVMReadiness (virtClient , vmCreationParams .VMNamespace , vmCreationParams .VMName )
142145
@@ -167,6 +170,10 @@ var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][F
167170 Expect (initialAddresses ).To (ContainElement (expectedIP ), fmt .Sprintf ("Expected IP %s not found in VM addresses %v" , expectedIP , initialAddresses ))
168171 }
169172 }
173+ if workloadConfig .preconfiguredMAC != "" {
174+ By ("Verifying VM received the preconfigured MAC address" )
175+ verifyVMMAC (virtClient , vmName , workloadConfig .preconfiguredMAC )
176+ }
170177 httpServerPodsIPs := httpServerTestPodsMultusNetworkIPs (netConfig , httpServerPods )
171178
172179 By (fmt .Sprintf ("Check east/west traffic before test operation using IPs: %v" , httpServerPodsIPs ))
@@ -189,6 +196,10 @@ var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][F
189196 ShouldNot (BeEmpty ())
190197 Expect (obtainedAddresses ).To (ConsistOf (initialAddresses ))
191198
199+ if workloadConfig .preconfiguredMAC != "" {
200+ By ("Verifying VM MAC address persisted after test operation" )
201+ verifyVMMAC (virtClient , vmName , workloadConfig .preconfiguredMAC )
202+ }
192203 By ("Check east/west after test operation" )
193204 checkEastWestTraffic (virtClient , vmName , httpServerPodsIPs )
194205 },
@@ -272,6 +283,20 @@ var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][F
272283 preconfiguredIPs : []string {"203.203.0.50" , "2014:100:200::50" },
273284 },
274285 ),
286+ Entry (
287+ "[OCPFeatureGate:PreconfiguredUDNAddresses] when the VM with preconfigured MAC attached to a primary UDN is restarted" ,
288+ networkAttachmentConfigParams {
289+ name : nadName ,
290+ topology : "layer2" ,
291+ role : "primary" ,
292+ allowPersistentIPs : true ,
293+ },
294+ kubevirt .FedoraVMWithPreconfiguredPrimaryUDNAttachment ,
295+ restartVM ,
296+ workloadNetworkConfig {
297+ preconfiguredMAC : "02:0A:0B:0C:0D:50" ,
298+ },
299+ ),
275300 )
276301 },
277302 Entry ("NetworkAttachmentDefinitions" , func (c networkAttachmentConfigParams ) networkAttachmentConfig {
@@ -459,6 +484,14 @@ func obtainAddresses(virtClient *kubevirt.Client, vmName string) ([]string, erro
459484 return addressFromStatus (virtClient , vmName )
460485}
461486
487+ func obtainMAC (virtClient * kubevirt.Client , vmName string ) (string , error ) {
488+ macStr , err := virtClient .GetJSONPath ("vmi" , vmName , "{@.status.interfaces[0].mac}" )
489+ if err != nil {
490+ return "" , fmt .Errorf ("failed to extract the MAC address from VM %q: %w" , vmName , err )
491+ }
492+ return strings .ToUpper (macStr ), nil
493+ }
494+
462495func restartVM (cli * kubevirt.Client , vmNamespace , vmName string ) {
463496 GinkgoHelper ()
464497 By (fmt .Sprintf ("Restarting vmi %s/%s" , vmNamespace , vmName ))
@@ -473,6 +506,22 @@ func migrateVM(cli *kubevirt.Client, vmNamespace, vmName string) {
473506 waitForVMIMSuccess (cli , vmNamespace , vmName )
474507}
475508
509+ func verifyVMMAC (virtClient * kubevirt.Client , vmName , expectedMAC string ) {
510+ GinkgoHelper ()
511+ var actualMAC string
512+ Eventually (func (g Gomega ) string {
513+ GinkgoHelper ()
514+
515+ var err error
516+ actualMAC , err = obtainMAC (virtClient , vmName )
517+ g .Expect (err ).NotTo (HaveOccurred (), "Failed to obtain MAC address for VM" )
518+ return actualMAC
519+ }).
520+ WithPolling (time .Second ).
521+ WithTimeout (5 * time .Minute ).
522+ Should (Equal (expectedMAC ))
523+ }
524+
476525func waitForPodsCondition (fr * framework.Framework , pods []* corev1.Pod , conditionFn func (g Gomega , pod * corev1.Pod )) {
477526 for _ , pod := range pods {
478527 Eventually (func (g Gomega ) {
0 commit comments