Skip to content

Commit

Permalink
tests/e2e, persistentip: Expand test matric using DescribeTableSubtree
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
RamLavi committed Oct 8, 2024
1 parent f007a5e commit 9505683
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions test/e2e/persistentips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ const (
nadName = "l2-net-attach-def"
)

var _ = Describe("Persistent IPs", func() {
const (
roleSecondary = "secondary"
)

type testParams struct {
role string
ipsFrom func(vmi *kubevirtv1.VirtualMachineInstance) []string
vmi func(namespace string) *kubevirtv1.VirtualMachineInstance
}

var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
var failureCount int = 0
JustAfterEach(func() {
if CurrentSpecReport().Failed() {
Expand All @@ -62,24 +72,21 @@ var _ = Describe("Persistent IPs", func() {

When("network attachment definition created with allowPersistentIPs=true", func() {
var (
td testenv.TestData
ipsFrom func(vmi *kubevirtv1.VirtualMachineInstance) []string
role = "secondary"
vm *kubevirtv1.VirtualMachine
vmi *kubevirtv1.VirtualMachineInstance
nad *nadv1.NetworkAttachmentDefinition
td testenv.TestData
vm *kubevirtv1.VirtualMachine
vmi *kubevirtv1.VirtualMachineInstance
nad *nadv1.NetworkAttachmentDefinition
)

ipsFrom = secondaryNetworkVMIStatusIPs
BeforeEach(func() {
td = testenv.GenerateTestData()
td.SetUp()
DeferCleanup(func() {
td.TearDown()
})

nad = testenv.GenerateLayer2WithSubnetNAD(nadName, td.Namespace, role)
vmi = vmiWithMultus(td.Namespace)
nad = testenv.GenerateLayer2WithSubnetNAD(nadName, td.Namespace, params.role)
vmi = params.vmi(td.Namespace)
vm = testenv.NewVirtualMachine(vmi, testenv.WithRunning())

By("Create NetworkAttachmentDefinition")
Expand All @@ -102,12 +109,12 @@ var _ = Describe("Persistent IPs", func() {
WithPolling(time.Second).
ShouldNot(BeEmpty())

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(ipsFrom, Not(BeEmpty())))
Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.ipsFrom, Not(BeEmpty())))
})

It("should keep ips after live migration", func() {
Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed())
vmiIPsBeforeMigration := ipsFrom(vmi)
vmiIPsBeforeMigration := params.ipsFrom(vmi)
Expect(vmiIPsBeforeMigration).NotTo(BeEmpty())

testenv.LiveMigrateVirtualMachine(td.Namespace, vm.Name)
Expand All @@ -119,7 +126,7 @@ var _ = Describe("Persistent IPs", func() {
WithTimeout(5 * time.Minute).
Should(testenv.ContainConditionVMIReady())

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(ipsFrom, ConsistOf(vmiIPsBeforeMigration)))
Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.ipsFrom, ConsistOf(vmiIPsBeforeMigration)))
})

It("should garbage collect IPAMClaims after VM deletion", func() {
Expand Down Expand Up @@ -178,7 +185,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 := ipsFrom(vmi)
vmiIPsBeforeRestart := params.ipsFrom(vmi)
Expect(vmiIPsBeforeRestart).NotTo(BeEmpty())
vmiUUIDBeforeRestart := vmi.UID

Expand All @@ -198,7 +205,7 @@ var _ = Describe("Persistent IPs", func() {
WithTimeout(5 * time.Minute).
Should(testenv.ContainConditionVMIReady())

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(ipsFrom, ConsistOf(vmiIPsBeforeRestart)))
Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.ipsFrom, ConsistOf(vmiIPsBeforeRestart)))
})
})

Expand All @@ -225,7 +232,7 @@ var _ = Describe("Persistent IPs", func() {
ShouldNot(BeEmpty())

Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed())
ips := ipsFrom(vmi)
ips := params.ipsFrom(vmi)
Expect(ips).NotTo(BeEmpty())
})

Expand Down Expand Up @@ -267,18 +274,18 @@ var _ = Describe("Persistent IPs", func() {
WithPolling(time.Second).
ShouldNot(BeEmpty())

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(ipsFrom, Not(BeEmpty())))
Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.ipsFrom, Not(BeEmpty())))
})

It("should keep ips after live migration", func() {
Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed())
vmiIPsBeforeMigration := ipsFrom(vmi)
vmiIPsBeforeMigration := params.ipsFrom(vmi)
Expect(vmiIPsBeforeMigration).NotTo(BeEmpty())

testenv.LiveMigrateVirtualMachine(td.Namespace, vmi.Name)
testenv.CheckLiveMigrationSucceeded(td.Namespace, vmi.Name)

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(ipsFrom, ConsistOf(vmiIPsBeforeMigration)))
Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPs(params.ipsFrom, ConsistOf(vmiIPsBeforeMigration)))
})

It("should garbage collect IPAMClaims after VMI deletion", func() {
Expand All @@ -299,7 +306,14 @@ var _ = Describe("Persistent IPs", func() {
})

})
})
},
Entry("secondary interfaces",
testParams{
role: roleSecondary,
ipsFrom: secondaryNetworkVMIStatusIPs,
vmi: vmiWithMultus,
}),
)

func foregroundDeleteOptions() *client.DeleteOptions {
foreground := metav1.DeletePropagationForeground
Expand Down

0 comments on commit 9505683

Please sign in to comment.