Skip to content

Commit d8a638b

Browse files
committed
Fixes for drivers with STAGE_UNSTAGE_VOLUME capability
1 parent 2099dcb commit d8a638b

File tree

5 files changed

+73
-124
lines changed

5 files changed

+73
-124
lines changed

cmd/csi-sanity/sanity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ func TestSanity(t *testing.T) {
5050
if len(endpoint) == 0 {
5151
t.Fatalf("--%sendpoint must be provided with an CSI endpoint", prefix)
5252
}
53-
sanity.Test(t, endpoint, mountPoint)
53+
sanity.Test(t, endpoint, mountPoint, "")
5454
}

mock/service/controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func (s *service) ControllerUnpublishVolume(
156156
s.volsRWL.Lock()
157157
defer s.volsRWL.Unlock()
158158

159+
if len(req.GetVolumeId()) == 0 {
160+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Expected a volume ID, got none"))
161+
}
162+
159163
i, v := s.findVolNoLock("id", req.VolumeId)
160164
if i < 0 {
161165
return nil, status.Error(codes.NotFound, req.VolumeId)

pkg/sanity/controller.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func verifyVolumeInfo(v *csi.Volume) {
3434
Expect(v.GetId()).NotTo(BeEmpty())
3535
}
3636

37-
func isCapabilitySupported(
37+
func isControllerCapabilitySupported(
3838
c csi.ControllerClient,
3939
capType csi.ControllerServiceCapability_RPC_Type,
4040
) bool {
@@ -97,7 +97,7 @@ var _ = Describe("GetCapacity [Controller Server]", func() {
9797
BeforeEach(func() {
9898
c = csi.NewControllerClient(conn)
9999

100-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_GET_CAPACITY) {
100+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_GET_CAPACITY) {
101101
Skip("GetCapacity not supported")
102102
}
103103
})
@@ -121,7 +121,7 @@ var _ = Describe("ListVolumes [Controller Server]", func() {
121121
BeforeEach(func() {
122122
c = csi.NewControllerClient(conn)
123123

124-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_VOLUMES) {
124+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_VOLUMES) {
125125
Skip("ListVolumes not supported")
126126
}
127127
})
@@ -152,7 +152,7 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
152152
BeforeEach(func() {
153153
c = csi.NewControllerClient(conn)
154154

155-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) {
155+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) {
156156
Skip("CreateVolume not supported")
157157
}
158158
})
@@ -217,11 +217,11 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
217217
})
218218

219219
// Pending fix in mock file
220-
It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() {
220+
It("should return appropriate values SingleNodeWriter WithCapacity 10Gi Type:Mount", func() {
221221

222222
By("creating a volume")
223223
name := "sanity"
224-
size := int64(1 * 1024 * 1024 * 1024)
224+
size := int64(10 * 1024 * 1024 * 1024)
225225
vol, err := c.CreateVolume(
226226
context.Background(),
227227
&csi.CreateVolumeRequest{
@@ -264,7 +264,7 @@ var _ = Describe("DeleteVolume [Controller Server]", func() {
264264
BeforeEach(func() {
265265
c = csi.NewControllerClient(conn)
266266

267-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) {
267+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) {
268268
Skip("DeleteVolume not supported")
269269
}
270270
})
@@ -430,7 +430,7 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
430430
c = csi.NewControllerClient(conn)
431431
n = csi.NewNodeClient(conn)
432432

433-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
433+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
434434
Skip("ControllerPublishVolume not supported")
435435
}
436436
})
@@ -560,7 +560,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
560560
c = csi.NewControllerClient(conn)
561561
n = csi.NewNodeClient(conn)
562562

563-
if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
563+
if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
564564
Skip("ControllerUnpublishVolume not supported")
565565
}
566566
})
@@ -574,7 +574,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
574574

575575
serverError, ok := status.FromError(err)
576576
Expect(ok).To(BeTrue())
577-
Expect(serverError.Code()).To(Equal(codes.NotFound))
577+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
578578
})
579579

580580
It("should return appropriate values (no optional values added)", func() {

pkg/sanity/node.go

+51-108
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ import (
2929
. "github.com/onsi/gomega"
3030
)
3131

32+
func isNodeCapabilitySupported(c csi.NodeClient,
33+
capType csi.NodeServiceCapability_RPC_Type,
34+
) bool {
35+
36+
caps, err := c.NodeGetCapabilities(
37+
context.Background(),
38+
&csi.NodeGetCapabilitiesRequest{})
39+
Expect(err).NotTo(HaveOccurred())
40+
Expect(caps).NotTo(BeNil())
41+
Expect(caps.GetCapabilities()).NotTo(BeNil())
42+
43+
for _, cap := range caps.GetCapabilities() {
44+
Expect(cap.GetRpc()).NotTo(BeNil())
45+
if cap.GetRpc().GetType() == capType {
46+
return true
47+
}
48+
}
49+
return false
50+
}
51+
3252
var _ = Describe("NodeGetCapabilities [Node Server]", func() {
3353
var (
3454
c csi.NodeClient
@@ -53,6 +73,7 @@ var _ = Describe("NodeGetCapabilities [Node Server]", func() {
5373

5474
switch cap.GetRpc().GetType() {
5575
case csi.NodeServiceCapability_RPC_UNKNOWN:
76+
case csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME:
5677
default:
5778
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType()))
5879
}
@@ -85,14 +106,16 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
85106
s csi.ControllerClient
86107
c csi.NodeClient
87108
controllerPublishSupported bool
109+
nodeStageSupported bool
88110
)
89111

90112
BeforeEach(func() {
91113
s = csi.NewControllerClient(conn)
92114
c = csi.NewNodeClient(conn)
93-
controllerPublishSupported = isCapabilitySupported(
115+
controllerPublishSupported = isControllerCapabilitySupported(
94116
s,
95117
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
118+
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
96119
})
97120

98121
It("should fail when no volume id is provided", func() {
@@ -189,6 +212,29 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
189212
Expect(err).NotTo(HaveOccurred())
190213
Expect(conpubvol).NotTo(BeNil())
191214
}
215+
// NodeStageVolume
216+
if nodeStageSupported {
217+
By("node staging volume")
218+
nodeStageVolReq := &csi.NodeStageVolumeRequest{
219+
VolumeId: vol.GetVolume().GetId(),
220+
VolumeCapability: &csi.VolumeCapability{
221+
AccessType: &csi.VolumeCapability_Mount{
222+
Mount: &csi.VolumeCapability_MountVolume{},
223+
},
224+
AccessMode: &csi.VolumeCapability_AccessMode{
225+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
226+
},
227+
},
228+
StagingTargetPath: stagingTargetPath,
229+
}
230+
if controllerPublishSupported {
231+
nodeStageVolReq.PublishInfo = conpubvol.GetPublishInfo()
232+
}
233+
nodestagevol, err := c.NodeStageVolume(
234+
context.Background(), nodeStageVolReq)
235+
Expect(err).NotTo(HaveOccurred())
236+
Expect(nodestagevol).NotTo(BeNil())
237+
}
192238
// NodePublishVolume
193239
By("publishing the volume on a node")
194240
nodepubvolRequest := &csi.NodePublishVolumeRequest{
@@ -203,6 +249,9 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
203249
},
204250
},
205251
}
252+
if nodeStageSupported {
253+
nodepubvolRequest.StagingTargetPath = stagingTargetPath
254+
}
206255
if controllerPublishSupported {
207256
nodepubvolRequest.PublishInfo = conpubvol.GetPublishInfo()
208257
}
@@ -245,17 +294,11 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
245294

246295
var _ = Describe("NodeUnpublishVolume [Node Server]", func() {
247296
var (
248-
s csi.ControllerClient
249-
c csi.NodeClient
250-
controllerPublishSupported bool
297+
c csi.NodeClient
251298
)
252299

253300
BeforeEach(func() {
254-
s = csi.NewControllerClient(conn)
255301
c = csi.NewNodeClient(conn)
256-
controllerPublishSupported = isCapabilitySupported(
257-
s,
258-
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
259302
})
260303

261304
It("should fail when no volume id is provided", func() {
@@ -283,106 +326,6 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() {
283326
Expect(ok).To(BeTrue())
284327
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
285328
})
286-
287-
It("should return appropriate values (no optional values added)", func() {
288-
289-
// Create Volume First
290-
By("creating a single node writer volume")
291-
name := "sanity"
292-
vol, err := s.CreateVolume(
293-
context.Background(),
294-
&csi.CreateVolumeRequest{
295-
Name: name,
296-
VolumeCapabilities: []*csi.VolumeCapability{
297-
{
298-
AccessType: &csi.VolumeCapability_Mount{
299-
Mount: &csi.VolumeCapability_MountVolume{},
300-
},
301-
AccessMode: &csi.VolumeCapability_AccessMode{
302-
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
303-
},
304-
},
305-
},
306-
})
307-
Expect(err).NotTo(HaveOccurred())
308-
Expect(vol).NotTo(BeNil())
309-
Expect(vol.GetVolume()).NotTo(BeNil())
310-
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())
311-
312-
// ControllerPublishVolume
313-
var conpubvol *csi.ControllerPublishVolumeResponse
314-
if controllerPublishSupported {
315-
By("calling controllerpublish on the volume")
316-
conpubvol, err = s.ControllerPublishVolume(
317-
context.Background(),
318-
&csi.ControllerPublishVolumeRequest{
319-
VolumeId: vol.GetVolume().GetId(),
320-
NodeId: "io.kubernetes.storage.mock",
321-
VolumeCapability: &csi.VolumeCapability{
322-
AccessType: &csi.VolumeCapability_Mount{
323-
Mount: &csi.VolumeCapability_MountVolume{},
324-
},
325-
AccessMode: &csi.VolumeCapability_AccessMode{
326-
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
327-
},
328-
},
329-
Readonly: false,
330-
})
331-
Expect(err).NotTo(HaveOccurred())
332-
Expect(conpubvol).NotTo(BeNil())
333-
}
334-
335-
// NodePublishVolume
336-
By("publishing the volume on a node")
337-
nodepubvolRequest := &csi.NodePublishVolumeRequest{
338-
VolumeId: vol.GetVolume().GetId(),
339-
TargetPath: csiTargetPath,
340-
VolumeCapability: &csi.VolumeCapability{
341-
AccessType: &csi.VolumeCapability_Mount{
342-
Mount: &csi.VolumeCapability_MountVolume{},
343-
},
344-
AccessMode: &csi.VolumeCapability_AccessMode{
345-
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
346-
},
347-
},
348-
}
349-
if controllerPublishSupported {
350-
nodepubvolRequest.PublishInfo = conpubvol.GetPublishInfo()
351-
}
352-
nodepubvol, err := c.NodePublishVolume(context.Background(), nodepubvolRequest)
353-
Expect(err).NotTo(HaveOccurred())
354-
Expect(nodepubvol).NotTo(BeNil())
355-
356-
// NodeUnpublishVolume
357-
nodeunpubvol, err := c.NodeUnpublishVolume(
358-
context.Background(),
359-
&csi.NodeUnpublishVolumeRequest{
360-
VolumeId: vol.GetVolume().GetId(),
361-
TargetPath: csiTargetPath,
362-
})
363-
Expect(err).NotTo(HaveOccurred())
364-
Expect(nodeunpubvol).NotTo(BeNil())
365-
366-
if controllerPublishSupported {
367-
By("cleaning up unpublishing the volume")
368-
nodeunpubvol, err := c.NodeUnpublishVolume(
369-
context.Background(),
370-
&csi.NodeUnpublishVolumeRequest{
371-
VolumeId: vol.GetVolume().GetId(),
372-
TargetPath: csiTargetPath,
373-
})
374-
Expect(err).NotTo(HaveOccurred())
375-
Expect(nodeunpubvol).NotTo(BeNil())
376-
}
377-
378-
By("cleaning up deleting the volume")
379-
_, err = s.DeleteVolume(
380-
context.Background(),
381-
&csi.DeleteVolumeRequest{
382-
VolumeId: vol.GetVolume().GetId(),
383-
})
384-
Expect(err).NotTo(HaveOccurred())
385-
})
386329
})
387330

388331
// TODO: Tests for NodeStageVolume/NodeUnstageVolume

pkg/sanity/sanity.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,21 @@ import (
3131
)
3232

3333
var (
34-
driverAddress string
35-
csiTargetPath string
36-
conn *grpc.ClientConn
37-
lock sync.Mutex
34+
driverAddress string
35+
csiTargetPath string
36+
stagingTargetPath string
37+
conn *grpc.ClientConn
38+
lock sync.Mutex
3839
)
3940

4041
// Test will test the CSI driver at the specified address
41-
func Test(t *testing.T, address, mountPoint string) {
42+
func Test(t *testing.T, address, mountPoint, stagePoint string) {
4243
lock.Lock()
4344
defer lock.Unlock()
4445

4546
driverAddress = address
4647
csiTargetPath = mountPoint
48+
stagingTargetPath = stagePoint
4749
RegisterFailHandler(Fail)
4850
RunSpecs(t, "CSI Driver Test Suite")
4951
}

0 commit comments

Comments
 (0)