Skip to content

Commit 4ee7e7c

Browse files
committed
sanity: test FAILED_PRECONDITION on NodePublishVolume
According to the CSI spec, a `NodePublishVolume` RPC must return a `FAILED_PRECONDITION` error when invoked with no `staging_target_path` set, if `STAGE_UNSTAGE_VOLUME` is supported by the driver. This patch adds a test to assert this. See: https://github.com/container-storage-interface/spec/blob/87a27a2496565857ed564284eaa762587feb9453/spec.md#nodepublishvolume-errors
1 parent 396075f commit 4ee7e7c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

hack/_apitest2/api_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func TestMyDriverWithCustomTargetPaths(t *testing.T) {
1515
var createTargetDirCalls, createStagingDirCalls,
1616
removeTargetDirCalls, removeStagingDirCalls int
1717

18-
wantCreateTargetCalls := 4
19-
wantCreateStagingCalls := 4
20-
wantRemoveTargetCalls := 4
21-
wantRemoveStagingCalls := 4
18+
wantCreateTargetCalls := 5
19+
wantCreateStagingCalls := 5
20+
wantRemoveTargetCalls := 5
21+
wantRemoveStagingCalls := 5
2222

2323
// tmpPath could be a CO specific directory under which all the target dirs
2424
// are created. For k8s, it could be /var/lib/kubelet/pods under which the

mock/service/node.go

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func (s *service) NodePublishVolume(
140140
return nil, status.Error(codes.InvalidArgument, "Volume ID cannot be empty")
141141
}
142142

143+
if len(req.GetStagingTargetPath()) == 0 {
144+
return nil, status.Error(codes.FailedPrecondition, "StagingTarget Path cannot be empty")
145+
}
146+
143147
if len(req.GetTargetPath()) == 0 {
144148
return nil, status.Error(codes.InvalidArgument, "Target Path cannot be empty")
145149
}

pkg/sanity/node.go

+15
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
392392
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
393393
})
394394

395+
It("should fail when no staging target path is provided", func() {
396+
if !nodeStageSupported {
397+
Skip("STAGE_UNSTAGE_VOLUME not supported")
398+
}
399+
400+
req.StagingTargetPath = ""
401+
402+
_, err := c.NodePublishVolume(context.Background(), req)
403+
Expect(err).To(HaveOccurred())
404+
405+
serverError, ok := status.FromError(err)
406+
Expect(ok).To(BeTrue())
407+
Expect(serverError.Code()).To(Equal(codes.FailedPrecondition))
408+
})
409+
395410
It("should fail when no volume capability is provided", func() {
396411
req.VolumeCapability = nil
397412

0 commit comments

Comments
 (0)