@@ -139,14 +139,46 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
139
139
testAttachWriteReadDetach (volID , volName , testContext .Instance , testContext .Client , readOnly )
140
140
i = i + 1
141
141
}
142
-
143
142
})
144
-
145
143
})
146
144
145
+ type verifyArgs struct {
146
+ publishDir string
147
+ }
148
+
149
+ type verifyFunc func (verifyArgs ) error
150
+
147
151
func testAttachWriteReadDetach (volID string , volName string , instance * remote.InstanceInfo , client * remote.CsiClient , readOnly bool ) error {
148
- var err error
152
+ var testFileContents = "test"
153
+ writeFile := func (a verifyArgs ) error {
154
+ if ! readOnly {
155
+ // Write a file
156
+ testFile := filepath .Join (a .publishDir , "testfile" )
157
+ err := testutils .WriteFile (instance , testFile , testFileContents )
158
+ if err != nil {
159
+ return fmt .Errorf ("Failed to write file: %v" , err )
160
+ }
161
+ }
162
+ return nil
163
+ }
149
164
165
+ verifyReadFile := func (a verifyArgs ) error {
166
+ // Read File
167
+ secondTestFile := filepath .Join (a .publishDir , "testfile" )
168
+ readContents , err := testutils .ReadFile (instance , secondTestFile )
169
+ if err != nil {
170
+ return fmt .Errorf ("ReadFile failed with error: %v" , err )
171
+ }
172
+ if strings .TrimSpace (string (readContents )) != testFileContents {
173
+ return fmt .Errorf ("wanted test file content: %s, got content: %s" , testFileContents , readContents )
174
+ }
175
+ return nil
176
+ }
177
+ return testLifecycleWithVerify (volID , volName , instance , client , readOnly , false /* fs */ , writeFile , verifyReadFile )
178
+ }
179
+
180
+ func testLifecycleWithVerify (volID string , volName string , instance * remote.InstanceInfo , client * remote.CsiClient , readOnly , useBlock bool , firstMountVerify , secondMountVerify verifyFunc ) error {
181
+ var err error
150
182
klog .Infof ("Starting testAttachWriteReadDetach with volume %v node %v with readonly %v\n " , volID , instance .GetNodeID (), readOnly )
151
183
// Attach Disk
152
184
err = client .ControllerPublishVolume (volID , instance .GetNodeID ())
@@ -165,7 +197,13 @@ func testAttachWriteReadDetach(volID string, volName string, instance *remote.In
165
197
166
198
// Stage Disk
167
199
stageDir := filepath .Join ("/tmp/" , volName , "stage" )
168
- err = client .NodeStageExt4Volume (volID , stageDir )
200
+ if useBlock {
201
+ err = client .NodeStageBlockVolume (volID , stageDir )
202
+ } else {
203
+ err = client .NodeStageExt4Volume (volID , stageDir )
204
+ }
205
+
206
+ //err = client.NodeStageExt4Volume(volID, stageDir)
169
207
if err != nil {
170
208
return fmt .Errorf ("NodeStageExt4Volume failed with error: %v" , err )
171
209
}
@@ -185,33 +223,13 @@ func testAttachWriteReadDetach(volID string, volName string, instance *remote.In
185
223
186
224
// Mount Disk
187
225
publishDir := filepath .Join ("/tmp/" , volName , "mount" )
188
- err = client .NodePublishVolume (volID , stageDir , publishDir )
189
- if err != nil {
190
- return fmt .Errorf ("NodePublishVolume failed with error: %v" , err )
191
- }
192
- err = testutils .ForceChmod (instance , filepath .Join ("/tmp/" , volName ), "777" )
193
- if err != nil {
194
- return fmt .Errorf ("Chmod failed with error: %v" , err )
195
- }
196
- testFileContents := "test"
197
- if ! readOnly {
198
- // Write a file
199
- testFile := filepath .Join (publishDir , "testfile" )
200
- err = testutils .WriteFile (instance , testFile , testFileContents )
201
- if err != nil {
202
- return fmt .Errorf ("Failed to write file: %v" , err )
203
- }
204
- }
205
226
206
- // Unmount Disk
207
- err = client .NodeUnpublishVolume (volID , publishDir )
208
- if err != nil {
209
- return fmt . Errorf ( "NodeUnpublishVolume failed with error: %v" , err )
227
+ if useBlock {
228
+ err = client .NodePublishBlockVolume (volID , stageDir , publishDir )
229
+ } else {
230
+ err = client . NodePublishVolume ( volID , stageDir , publishDir )
210
231
}
211
232
212
- // Mount disk somewhere else
213
- secondPublishDir := filepath .Join ("/tmp/" , volName , "secondmount" )
214
- err = client .NodePublishVolume (volID , stageDir , secondPublishDir )
215
233
if err != nil {
216
234
return fmt .Errorf ("NodePublishVolume failed with error: %v" , err )
217
235
}
@@ -220,20 +238,45 @@ func testAttachWriteReadDetach(volID string, volName string, instance *remote.In
220
238
return fmt .Errorf ("Chmod failed with error: %v" , err )
221
239
}
222
240
223
- // Read File
224
- secondTestFile := filepath .Join (secondPublishDir , "testfile" )
225
- readContents , err := testutils .ReadFile (instance , secondTestFile )
241
+ a := verifyArgs {
242
+ publishDir : publishDir ,
243
+ }
244
+
245
+ err = firstMountVerify (a )
226
246
if err != nil {
227
- return fmt .Errorf ("ReadFile failed with error : %v" , err )
247
+ return fmt .Errorf ("failed to verify after first mount to %s : %v" , publishDir , err )
228
248
}
229
- Expect (strings .TrimSpace (string (readContents ))).To (Equal (testFileContents ))
230
249
231
250
// Unmount Disk
232
- err = client .NodeUnpublishVolume (volID , secondPublishDir )
251
+ err = client .NodeUnpublishVolume (volID , publishDir )
233
252
if err != nil {
234
253
return fmt .Errorf ("NodeUnpublishVolume failed with error: %v" , err )
235
254
}
236
255
256
+ if secondMountVerify != nil {
257
+ // Mount disk somewhere else
258
+ secondPublishDir := filepath .Join ("/tmp/" , volName , "secondmount" )
259
+ err = client .NodePublishVolume (volID , stageDir , secondPublishDir )
260
+ if err != nil {
261
+ return fmt .Errorf ("NodePublishVolume failed with error: %v" , err )
262
+ }
263
+ err = testutils .ForceChmod (instance , filepath .Join ("/tmp/" , volName ), "777" )
264
+ if err != nil {
265
+ return fmt .Errorf ("Chmod failed with error: %v" , err )
266
+ }
267
+
268
+ b := verifyArgs {
269
+ publishDir : secondPublishDir ,
270
+ }
271
+ secondMountVerify (b )
272
+
273
+ // Unmount Disk
274
+ err = client .NodeUnpublishVolume (volID , secondPublishDir )
275
+ if err != nil {
276
+ return fmt .Errorf ("NodeUnpublishVolume failed with error: %v" , err )
277
+ }
278
+ }
279
+
237
280
klog .Infof ("Completed testAttachWriteReadDetach with volume %v node %v\n " , volID , instance .GetNodeID ())
238
281
return nil
239
282
}
0 commit comments