From 2545932ad8a66c38f74f7e4af94a6e496cfbab6e Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Tue, 1 Oct 2024 14:40:02 +0300 Subject: [PATCH] tests/e2e, persistentip: Expand test matric using DescribeTableSubtree Expand the current test to run in a DescribeTableSubtree context. This is in preparation of adding more interface types in future commits. This commit does not add tests, nor change their operation. Signed-off-by: Ram Lavi --- test/e2e/persistentips_test.go | 54 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/test/e2e/persistentips_test.go b/test/e2e/persistentips_test.go index a892300c..5def557c 100644 --- a/test/e2e/persistentips_test.go +++ b/test/e2e/persistentips_test.go @@ -42,7 +42,16 @@ import ( const networkInterfaceName = "multus" -var _ = Describe("Persistent IPs", func() { +const ( + roleSecondary = "secondary" +) + +type testParams struct { + role string + getIPsFunc func(vmi *kubevirtv1.VirtualMachineInstance) ([]string, error) +} + +var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) { var failureCount int = 0 JustAfterEach(func() { if CurrentSpecReport().Failed() { @@ -59,15 +68,12 @@ var _ = Describe("Persistent IPs", func() { When("network attachment definition created with allowPersistentIPs=true", func() { var ( - td testenv.TestData - getIPsFunc func(vmi *kubevirtv1.VirtualMachineInstance) ([]string, error) - role = "secondary" - vm *kubevirtv1.VirtualMachine - vmi *kubevirtv1.VirtualMachineInstance - nad *nadv1.NetworkAttachmentDefinition + td testenv.TestData + vm *kubevirtv1.VirtualMachine + vmi *kubevirtv1.VirtualMachineInstance + nad *nadv1.NetworkAttachmentDefinition ) - getIPsFunc = getIPsFromVMIStatus BeforeEach(func() { td = testenv.GenerateTestData() td.SetUp() @@ -75,8 +81,10 @@ var _ = Describe("Persistent IPs", func() { td.TearDown() }) - nad = testenv.GenerateLayer2WithSubnetNAD(td.Namespace, role) - vmi = testenv.GenerateAlpineWithMultusVMI(td.Namespace, networkInterfaceName, nad.Name) + nad = testenv.GenerateLayer2WithSubnetNAD(td.Namespace, params.role) + if params.role == roleSecondary { + vmi = testenv.GenerateAlpineWithMultusVMI(td.Namespace, networkInterfaceName, nad.Name) + } vm = testenv.NewVirtualMachine(vmi, testenv.WithRunning()) By("Create NetworkAttachmentDefinition") @@ -99,12 +107,12 @@ var _ = Describe("Persistent IPs", func() { WithPolling(time.Second). ShouldNot(BeEmpty()) - Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(getIPsFunc, Not(BeEmpty()))) + Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.getIPsFunc, Not(BeEmpty()))) }) It("should keep ips after live migration", func() { Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed()) - vmiIPsBeforeMigration, err := getIPsFunc(vmi) + vmiIPsBeforeMigration, err := params.getIPsFunc(vmi) Expect(err).ToNot(HaveOccurred()) Expect(vmiIPsBeforeMigration).NotTo(BeEmpty()) @@ -117,7 +125,7 @@ var _ = Describe("Persistent IPs", func() { WithTimeout(5 * time.Minute). Should(testenv.ContainConditionVMIReady()) - Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(getIPsFunc, ConsistOf(vmiIPsBeforeMigration))) + Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.getIPsFunc, ConsistOf(vmiIPsBeforeMigration))) }) It("should garbage collect IPAMClaims after VM deletion", func() { @@ -176,7 +184,7 @@ var _ = Describe("Persistent IPs", func() { It("should keep ips after restart", func() { Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed()) - vmiIPsBeforeRestart, err := getIPsFunc(vmi) + vmiIPsBeforeRestart, err := params.getIPsFunc(vmi) Expect(err).ToNot(HaveOccurred()) Expect(vmiIPsBeforeRestart).NotTo(BeEmpty()) vmiUUIDBeforeRestart := vmi.UID @@ -197,7 +205,7 @@ var _ = Describe("Persistent IPs", func() { WithTimeout(5 * time.Minute). Should(testenv.ContainConditionVMIReady()) - Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(getIPsFunc, ConsistOf(vmiIPsBeforeRestart))) + Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.getIPsFunc, ConsistOf(vmiIPsBeforeRestart))) }) }) @@ -224,7 +232,7 @@ var _ = Describe("Persistent IPs", func() { ShouldNot(BeEmpty()) Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed()) - IPs, err := getIPsFunc(vmi) + IPs, err := params.getIPsFunc(vmi) Expect(err).ToNot(HaveOccurred()) Expect(IPs).NotTo(BeEmpty()) }) @@ -267,19 +275,19 @@ var _ = Describe("Persistent IPs", func() { WithPolling(time.Second). ShouldNot(BeEmpty()) - Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(getIPsFunc, Not(BeEmpty()))) + Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.getIPsFunc, Not(BeEmpty()))) }) It("should keep ips after live migration", func() { Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed()) - vmiIPsBeforeMigration, err := getIPsFunc(vmi) + vmiIPsBeforeMigration, err := params.getIPsFunc(vmi) Expect(err).ToNot(HaveOccurred()) Expect(vmiIPsBeforeMigration).NotTo(BeEmpty()) testenv.LiveMigrateVirtualMachine(td.Namespace, vmi.Name) testenv.CheckLiveMigrationSucceeded(td.Namespace, vmi.Name) - Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(getIPsFunc, ConsistOf(vmiIPsBeforeMigration))) + Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.getIPsFunc, ConsistOf(vmiIPsBeforeMigration))) }) It("should garbage collect IPAMClaims after VMI deletion", func() { @@ -300,7 +308,13 @@ var _ = Describe("Persistent IPs", func() { }) }) -}) +}, + Entry("secondary interfaces", + testParams{ + role: roleSecondary, + getIPsFunc: getIPsFromVMIStatus, + }), +) func foregroundDeleteOptions() *client.DeleteOptions { foreground := metav1.DeletePropagationForeground