@@ -16,7 +16,10 @@ package dsa
16
16
17
17
import (
18
18
"context"
19
+ "io"
20
+ "os"
19
21
"path/filepath"
22
+ "strings"
20
23
"time"
21
24
22
25
"github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/utils"
@@ -36,13 +39,76 @@ const (
36
39
kustomizationYaml = "deployments/dsa_plugin/overlays/dsa_initcontainer/dsa_initcontainer.yaml"
37
40
configmapYaml = "demo/dsa.conf"
38
41
demoYaml = "demo/dsa-accel-config-demo-pod.yaml"
42
+ dpdkDemoYaml = "demo/dsa-dpdk-dmadevtest.yaml"
39
43
podName = "dsa-accel-config-demo"
44
+ dpdkPodName = "dpdk"
45
+
46
+ appMode = false
47
+ dpdkMode = true
40
48
)
41
49
42
50
func init () {
43
51
ginkgo .Describe ("DSA plugin [Device:dsa]" , describe )
44
52
}
45
53
54
+ func createDsaConfigWithDpdkMode (configmap , tmpDir string ) string {
55
+ origFile , err := os .Open (configmap )
56
+ if err != nil {
57
+ framework .Failf ("unable to open dsa configmap from %s: %+v" , configmap , err )
58
+ }
59
+ defer origFile .Close ()
60
+
61
+ content , err := io .ReadAll (origFile )
62
+ if err != nil {
63
+ framework .Failf ("unable to read dsa configmap from %s: %+v" , configmap , err )
64
+ }
65
+
66
+ updated := strings .ReplaceAll (string (content ), "appX" , "dpdk_X" )
67
+
68
+ newconfigmap := filepath .Join (tmpDir , "dsa.conf" )
69
+ err = os .WriteFile (newconfigmap , []byte (updated ), 0600 )
70
+ if err != nil {
71
+ framework .Failf ("unable to write updated dsa configmap: %+v" , err )
72
+ }
73
+
74
+ return newconfigmap
75
+ }
76
+
77
+ func preparePlugin (dpdkMode bool , configmap , kustomizationPath string , ctx context.Context , f * framework.Framework ) string {
78
+ ginkgo .By ("deploying DSA plugin" )
79
+
80
+ if dpdkMode {
81
+ tmpDir , err := os .MkdirTemp ("" , "dsa-config" )
82
+ if err != nil {
83
+ framework .Failf ("unable to create temporary dir for dsa config" )
84
+ }
85
+ defer os .RemoveAll (tmpDir )
86
+
87
+ configmap = createDsaConfigWithDpdkMode (configmap , tmpDir )
88
+ }
89
+
90
+ e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "intel-dsa-config" , "--from-file=" + configmap )
91
+ e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "apply" , "-k" , filepath .Dir (kustomizationPath ))
92
+
93
+ ginkgo .By ("waiting for DSA plugin's availability" )
94
+ podList , err := e2epod .WaitForPodsWithLabelRunningReady (ctx , f .ClientSet , f .Namespace .Name ,
95
+ labels.Set {"app" : "intel-dsa-plugin" }.AsSelector (), 1 /* one replica */ , 300 * time .Second )
96
+ if err != nil {
97
+ e2edebug .DumpAllNamespaceInfo (ctx , f .ClientSet , f .Namespace .Name )
98
+ e2ekubectl .LogFailedContainers (ctx , f .ClientSet , f .Namespace .Name , framework .Logf )
99
+ framework .Failf ("unable to wait for all pods to be running and ready: %v" , err )
100
+ }
101
+
102
+ dpPodName := podList .Items [0 ].Name
103
+
104
+ ginkgo .By ("checking DSA plugin's securityContext" )
105
+ if err = utils .TestPodsFileSystemInfo (podList .Items ); err != nil {
106
+ framework .Failf ("container filesystem info checks failed: %v" , err )
107
+ }
108
+
109
+ return dpPodName
110
+ }
111
+
46
112
func describe () {
47
113
f := framework .NewDefaultFramework ("dsaplugin" )
48
114
f .NamespacePodSecurityEnforceLevel = admissionapi .LevelPrivileged
@@ -62,29 +128,12 @@ func describe() {
62
128
framework .Failf ("unable to locate %q: %v" , demoYaml , errFailedToLocateRepoFile )
63
129
}
64
130
65
- var dpPodName string
66
-
67
- ginkgo .BeforeEach (func (ctx context.Context ) {
68
- ginkgo .By ("deploying DSA plugin" )
69
- e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "create" , "configmap" , "intel-dsa-config" , "--from-file=" + configmap )
70
-
71
- e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "apply" , "-k" , filepath .Dir (kustomizationPath ))
72
-
73
- ginkgo .By ("waiting for DSA plugin's availability" )
74
- podList , err := e2epod .WaitForPodsWithLabelRunningReady (ctx , f .ClientSet , f .Namespace .Name ,
75
- labels.Set {"app" : "intel-dsa-plugin" }.AsSelector (), 1 /* one replica */ , 300 * time .Second )
76
- if err != nil {
77
- e2edebug .DumpAllNamespaceInfo (ctx , f .ClientSet , f .Namespace .Name )
78
- e2ekubectl .LogFailedContainers (ctx , f .ClientSet , f .Namespace .Name , framework .Logf )
79
- framework .Failf ("unable to wait for all pods to be running and ready: %v" , err )
80
- }
81
- dpPodName = podList .Items [0 ].Name
131
+ demoDpdkPath , errFailedToLocateRepoFile := utils .LocateRepoFile (dpdkDemoYaml )
132
+ if errFailedToLocateRepoFile != nil {
133
+ framework .Failf ("unable to locate %q: %v" , dpdkDemoYaml , errFailedToLocateRepoFile )
134
+ }
82
135
83
- ginkgo .By ("checking DSA plugin's securityContext" )
84
- if err = utils .TestPodsFileSystemInfo (podList .Items ); err != nil {
85
- framework .Failf ("container filesystem info checks failed: %v" , err )
86
- }
87
- })
136
+ var dpPodName string
88
137
89
138
ginkgo .AfterEach (func (ctx context.Context ) {
90
139
ginkgo .By ("undeploying DSA plugin" )
@@ -94,8 +143,10 @@ func describe() {
94
143
}
95
144
})
96
145
97
- ginkgo .Context ("When DSA resources are available [Resource:dedicated]" , func () {
146
+ ginkgo .Context ("When DSA resources are available [Resource:dedicated] [Mode:app] " , func () {
98
147
ginkgo .BeforeEach (func (ctx context.Context ) {
148
+ dpPodName = preparePlugin (appMode , configmap , kustomizationPath , ctx , f )
149
+
99
150
ginkgo .By ("checking if the resource is allocatable" )
100
151
if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , "dsa.intel.com/wq-user-dedicated" , 300 * time .Second , utils .WaitForPositiveResource ); err != nil {
101
152
framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
@@ -114,4 +165,27 @@ func describe() {
114
165
ginkgo .It ("does nothing" , func () {})
115
166
})
116
167
})
168
+
169
+ ginkgo .Context ("When DSA resources are available [Resource:dedicated] [Mode:dpdk]" , func () {
170
+ ginkgo .BeforeEach (func (ctx context.Context ) {
171
+ dpPodName = preparePlugin (dpdkMode , configmap , kustomizationPath , ctx , f )
172
+
173
+ ginkgo .By ("checking if the resource is allocatable" )
174
+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , "dsa.intel.com/wq-user-dedicated" , 300 * time .Second , utils .WaitForPositiveResource ); err != nil {
175
+ framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
176
+ }
177
+ })
178
+
179
+ ginkgo .It ("deploys a demo app [App:dpdk-test]" , func (ctx context.Context ) {
180
+ e2ekubectl .RunKubectlOrDie (f .Namespace .Name , "apply" , "-f" , demoDpdkPath )
181
+
182
+ ginkgo .By ("waiting for the DSA DPDK demo to succeed" )
183
+ err := e2epod .WaitForPodSuccessInNamespaceTimeout (ctx , f .ClientSet , dpdkPodName , f .Namespace .Name , 200 * time .Second )
184
+ gomega .Expect (err ).To (gomega .BeNil (), utils .GetPodLogs (ctx , f , dpdkPodName , dpdkPodName ))
185
+ })
186
+
187
+ ginkgo .When ("there is no app to run [App:noapp]" , func () {
188
+ ginkgo .It ("does nothing" , func () {})
189
+ })
190
+ })
117
191
}
0 commit comments