|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strings" |
| 6 | + "time" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + . "github.com/onsi/gomega/gstruct" |
| 11 | + |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + "k8s.io/apimachinery/pkg/api/resource" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" |
| 16 | + |
| 17 | + sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" |
| 18 | + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" |
| 19 | + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery" |
| 20 | + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces" |
| 21 | + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/network" |
| 22 | + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/pod" |
| 23 | +) |
| 24 | + |
| 25 | +var _ = FDescribe("[sriov] aws platform", Ordered, func() { |
| 26 | + BeforeAll(func() { |
| 27 | + if platformType != consts.AWS { |
| 28 | + Skip("AWS platform is not supported on non-AWS platforms") |
| 29 | + } |
| 30 | + Expect(len(sriovInfos.Nodes)).ToNot(BeZero()) |
| 31 | + Expect(len(sriovInfos.States)).ToNot(BeZero()) |
| 32 | + Expect(sriovInfos.States[sriovInfos.Nodes[0]].Status.Interfaces).ToNot(BeEmpty()) |
| 33 | + Expect(sriovInfos.States[sriovInfos.Nodes[0]].Status.Interfaces[0].NetFilter).To(ContainSubstring("aws/NetworkID:")) |
| 34 | + }) |
| 35 | + |
| 36 | + AfterAll(func() { |
| 37 | + err := namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled()) |
| 38 | + Expect(err).ToNot(HaveOccurred()) |
| 39 | + WaitForSRIOVStable() |
| 40 | + }) |
| 41 | + |
| 42 | + Describe("Generic SriovNetworkNodePolicy", func() { |
| 43 | + It("should configure vf in vfio-pci mode", func() { |
| 44 | + node := sriovInfos.Nodes[0] |
| 45 | + nic, err := sriovInfos.FindOneSriovDevice(node) |
| 46 | + Expect(err).ToNot(HaveOccurred()) |
| 47 | + Expect(nic).ToNot(BeNil()) |
| 48 | + |
| 49 | + By("creating a vfio-pci node policy") |
| 50 | + resourceName := "testvfio" |
| 51 | + vfioPolicy, err := network.CreateSriovPolicyWithNetfilter(clients, "test-policy-", operatorNamespace, nic.NetFilter, node, 1, resourceName, "vfio-pci") |
| 52 | + Expect(err).ToNot(HaveOccurred()) |
| 53 | + |
| 54 | + By("waiting for the node state to be updated") |
| 55 | + Eventually(func() sriovv1.Interfaces { |
| 56 | + nodeState := &sriovv1.SriovNetworkNodeState{} |
| 57 | + err := clients.Get(context.Background(), runtimeclient.ObjectKey{Namespace: operatorNamespace, Name: node}, nodeState) |
| 58 | + Expect(err).ToNot(HaveOccurred()) |
| 59 | + return nodeState.Spec.Interfaces |
| 60 | + }, 1*time.Minute, 1*time.Second).Should(ContainElement(MatchFields( |
| 61 | + IgnoreExtras, |
| 62 | + Fields{ |
| 63 | + "Name": Equal(nic.Name), |
| 64 | + "NumVfs": Equal(1), |
| 65 | + }))) |
| 66 | + |
| 67 | + By("waiting the sriov to be stable on the node") |
| 68 | + WaitForSRIOVStable() |
| 69 | + |
| 70 | + By("waiting for the resources to be available") |
| 71 | + Eventually(func() int64 { |
| 72 | + testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), node, metav1.GetOptions{}) |
| 73 | + Expect(err).ToNot(HaveOccurred()) |
| 74 | + resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)] |
| 75 | + allocatable, _ := resNum.AsInt64() |
| 76 | + return allocatable |
| 77 | + }, 10*time.Minute, time.Second).Should(Equal(int64(1))) |
| 78 | + |
| 79 | + By("validate the pf info exist on host") |
| 80 | + output, _, err := runCommandOnConfigDaemon(node, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l") |
| 81 | + Expect(err).ToNot(HaveOccurred()) |
| 82 | + Expect(output).ToNot(Equal("1")) |
| 83 | + |
| 84 | + podDefinition := pod.GetDefinition() |
| 85 | + podDefinition.Spec.Containers[0].Resources = corev1.ResourceRequirements{ |
| 86 | + Requests: corev1.ResourceList{ |
| 87 | + corev1.ResourceName("openshift.io/" + resourceName): resource.MustParse("1"), |
| 88 | + }, |
| 89 | + Limits: corev1.ResourceList{ |
| 90 | + corev1.ResourceName("openshift.io/" + resourceName): resource.MustParse("1"), |
| 91 | + }, |
| 92 | + } |
| 93 | + |
| 94 | + firstPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{}) |
| 95 | + Expect(err).ToNot(HaveOccurred()) |
| 96 | + |
| 97 | + firstPod = waitForPodRunning(firstPod) |
| 98 | + |
| 99 | + By("Checking the vfio device exist inside the pod") |
| 100 | + output, errOutput, err := pod.ExecCommand(clients, firstPod, "sh", "-c", "ls /dev/vfio/ | wc -l") |
| 101 | + Expect(err).ToNot(HaveOccurred()) |
| 102 | + Expect(errOutput).To(Equal("")) |
| 103 | + Expect(strings.TrimSpace(output)).To(Equal("2")) |
| 104 | + |
| 105 | + By("deleting the policy") |
| 106 | + err = clients.Delete(context.Background(), vfioPolicy, &runtimeclient.DeleteOptions{}) |
| 107 | + Expect(err).ToNot(HaveOccurred()) |
| 108 | + WaitForSRIOVStable() |
| 109 | + |
| 110 | + Eventually(func() int64 { |
| 111 | + testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), node, metav1.GetOptions{}) |
| 112 | + Expect(err).ToNot(HaveOccurred()) |
| 113 | + resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)] |
| 114 | + allocatable, _ := resNum.AsInt64() |
| 115 | + return allocatable |
| 116 | + }, 2*time.Minute, time.Second).Should(Equal(int64(0))) |
| 117 | + |
| 118 | + By("validate the pf info doesn't exist on the host anymore") |
| 119 | + output, _, err = runCommandOnConfigDaemon(node, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l") |
| 120 | + Expect(err).ToNot(HaveOccurred()) |
| 121 | + Expect(output).ToNot(Equal("0")) |
| 122 | + |
| 123 | + By("checking the driver was reset to default") |
| 124 | + nodeState := &sriovv1.SriovNetworkNodeState{} |
| 125 | + err = clients.Get(context.Background(), runtimeclient.ObjectKey{Namespace: operatorNamespace, Name: node}, nodeState) |
| 126 | + Expect(err).ToNot(HaveOccurred()) |
| 127 | + Expect(nodeState.Status.Interfaces).To(ContainElement(MatchFields( |
| 128 | + IgnoreExtras, |
| 129 | + Fields{ |
| 130 | + "Name": Equal(nic.Name), |
| 131 | + "Driver": Equal("ena"), |
| 132 | + }))) |
| 133 | + }) |
| 134 | + }) |
| 135 | +}) |
0 commit comments