Skip to content

Commit 1f0125d

Browse files
committed
Assert NodePublishVolume behavior for single node single writer volumes
Ensure that a single node single writer volume cannot be mounted at two different target paths on the same node. See the second table in the NodePublishVolume section of the CSI spec for more details: https://github.com/container-storage-interface/spec/blob/v1.7.0/spec.md#nodepublishvolume
1 parent 45cd08b commit 1f0125d

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

pkg/sanity/node.go

+58-6
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
183183
var (
184184
r *Resources
185185

186-
providesControllerService bool
187-
controllerPublishSupported bool
188-
nodeStageSupported bool
189-
nodeVolumeStatsSupported bool
190-
nodeExpansionSupported bool
191-
controllerExpansionSupported bool
186+
providesControllerService bool
187+
controllerPublishSupported bool
188+
nodeStageSupported bool
189+
nodeVolumeStatsSupported bool
190+
nodeExpansionSupported bool
191+
controllerExpansionSupported bool
192+
singleNodeMultiWriterSupported bool
192193
)
193194

194195
createVolumeWithCapability := func(volumeName string, cap *csi.VolumeCapability) *csi.CreateVolumeResponse {
@@ -319,6 +320,8 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
319320
nodeVolumeStatsSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
320321
nodeExpansionSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_EXPAND_VOLUME)
321322
controllerExpansionSupported = isControllerCapabilitySupported(cl, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
323+
singleNodeMultiWriterSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER)
324+
322325
r = &Resources{
323326
Context: sc,
324327
ControllerClient: cl,
@@ -431,6 +434,55 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
431434
Expect(ok).To(BeTrue())
432435
Expect(serverError.Code()).To(Equal(codes.InvalidArgument), "unexpected error: %s", serverError.Message())
433436
})
437+
438+
Describe("with single node multi writer capability", func() {
439+
BeforeEach(func() {
440+
if !singleNodeMultiWriterSupported {
441+
Skip("Service does not have single node multi writer capability")
442+
}
443+
})
444+
445+
It("should fail when volume with single node single writer access mode is already mounted at a different target path", func() {
446+
By("creating a single node single writer volume")
447+
name := UniqueString("sanity-node-publish-single-node-single-writer")
448+
cap := TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER)
449+
vol := createVolumeWithCapability(name, cap)
450+
451+
By("Getting a node id")
452+
nid, err := r.NodeGetInfo(
453+
context.Background(),
454+
&csi.NodeGetInfoRequest{})
455+
Expect(err).NotTo(HaveOccurred())
456+
Expect(nid).NotTo(BeNil())
457+
Expect(nid.GetNodeId()).NotTo(BeEmpty())
458+
459+
By("Staging and publishing a volume")
460+
conpubvol := controllerPublishVolumeWithCapability(name, vol, nid, cap)
461+
_ = nodeStageVolumeWithCapability(name, vol, conpubvol, cap)
462+
_ = nodePublishVolumeWithCapability(name, vol, conpubvol, cap)
463+
464+
var stagingPath string
465+
if nodeStageSupported {
466+
stagingPath = sc.StagingPath
467+
}
468+
_, err = r.NodePublishVolume(
469+
context.Background(),
470+
&csi.NodePublishVolumeRequest{
471+
VolumeId: vol.GetVolume().GetVolumeId(),
472+
TargetPath: sc.TargetPath + "/other_target",
473+
StagingTargetPath: stagingPath,
474+
VolumeCapability: cap,
475+
VolumeContext: vol.GetVolume().GetVolumeContext(),
476+
Secrets: sc.Secrets.NodePublishVolumeSecret,
477+
},
478+
)
479+
Expect(err).To(HaveOccurred())
480+
481+
serverError, ok := status.FromError(err)
482+
Expect(ok).To(BeTrue())
483+
Expect(serverError.Code()).To(Equal(codes.FailedPrecondition), "unexpected error: %s", serverError.Message())
484+
})
485+
})
434486
})
435487

436488
Describe("NodeUnpublishVolume", func() {

0 commit comments

Comments
 (0)