Skip to content

Commit 45cd08b

Browse files
committed
Helper functions for managing volumes with specific access modes
1 parent e3d351a commit 45cd08b

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

pkg/sanity/node.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,13 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
191191
controllerExpansionSupported bool
192192
)
193193

194-
createVolume := func(volumeName string) *csi.CreateVolumeResponse {
194+
createVolumeWithCapability := func(volumeName string, cap *csi.VolumeCapability) *csi.CreateVolumeResponse {
195195
By("creating a single node writer volume for expansion")
196196
return r.MustCreateVolume(
197197
context.Background(),
198198
&csi.CreateVolumeRequest{
199-
Name: volumeName,
200-
VolumeCapabilities: []*csi.VolumeCapability{
201-
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
202-
},
199+
Name: volumeName,
200+
VolumeCapabilities: []*csi.VolumeCapability{cap},
203201
CapacityRange: &csi.CapacityRange{
204202
RequiredBytes: TestVolumeSize(sc),
205203
},
@@ -208,8 +206,11 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
208206
},
209207
)
210208
}
209+
createVolume := func(volumeName string) *csi.CreateVolumeResponse {
210+
return createVolumeWithCapability(volumeName, TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER))
211+
}
211212

212-
controllerPublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, nid *csi.NodeGetInfoResponse) *csi.ControllerPublishVolumeResponse {
213+
controllerPublishVolumeWithCapability := func(volumeName string, vol *csi.CreateVolumeResponse, nid *csi.NodeGetInfoResponse, cap *csi.VolumeCapability) *csi.ControllerPublishVolumeResponse {
213214
var conpubvol *csi.ControllerPublishVolumeResponse
214215
if controllerPublishSupported {
215216
By("controller publishing volume")
@@ -219,7 +220,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
219220
&csi.ControllerPublishVolumeRequest{
220221
VolumeId: vol.GetVolume().GetVolumeId(),
221222
NodeId: nid.GetNodeId(),
222-
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
223+
VolumeCapability: cap,
223224
VolumeContext: vol.GetVolume().GetVolumeContext(),
224225
Readonly: false,
225226
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
@@ -228,14 +229,17 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
228229
}
229230
return conpubvol
230231
}
232+
controllerPublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, nid *csi.NodeGetInfoResponse) *csi.ControllerPublishVolumeResponse {
233+
return controllerPublishVolumeWithCapability(volumeName, vol, nid, TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER))
234+
}
231235

232-
nodeStageVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodeStageVolumeResponse {
236+
nodeStageVolumeWithCapability := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse, cap *csi.VolumeCapability) *csi.NodeStageVolumeResponse {
233237
// NodeStageVolume
234238
if nodeStageSupported {
235239
By("node staging volume")
236240
nodeStageRequest := &csi.NodeStageVolumeRequest{
237241
VolumeId: vol.GetVolume().GetVolumeId(),
238-
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
242+
VolumeCapability: cap,
239243
StagingTargetPath: sc.StagingPath,
240244
VolumeContext: vol.GetVolume().GetVolumeContext(),
241245
Secrets: sc.Secrets.NodeStageVolumeSecret,
@@ -253,8 +257,11 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
253257
}
254258
return nil
255259
}
260+
nodeStageVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodeStageVolumeResponse {
261+
return nodeStageVolumeWithCapability(volumeName, vol, conpubvol, TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER))
262+
}
256263

257-
nodePublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodePublishVolumeResponse {
264+
nodePublishVolumeWithCapability := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse, cap *csi.VolumeCapability) *csi.NodePublishVolumeResponse {
258265
By("publishing the volume on a node")
259266
var stagingPath string
260267
if nodeStageSupported {
@@ -264,7 +271,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
264271
VolumeId: vol.GetVolume().GetVolumeId(),
265272
TargetPath: sc.TargetPath + "/target",
266273
StagingTargetPath: stagingPath,
267-
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
274+
VolumeCapability: cap,
268275
VolumeContext: vol.GetVolume().GetVolumeContext(),
269276
Secrets: sc.Secrets.NodePublishVolumeSecret,
270277
}
@@ -281,6 +288,9 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
281288
Expect(nodepubvol).NotTo(BeNil())
282289
return nodepubvol
283290
}
291+
nodePublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodePublishVolumeResponse {
292+
return nodePublishVolumeWithCapability(volumeName, vol, conpubvol, TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER))
293+
}
284294

285295
BeforeEach(func() {
286296
cl := csi.NewControllerClient(sc.ControllerConn)

0 commit comments

Comments
 (0)