Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky e2e test due to mac address re-used #198

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package e2e

import (
"crypto/rand"
"encoding/json"
"fmt"
"net"
"os"
"testing"
"time"
Expand Down Expand Up @@ -153,17 +155,22 @@ var _ = Describe("Multus dynamic networks controller", func() {
})

Context("a network with IPAM", func() {
var macAddress string

const (
ifaceToAddWithIPAM = "ens202"
ipAddressToAdd = "10.10.10.111"
ipamNetworkToAdd = "tenant-network-ipam"
netmaskLen = 24
)

macAddress := "02:03:04:05:06:07"

BeforeEach(func() {
_, err := clients.AddNetAttachDef(macvlanNetworkWitStaticIPAM(ipamNetworkToAdd, namespace, lowerDeviceName()))
var err error
hardwareAddr, err := generateMacAddress()
Expect(err).NotTo(HaveOccurred())
macAddress = hardwareAddr.String()

_, err = clients.AddNetAttachDef(macvlanNetworkWitStaticIPAM(ipamNetworkToAdd, namespace, lowerDeviceName()))
Expect(err).NotTo(HaveOccurred())
Expect(clients.AddNetworkToPod(pod, &nettypes.NetworkSelectionElement{
Name: ipamNetworkToAdd,
Expand Down Expand Up @@ -207,10 +214,17 @@ var _ = Describe("Multus dynamic networks controller", func() {
})

Context("a provisioned pod featuring *only* the cluster's default network", func() {
var pod *corev1.Pod
var (
pod *corev1.Pod
desiredMACAddr string
)

BeforeEach(func() {
var err error
hardwareAddr, err := generateMacAddress()
Expect(err).NotTo(HaveOccurred())
desiredMACAddr = hardwareAddr.String()

pod, err = clients.ProvisionPod(
podName,
namespace,
Expand All @@ -226,8 +240,7 @@ var _ = Describe("Multus dynamic networks controller", func() {

It("manages to add a new interface to a running pod", func() {
const (
desiredMACAddr = "02:03:04:05:06:07"
ifaceToAdd = "ens58"
ifaceToAdd = "ens58"
)

Expect(clients.AddNetworkToPod(pod, &nettypes.NetworkSelectionElement{
Expand All @@ -249,12 +262,12 @@ var _ = Describe("Multus dynamic networks controller", func() {
Context("a provisioned pod whose network selection elements do not feature the interface name", func() {
const (
ifaceToAdd = "ens58"
macAddress = "02:03:04:05:06:07"
)

var (
pod *corev1.Pod
initialPodsNetworkStatus []nettypes.NetworkStatus
macAddress string
)

runtimePodNetworkStatus := func() []nettypes.NetworkStatus {
Expand All @@ -270,6 +283,10 @@ var _ = Describe("Multus dynamic networks controller", func() {

BeforeEach(func() {
var err error
hardwareAddr, err := generateMacAddress()
Expect(err).NotTo(HaveOccurred())
macAddress = hardwareAddr.String()

pod, err = clients.ProvisionPod(
podName,
namespace,
Expand Down Expand Up @@ -326,6 +343,19 @@ var _ = Describe("Multus dynamic networks controller", func() {
})
})

// https://stackoverflow.com/questions/21018729/generate-mac-address-in-go
func generateMacAddress() (net.HardwareAddr, error) {
buf := make([]byte, 6)
_, err := rand.Read(buf)
if err != nil {
return nil, err
}

buf[0] = (buf[0] | 2) & 0xfe // Set local bit, ensure unicast addres

return buf, nil
}

func clusterConfig() (*rest.Config, error) {
const kubeconfig = "KUBECONFIG"

Expand Down
Loading