Skip to content

Commit

Permalink
Assert NodePublishVolume behavior for single node single writer volumes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrishenzie committed Jan 5, 2023
1 parent 45cd08b commit 143bfa9
Showing 1 changed file with 60 additions and 6 deletions.
66 changes: 60 additions & 6 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
var (
r *Resources

providesControllerService bool
controllerPublishSupported bool
nodeStageSupported bool
nodeVolumeStatsSupported bool
nodeExpansionSupported bool
controllerExpansionSupported bool
providesControllerService bool
controllerPublishSupported bool
nodeStageSupported bool
nodeVolumeStatsSupported bool
nodeExpansionSupported bool
controllerExpansionSupported bool
singleNodeMultiWriterSupported bool
)

createVolumeWithCapability := func(volumeName string, cap *csi.VolumeCapability) *csi.CreateVolumeResponse {
Expand Down Expand Up @@ -319,6 +320,8 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
nodeVolumeStatsSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
nodeExpansionSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_EXPAND_VOLUME)
controllerExpansionSupported = isControllerCapabilitySupported(cl, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
singleNodeMultiWriterSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER)

r = &Resources{
Context: sc,
ControllerClient: cl,
Expand Down Expand Up @@ -431,6 +434,57 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument), "unexpected error: %s", serverError.Message())
})

Describe("with single node multi writer capability", func() {
BeforeEach(func() {
if !singleNodeMultiWriterSupported {
Skip("Service does not have single node multi writer capability")
}
})

It("should fail when volume with single node single writer access mode is already mounted at a different target path", func() {
By("creating a single node single writer volume")
name := UniqueString("sanity-node-publish-single-node-single-writer")
cap := TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER)
vol := createVolumeWithCapability(name, cap)

By("Getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

By("Staging and publishing a volume")
conpubvol := controllerPublishVolumeWithCapability(name, vol, nid, cap)
_ = nodeStageVolumeWithCapability(name, vol, conpubvol, cap)
_ = nodePublishVolumeWithCapability(name, vol, conpubvol, cap)

nodePublishRequest := &csi.NodePublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
TargetPath: sc.TargetPath + "/other_target",
VolumeCapability: cap,
VolumeContext: vol.GetVolume().GetVolumeContext(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
}
if conpubvol != nil {
nodePublishRequest.PublishContext = conpubvol.GetPublishContext()
}
if nodeStageSupported {
nodePublishRequest.StagingTargetPath = sc.StagingPath
}

_, err = r.NodePublishVolume(
context.Background(),
nodePublishRequest)
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.FailedPrecondition), "unexpected error: %s", serverError.Message())
})
})
})

Describe("NodeUnpublishVolume", func() {
Expand Down

0 comments on commit 143bfa9

Please sign in to comment.