Skip to content

Commit

Permalink
add func test for MTU in network-status annotation
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Sch <[email protected]>
  • Loading branch information
SchSeba committed May 13, 2024
1 parent 5418684 commit 61e4a8b
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ var _ = Describe("[sriov] operator", func() {
By("Using device " + vfioNic.Name + " on node " + vfioNode)
})

It("Should be possible to create a vfio-pci resource", func() {
It("Should be possible to create a vfio-pci resource and allocate to a pod", func() {
By("creating a vfio-pci node policy")
resourceName := "testvfio"
_, err := network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, vfioNic.Name, vfioNode, 5, resourceName, "vfio-pci")
Expand Down Expand Up @@ -1157,6 +1157,39 @@ var _ = Describe("[sriov] operator", func() {
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(5)))

By("Creating sriov network to use the vfio device")
sriovNetwork := &sriovv1.SriovNetwork{
ObjectMeta: metav1.ObjectMeta{
Name: "test-vfionetwork",
Namespace: operatorNamespace,
},
Spec: sriovv1.SriovNetworkSpec{
ResourceName: resourceName,
IPAM: `{"type":"host-local","subnet":"10.10.10.0/24","rangeStart":"10.10.10.171","rangeEnd":"10.10.10.181","routes":[{"dst":"0.0.0.0/0"}],"gateway":"10.10.10.1"}`,
NetworkNamespace: namespaces.Test,
}}

err = clients.Create(context.Background(), sriovNetwork)
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
netAttDef := &netattdefv1.NetworkAttachmentDefinition{}
return clients.Get(context.Background(), runtimeclient.ObjectKey{Name: "test-vfionetwork", Namespace: namespaces.Test}, netAttDef)
}, (10+snoTimeoutMultiplier*110)*time.Second, 1*time.Second).ShouldNot(HaveOccurred())

podDefinition := pod.DefineWithNetworks([]string{"test-vfionetwork"})
firstPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func() corev1.PodPhase {
firstPod, _ = clients.Pods(namespaces.Test).Get(context.Background(), firstPod.Name, metav1.GetOptions{})
return firstPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))

By("Checking MTU in pod network status annotation")
networkStatusJson, exist := firstPod.Annotations["k8s.v1.cni.cncf.io/network-status"]

Check failure on line 1190 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / build

ST1003: var networkStatusJson should be networkStatusJSON (stylecheck)

Check failure on line 1190 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

ST1003: var networkStatusJson should be networkStatusJSON (stylecheck)
Expect(exist).To(BeTrue())
Expect(networkStatusJson).To(ContainSubstring(fmt.Sprintf("\"mtu\": %d", vfioNic.Mtu)))
})
})

Expand Down Expand Up @@ -1619,6 +1652,11 @@ var _ = Describe("[sriov] operator", func() {
return firstPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))

By("Checking MTU in pod network status annotation")
networkStatusJson, exist := firstPod.Annotations["k8s.v1.cni.cncf.io/network-status"]

Check failure on line 1656 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / build

ST1003: var networkStatusJson should be networkStatusJSON (stylecheck)

Check failure on line 1656 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

ST1003: var networkStatusJson should be networkStatusJSON (stylecheck)
Expect(exist).To(BeTrue())
Expect(networkStatusJson).To(ContainSubstring("\"mtu\": 9000"))

var stdout, stderr string
Eventually(func() error {
stdout, stderr, err = pod.ExecCommand(clients, firstPod, "ip", "link", "show", "net1")
Expand Down

0 comments on commit 61e4a8b

Please sign in to comment.