diff --git a/pkg/pool-manager/pool_test.go b/pkg/pool-manager/pool_test.go index 434c5728..b342b888 100644 --- a/pkg/pool-manager/pool_test.go +++ b/pkg/pool-manager/pool_test.go @@ -54,8 +54,11 @@ var _ = Describe("Pool", func() { return map[string]string{NetworksAnnotation: `[{"name":"ovs-conf","namespace":"` + namespace + `","mac":"` + macAddress + `","cni-args":null}]`} } const ( - managedNamespaceMAC = "02:00:00:00:00:00" - unmanagedNamespaceMAC = "02:00:00:00:00:FF" + managedNamespaceMAC = "03:00:00:00:00:00" + unmanagedNamespaceMAC = "03:00:00:00:00:FF" + + minRangeMACPool = "02:00:00:00:00:00" + maxRangeMACPool = "02:FF:FF:FF:FF:FF" ) managedPodWithMacAllocated := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "podpod", Namespace: managedNamespaceName, Annotations: afterAllocationAnnotation(managedNamespaceName, managedNamespaceMAC)}} unmanagedPodWithMacAllocated := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "unmanagedPod", Namespace: notManagedNamespaceName, Annotations: afterAllocationAnnotation(notManagedNamespaceName, unmanagedNamespaceMAC)}} @@ -137,7 +140,7 @@ var _ = Describe("Pool", func() { Describe("Pool Manager General Functions ", func() { It("should create a pool manager", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:FF:FF:FF:FF:FF") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) Expect(poolManager).ToNot(BeNil()) }) Context("check NewPoolManager", func() { @@ -179,7 +182,7 @@ var _ = Describe("Pool", func() { Context("When poolManager is initialized when there are pods on managed and unmanaged namespaces", func() { var poolManager *PoolManager BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:FF:FF:FF:FF:FF", &managedPodWithMacAllocated, &unmanagedPodWithMacAllocated) + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool, &managedPodWithMacAllocated, &unmanagedPodWithMacAllocated) Expect(poolManager).ToNot(BeNil()) }) It("Should initialize the macPoolmap only with macs on the mananged pods", func() { @@ -259,7 +262,7 @@ var _ = Describe("Pool", func() { return time.Now().Add(secondsPassed * time.Second) } It("should reject allocation if there are interfaces with the same name", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := duplicateInterfacesVM.DeepCopy() newVM.Name = "duplicateInterfacesVM" @@ -269,7 +272,7 @@ var _ = Describe("Pool", func() { Expect(poolManager.macPoolMap).To(BeEmpty(), "Should not allocate macs if there are duplicate interfaces") }) It("should not allocate a new mac for bridge interface on pod network", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := sampleVM newVM.Name = "newVM" @@ -281,7 +284,7 @@ var _ = Describe("Pool", func() { Context("and there is a pre-existing pod with mac allocated to it", func() { var poolManager *PoolManager BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02", &managedPodWithMacAllocated) + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool, &managedPodWithMacAllocated) }) It("should allocate a new mac and release it for masquerade", func() { newVM := masqueradeVM @@ -320,7 +323,7 @@ var _ = Describe("Pool", func() { vm.Spec.Template.Spec.Domain.Devices.Disks = make([]kubevirt.Disk, 1) vm.Spec.Template.Spec.Domain.Devices.Disks[0].IO = ioName } - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" @@ -338,7 +341,7 @@ var _ = Describe("Pool", func() { Expect(updateVm.Spec.Template.Spec.Domain.Devices.Disks[0].IO).To(Equal(kubevirt.DriverIO("native-update")), "disk.io configuration must be preserved after mac allocation update") }) It("should reject update allocation if there are interfaces with the same name", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "multipleInterfacesVM" @@ -357,7 +360,7 @@ var _ = Describe("Pool", func() { Expect(checkMacPoolMapEntries(poolManager.macPoolMap, &transactionTimestamp, expectedMACsAfterRejection, []string{})).To(Succeed(), "Failed to check macs in macMap") }) It("should preserve mac addresses on update", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" transactionTimestamp := updateTransactionTimestamp(0) @@ -375,7 +378,7 @@ var _ = Describe("Pool", func() { Expect(checkMacPoolMapEntries(poolManager.macPoolMap, &newTransactionTimestamp, expectedUpdatedMACs, []string{})).To(Succeed(), "Failed to check macs in macMap") }) It("should preserve mac addresses and allocate a requested one on update", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" @@ -401,7 +404,7 @@ var _ = Describe("Pool", func() { Expect(checkMacPoolMapEntries(poolManager.macPoolMap, &newTransactionTimestamp, expectedUpdatedMACs, []string{})).To(Succeed(), "Failed to check macs in macMap") }) It("should allow to add a new interface on update", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" @@ -424,7 +427,7 @@ var _ = Describe("Pool", func() { Expect(checkMacPoolMapEntries(poolManager.macPoolMap, &NewTransactionTimestamp, expectedUpdatedMACs, expectedNotUpdatedMacs)).To(Succeed(), "Failed to check macs in macMap") }) It("should allow to remove an interface on update", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" newVM.Spec.Template.Spec.Domain.Devices.Interfaces = append(newVM.Spec.Template.Spec.Domain.Devices.Interfaces, anotherMultusBridgeInterface) @@ -448,7 +451,7 @@ var _ = Describe("Pool", func() { Expect(checkMacPoolMapEntries(poolManager.macPoolMap, &NewTransactionTimestamp, expectedUpdatedMACs, expectedNotUpdatedMACs)).To(Succeed(), "Failed to check macs in macMap") }) It("should allow to remove and add an interface on update", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newVM := multipleInterfacesVM.DeepCopy() newVM.Name = "newVM" @@ -485,7 +488,7 @@ var _ = Describe("Pool", func() { vmFirstUpdateTimestamp := now.Add(time.Duration(1) * time.Second) vmSecondUpdateTimestamp := now.Add(time.Duration(2) * time.Second) BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool) }) var vm, vmFirstUpdate, vmSecondUpdate *kubevirt.VirtualMachine var vmLastPersistedTransactionTimestampAnnotation *time.Time @@ -604,7 +607,7 @@ var _ = Describe("Pool", func() { transactionTimestamp time.Time ) BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:01", &vmConfigMap) + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool, &vmConfigMap) newVM = masqueradeVM.DeepCopy() newVM.Name = "newVM" @@ -697,7 +700,7 @@ var _ = Describe("Pool", func() { Describe("Pool Manager Functions For pod", func() { It("should allocate a new mac and release it", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02", &managedPodWithMacAllocated) + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool, &managedPodWithMacAllocated) newPod := managedPodWithMacAllocated newPod.Name = "newPod" newPod.Annotations = beforeAllocationAnnotation @@ -729,7 +732,7 @@ var _ = Describe("Pool", func() { Expect(exist).To(BeFalse()) }) It("should allocate requested mac when empty", func() { - poolManager := createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager := createPoolManager(minRangeMACPool, maxRangeMACPool) newPod := managedPodWithMacAllocated newPod.Name = "newPod" @@ -744,7 +747,7 @@ var _ = Describe("Pool", func() { poolManager := &PoolManager{} BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:02") + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool) Expect(poolManager).ToNot(Equal(nil), "should create pool-manager") }) @@ -903,7 +906,7 @@ var _ = Describe("Pool", func() { } var poolManager *PoolManager BeforeEach(func() { - poolManager = createPoolManager("02:00:00:00:00:00", "02:00:00:00:00:01", optOutMutatingWebhookConfiguration, optInMutatingWebhookConfiguration, namespaceWithIncludingLabel, namespaceWithExcludingLabel, namespaceWithNoLabels, namespaceWithIrrelevantLabels) + poolManager = createPoolManager(minRangeMACPool, maxRangeMACPool, optOutMutatingWebhookConfiguration, optInMutatingWebhookConfiguration, namespaceWithIncludingLabel, namespaceWithExcludingLabel, namespaceWithNoLabels, namespaceWithIrrelevantLabels) }) DescribeTable("Should return the expected namespace acceptance outcome according to the opt-mode or return an error", func(n *isNamespaceSelectorCompatibleWithOptModeLabelParams) {