Skip to content

Commit

Permalink
e2e, persistent-ips: Unify ipsFrom function for primary/secondary UDNs
Browse files Browse the repository at this point in the history
Now that both secondary/primary UDNs get the IPs from the vmi.status, it
possible to remove the ipsFrom helper function, and instead use the
interface name as a parameter of the test.
Doing so unifies and simplifies the e2e tests for both secondary and primary UDNs.

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Nov 21, 2024
1 parent 5aca44d commit fef420c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
48 changes: 18 additions & 30 deletions test/e2e/persistentips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const (
)

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

var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
Expand Down Expand Up @@ -112,13 +112,12 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
WithPolling(time.Second).
ShouldNot(BeEmpty())

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

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

testenv.LiveMigrateVirtualMachine(td.Namespace, vm.Name)
Expand All @@ -130,7 +129,7 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
WithTimeout(5 * time.Minute).
Should(testenv.ContainConditionVMIReady())

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

It("should garbage collect IPAMClaims after VM deletion", func() {
Expand Down Expand Up @@ -189,8 +188,7 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {

It("should keep ips after restart", func() {
Expect(testenv.Client.Get(context.Background(), client.ObjectKeyFromObject(vmi), vmi)).To(Succeed())
vmiIPsBeforeRestart, err := params.ipsFrom(vmi)
Expect(err).NotTo(HaveOccurred())
vmiIPsBeforeRestart := testenv.GetIPsFromVMIStatus(vmi, params.networkInterfaceName)
Expect(vmiIPsBeforeRestart).NotTo(BeEmpty())
vmiUUIDBeforeRestart := vmi.UID

Expand All @@ -210,7 +208,7 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
WithTimeout(5 * time.Minute).
Should(testenv.ContainConditionVMIReady())

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

Expand All @@ -237,8 +235,7 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
ShouldNot(BeEmpty())

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

Expand Down Expand Up @@ -280,19 +277,18 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
WithPolling(time.Second).
ShouldNot(BeEmpty())

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

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

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

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

It("should garbage collect IPAMClaims after VMI deletion", func() {
Expand All @@ -316,15 +312,15 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
},
Entry("secondary interfaces",
testParams{
role: roleSecondary,
ipsFrom: secondaryNetworkVMIStatusIPs,
vmi: vmiWithMultus,
role: roleSecondary,
networkInterfaceName: secondaryLogicalNetworkInterfaceName,
vmi: vmiWithMultus,
}),
Entry("primary UDN",
testParams{
role: rolePrimary,
ipsFrom: primaryNetworkVMIStatusIPs,
vmi: vmiWithManagedTap,
role: rolePrimary,
networkInterfaceName: primaryLogicalNetworkInterfaceName,
vmi: vmiWithManagedTap,
}),
)

Expand All @@ -344,14 +340,6 @@ func removeFinalizersPatch() ([]byte, error) {
return json.Marshal(patch)
}

func secondaryNetworkVMIStatusIPs(vmi *kubevirtv1.VirtualMachineInstance) ([]string, error) {
return testenv.GetIPsFromVMIStatus(vmi, secondaryLogicalNetworkInterfaceName), nil
}

func primaryNetworkVMIStatusIPs(vmi *kubevirtv1.VirtualMachineInstance) ([]string, error) {
return testenv.GetIPsFromVMIStatus(vmi, primaryLogicalNetworkInterfaceName), nil
}

func vmiWithMultus(namespace string) *kubevirtv1.VirtualMachineInstance {
interfaceName := secondaryLogicalNetworkInterfaceName
return testenv.NewVirtualMachineInstance(
Expand Down
24 changes: 13 additions & 11 deletions test/env/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ func vmiStatusConditions(vmi *kubevirtv1.VirtualMachineInstance) []kubevirtv1.Vi
return vmi.Status.Conditions
}

type IPResult struct {
IPs []string
Err error
func interfaceIPs(networkInterface *kubevirtv1.VirtualMachineInstanceNetworkInterface) []string {
if networkInterface == nil {
return nil
}
return networkInterface.IPs
}

func MatchIPs(getIPsFunc func(vmi *kubevirtv1.VirtualMachineInstance) ([]string, error), ipsMatcher gomegatypes.GomegaMatcher) gomegatypes.GomegaMatcher {
return WithTransform(func(vmi *kubevirtv1.VirtualMachineInstance) IPResult {
ips, err := getIPsFunc(vmi)
return IPResult{IPs: ips, Err: err}
}, SatisfyAll(
WithTransform(func(result IPResult) error { return result.Err }, Succeed()),
WithTransform(func(result IPResult) []string { return result.IPs }, ipsMatcher),
))
func MatchIPsAtInterfaceByName(interfaceName string, ipsMatcher gomegatypes.GomegaMatcher) gomegatypes.GomegaMatcher {
return WithTransform(
func(vmi *kubevirtv1.VirtualMachineInstance) *kubevirtv1.VirtualMachineInstanceNetworkInterface {
return lookupInterfaceStatusByName(vmi.Status.Interfaces, interfaceName)
},
SatisfyAll(
Not(BeNil()),
WithTransform(interfaceIPs, ipsMatcher)))
}

func BeRestarted(oldUID types.UID) gomegatypes.GomegaMatcher {
Expand Down

0 comments on commit fef420c

Please sign in to comment.