Skip to content

Commit 6b6dfb1

Browse files
maiquebRamLavi
andcommitted
networking, virt: generalize conflict detection
This way we can ensure the MAC conflict and IP conflicts are caught, and in a generic way. With it, we can safely expect to find: - IP conflicts when there are duplicate IPs in the network - MAC conflicts when there are duplicate MACs in the network Co-authored-by: Ram Lavi <[email protected]> Signed-off-by: Miguel Duarte Barroso <[email protected]>
1 parent 08111ff commit 6b6dfb1

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

test/extended/networking/livemigration.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3538
var _ = Describe("[sig-network][OCPFeatureGate:PersistentIPsForVirtualization][Feature:Layer2LiveMigration] Kubevirt Virtual Machines", func() {
3639
// disable automatic namespace creation, we need to add the required UDN label
@@ -584,14 +587,36 @@ func duplicateVM(cli *kubevirt.Client, vmNamespace, vmName string) {
584587
Expect(json.Unmarshal([]byte(originalVMIRawAnnotations), &originalVMIAnnotations)).To(Succeed())
585588

586589
var vmiCreationOptions []kubevirt.Option
590+
var vmiExpectations []func()
587591
if requestedIPs, hasIPRequests := originalVMIAnnotations[kvIPRequestsAnnot]; hasIPRequests {
588592
vmiCreationOptions = append(
589593
vmiCreationOptions,
590594
kubevirt.WithAnnotations(ipRequests(requestedIPs)),
591595
)
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+
})
592615
}
593616
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+
}
595620
}
596621

597622
func waitForVMPodEventWithMessage(vmClient *kubevirt.Client, vmNamespace, vmName, expectedEventMessage string, timeout time.Duration) {
@@ -802,7 +827,6 @@ func networkName(netSpecConfig string) string {
802827

803828
// formatAddressesAnnotation converts slice of IPs to the required JSON format for kubevirt addresses annotation
804829
func formatAddressesAnnotation(preconfiguredIPs []string) (string, error) {
805-
const primaryUDNNetworkName = "overlay"
806830
if len(preconfiguredIPs) == 0 {
807831
return "", nil
808832
}
@@ -825,3 +849,12 @@ func formatAddressesAnnotation(preconfiguredIPs []string) (string, error) {
825849
func ipRequests(ips string) map[string]string {
826850
return map[string]string{kvIPRequestsAnnot: ips}
827851
}
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

Comments
 (0)