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 1, 2024
1 parent fb75885 commit 2545932
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 @@ -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() {
Expand All @@ -59,24 +68,23 @@ 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()
DeferCleanup(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")
Expand All @@ -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())

Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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)))
})
})

Expand All @@ -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())
})
Expand Down Expand Up @@ -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() {
Expand All @@ -300,7 +308,13 @@ var _ = Describe("Persistent IPs", func() {
})

})
})
},
Entry("secondary interfaces",
testParams{
role: roleSecondary,
getIPsFunc: getIPsFromVMIStatus,
}),
)

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

0 comments on commit 2545932

Please sign in to comment.