@@ -29,6 +29,7 @@ import (
2929 "k8s.io/apimachinery/pkg/labels"
3030 "k8s.io/kubernetes/test/e2e/framework"
3131 e2edebug "k8s.io/kubernetes/test/e2e/framework/debug"
32+ e2ejob "k8s.io/kubernetes/test/e2e/framework/job"
3233 e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
3334 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3435 admissionapi "k8s.io/pod-security-admission/api"
@@ -38,6 +39,8 @@ const (
3839 qatPluginKustomizationYaml = "deployments/qat_plugin/overlays/e2e/kustomization.yaml"
3940 cryptoTestYaml = "deployments/qat_dpdk_app/crypto-perf/crypto-perf-dpdk-pod-requesting-qat-cy.yaml"
4041 compressTestYaml = "deployments/qat_dpdk_app/compress-perf/compress-perf-dpdk-pod-requesting-qat-dc.yaml"
42+ cyResource = "qat.intel.com/cy"
43+ dcResource = "qat.intel.com/dc"
4144)
4245
4346const (
@@ -77,6 +80,7 @@ func describeQatDpdkPlugin() {
7780 var dpPodName string
7881
7982 var resourceName v1.ResourceName
83+ var nodeName string
8084
8185 ginkgo .JustBeforeEach (func (ctx context.Context ) {
8286 ginkgo .By ("deploying QAT plugin in DPDK mode" )
@@ -97,6 +101,18 @@ func describeQatDpdkPlugin() {
97101 framework .Failf ("container filesystem info checks failed: %v" , err )
98102 }
99103
104+ // when running [Functionality] e2e tests
105+ if resourceName == "" {
106+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , cyResource , 100 * time .Second , utils .WaitForPositiveResource ); err != nil {
107+ resourceName = dcResource
108+ nodeName , _ = utils .FindNodeAndResourceCapacity (f , ctx , dcResource )
109+ return
110+ }
111+ resourceName = cyResource
112+ nodeName , _ = utils .FindNodeAndResourceCapacity (f , ctx , cyResource )
113+ return
114+ }
115+
100116 ginkgo .By ("checking if the resource is allocatable" )
101117 if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 30 * time .Second , utils .WaitForPositiveResource ); err != nil {
102118 framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
@@ -111,14 +127,14 @@ func describeQatDpdkPlugin() {
111127 }
112128 })
113129
114- ginkgo .Context ("When QAT resources are available with crypto (cy) services enabled [Resource:cy]" , func () {
130+ ginkgo .Context ("When QAT resources are continuously available with crypto (cy) services enabled [Resource:cy]" , func () {
115131 // This BeforeEach runs even before the JustBeforeEach above.
116132 ginkgo .BeforeEach (func () {
117133 ginkgo .By ("creating a configMap before plugin gets deployed" )
118134 e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "--from-literal" , "qat.conf=ServicesEnabled=sym;asym" , "qat-config" )
119135
120136 ginkgo .By ("setting resourceName for cy services" )
121- resourceName = "qat.intel.com/cy"
137+ resourceName = cyResource
122138 })
123139
124140 ginkgo .It ("deploys a crypto pod (openssl) requesting QAT resources [App:openssl]" , func (ctx context.Context ) {
@@ -139,13 +155,13 @@ func describeQatDpdkPlugin() {
139155 })
140156 })
141157
142- ginkgo .Context ("When QAT resources are available with compress (dc) services enabled [Resource:dc]" , func () {
158+ ginkgo .Context ("When QAT resources are continuously available with compress (dc) services enabled [Resource:dc]" , func () {
143159 ginkgo .BeforeEach (func () {
144160 ginkgo .By ("creating a configMap before plugin gets deployed" )
145161 e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "--from-literal" , "qat.conf=ServicesEnabled=dc" , "qat-config" )
146162
147163 ginkgo .By ("setting resourceName for dc services" )
148- resourceName = "qat.intel.com/dc"
164+ resourceName = dcResource
149165 })
150166
151167 ginkgo .It ("deploys a compress pod (openssl) requesting QAT resources [App:openssl]" , func (ctx context.Context ) {
@@ -165,6 +181,57 @@ func describeQatDpdkPlugin() {
165181 ginkgo .It ("does nothing" , func () {})
166182 })
167183 })
184+
185+ ginkgo .Context ("When a QAT device goes unresponsive" , func () {
186+ ginkgo .When ("QAT's auto-reset is off" , func () {
187+ ginkgo .BeforeEach (func () {
188+ ginkgo .By ("creating a configMap before plugin gets deployed" )
189+ e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "--from-literal" , "qat.conf=AutoresetEnabled=off" , "qat-config" )
190+ })
191+
192+ ginkgo .It ("checks if the heartbeat is read correctly [Functionality:heartbeat]" , func (ctx context.Context ) {
193+ injectError (ctx , f , nodeName )
194+
195+ ginkgo .By ("seeing if there is zero resource" )
196+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForZeroResource ); err != nil {
197+ framework .Failf ("unable to wait for nodes to have no resource: %v" , err )
198+ }
199+ })
200+ })
201+
202+ ginkgo .When ("QAT's autoreset is on" , func () {
203+ ginkgo .BeforeEach (func () {
204+ ginkgo .By ("creating a configMap before plugin gets deployed" )
205+ e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "--from-literal" , "qat.conf=AutoresetEnabled=on" , "qat-config" )
206+ })
207+
208+ ginkgo .It ("checks if an injected error gets solved [Functionality:auto-reset]" , func (ctx context.Context ) {
209+ injectError (ctx , f , nodeName )
210+
211+ ginkgo .By ("seeing if there is zero resource" )
212+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForZeroResource ); err != nil {
213+ framework .Logf ("unable to wait for nodes to have no resource: %v" , err )
214+ // It should not be Failf since there can be a case auto-reset worked before plugin notices.
215+ // It is still necessary to have utils.WaitForNodeWithResource for WaitForZeroResource
216+ // because there can be also a case that the following part that checks WaitForPositiveResource may run
217+ // before the injected error is recognized by plugin when this part does not exist.
218+ // In other words, this is necessary to ensure that the injected error does not remain after this It() spec.
219+ }
220+
221+ ginkgo .By ("seeing if there is positive allocatable resource" )
222+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 300 * time .Second , utils .WaitForPositiveResource ); err != nil {
223+ framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
224+ }
225+
226+ ginkgo .By ("checking if openssl pod runs successfully" )
227+ if resourceName == cyResource {
228+ runCpaSampleCode (ctx , f , symmetric , resourceName )
229+ } else {
230+ runCpaSampleCode (ctx , f , compression , resourceName )
231+ }
232+ })
233+ })
234+ })
168235}
169236
170237func runCpaSampleCode (ctx context.Context , f * framework.Framework , runTests int , resourceName v1.ResourceName ) {
@@ -199,3 +266,35 @@ func runCpaSampleCode(ctx context.Context, f *framework.Framework, runTests int,
199266 err = e2epod .WaitForPodSuccessInNamespaceTimeout (ctx , f .ClientSet , pod .ObjectMeta .Name , f .Namespace .Name , 300 * time .Second )
200267 gomega .Expect (err ).To (gomega .BeNil (), utils .GetPodLogs (ctx , f , pod .ObjectMeta .Name , pod .Spec .Containers [0 ].Name ))
201268}
269+
270+ func injectError (ctx context.Context , f * framework.Framework , nodeName string ) {
271+ job := e2ejob .NewTestJobOnNode ("success" , "qat-inject-error" , v1 .RestartPolicyNever , 1 , 1 , nil , 0 , nodeName )
272+
273+ job .Spec .Template .Spec .Containers [0 ].Command = []string {
274+ "/bin/sh" ,
275+ "-c" ,
276+ "find /sys/kernel/debug/qat_*/heartbeat/ -name inject_error -exec sh -c 'echo 1 > {}' \\ ;" ,
277+ }
278+ job .Spec .Template .Spec .Containers [0 ].VolumeMounts = []v1.VolumeMount {{
279+ Name : "debugfs" ,
280+ MountPath : "/sys/kernel/debug/" ,
281+ }}
282+ job .Spec .Template .Spec .Volumes = []v1.Volume {{
283+ Name : "debugfs" ,
284+ VolumeSource : v1.VolumeSource {
285+ HostPath : & v1.HostPathVolumeSource {
286+ Path : "/sys/kernel/debug/" ,
287+ },
288+ },
289+ }}
290+ yes := true
291+ job .Spec .Template .Spec .Containers [0 ].SecurityContext = & v1.SecurityContext {
292+ Privileged : & yes ,
293+ }
294+
295+ job , err := e2ejob .CreateJob (ctx , f .ClientSet , f .Namespace .Name , job )
296+ framework .ExpectNoError (err , "failed to create job in namespace: %s" , f .Namespace .Name )
297+
298+ err = e2ejob .WaitForJobComplete (ctx , f .ClientSet , f .Namespace .Name , job .Name , nil , 1 )
299+ framework .ExpectNoError (err , "failed to ensure job completion in namespace: %s" , f .Namespace .Name )
300+ }
0 commit comments