Skip to content

Commit

Permalink
cnf network: update RDMA Metrics API Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaggapa committed Jan 21, 2025
1 parent 66d008a commit 68e561f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tests/cnf/core/network/sriov/tests/rdmametricsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
sriovNetNodeState *sriov.PoolConfigBuilder
tPol1, tPol2 *sriov.PolicyBuilder
tNet1, tNet2 *sriov.NetworkBuilder
testPod *pod.Builder
)

BeforeAll(func() {
Expand Down Expand Up @@ -88,7 +89,7 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
})
It("1 Pod with 1 VF", reportxml.ID("77651"), func() {
By("Define and Create Test Pod")
testPod := defineAndCreatePod(tNet1.Object.Name, "")
testPod = defineAndCreatePod(tNet1.Object.Name, "")

By("Verify allocatable devices doesn't change after sriov-device-plugin pod restart")
verifyAllocatableResouces(testPod, tPol1.Object.Spec.ResourceName)
Expand All @@ -98,7 +99,7 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
})
It("1 Pod with 2 VF of same PF", reportxml.ID("77650"), func() {
By("Define and Create Test Pod")
testPod := defineAndCreatePod(tNet1.Object.Name, tNet1.Object.Name)
testPod = defineAndCreatePod(tNet1.Object.Name, tNet1.Object.Name)

By("Verify allocatable devices doesn't change after sriov-device-plugin pod restart")
verifyAllocatableResouces(testPod, tPol1.Object.Spec.ResourceName)
Expand All @@ -109,7 +110,7 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
})
It("1 Pod with 2 VF of different PF", reportxml.ID("77649"), func() {
By("Define and Create Test Pod")
testPod := defineAndCreatePod(tNet1.Object.Name, tNet2.Object.Name)
testPod = defineAndCreatePod(tNet1.Object.Name, tNet2.Object.Name)

By("Verify allocatable devices doesn't change after sriov-device-plugin pod restart")
verifyAllocatableResouces(testPod, tPol1.Object.Spec.ResourceName)
Expand All @@ -121,10 +122,10 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
})

AfterEach(func() {
By("Cleaning test namespace")
err := namespace.NewBuilder(APIClient, tsparams.TestNamespaceName).CleanObjects(
netparam.DefaultTimeout, pod.GetGVR())
Expect(err).ToNot(HaveOccurred(), "Failed to clean test namespace")
By("Delete test pod")
_, err := testPod.DeleteAndWait(1 * time.Minute)
Expect(err).ToNot(HaveOccurred(), "Failed to delete test pod")

})

AfterAll(func() {
Expand Down Expand Up @@ -169,6 +170,8 @@ var _ = Describe("rdmaMetricsAPI", Ordered, Label(tsparams.LabelRdmaMetricsAPITe
pciAddress, rdmaDevice, err := getInterfacePci(testPod, "net1")
Expect(err).ToNot(HaveOccurred(),
"Could not get PCI Address and/or Rdma device from Pod Annotations")
Expect(pciAddress).To(Not(BeEmpty()), "pci-address field is empty")
Expect(rdmaDevice).To(Not(BeEmpty()), "rdma-device field is empty")

By("Verify Rdma Metrics should not be present inside Pod")
podOutput, err := testPod.ExecCommand(
Expand Down Expand Up @@ -266,19 +269,19 @@ func verifyAllocatableResouces(tPod *pod.Builder, resName string) {
Expect(err).ToNot(HaveOccurred(), "Failed to list sriov device plugin pods")
Expect(len(sriovDevicePluginPods)).To(Equal(1), "Failed to fetch the sriov device plugin pod")

_, err = sriovDevicePluginPods[0].Delete()
_, err = sriovDevicePluginPods[0].DeleteAndWait(1 * time.Minute)
Expect(err).ToNot(HaveOccurred(), "Failed to delete the sriov device plugin pod")

Eventually(func() bool {
sriovDevicePluginPods, err := pod.List(APIClient, NetConfig.SriovOperatorNamespace, metav1.ListOptions{
sriovDevicePluginPods, err = pod.List(APIClient, NetConfig.SriovOperatorNamespace, metav1.ListOptions{
LabelSelector: labels.Set{"app": "sriov-device-plugin"}.String(),
FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": tPod.Object.Spec.NodeName}).String()})
Expect(err).ToNot(HaveOccurred(), "Failed to list sriov device plugin pods")

return len(sriovDevicePluginPods) == 1
}, 1*time.Minute, 2*time.Second).Should(BeTrue(), "Failed to find the new sriov device plugin pod")

Consistently(func() bool {
Eventually(func() bool {
testNode, err := nodes.Pull(APIClient, tPod.Object.Spec.NodeName)
Expect(err).NotTo(HaveOccurred(), "Failed to pull test pod's host worker node")

Expand Down Expand Up @@ -398,6 +401,8 @@ func verifyRdmaMetrics(inputPod *pod.Builder, iName string) {
pciAddress, rdmaDevice, err := getInterfacePci(inputPod, iName)
Expect(err).ToNot(HaveOccurred(),
"Could not get PCI Address and/or Rdma device from Pod Annotations")
Expect(pciAddress).To(Not(BeEmpty()), "pci-address field is empty")
Expect(rdmaDevice).To(Not(BeEmpty()), "rdma-device field is empty")

By("Rdma metrics should be present inside the Pod")

Expand Down

0 comments on commit 68e561f

Please sign in to comment.