Skip to content

Commit 392225c

Browse files
authored
Merge pull request #60 from sbezverk/mock_driver_part_3
Controller Publish/Unpublish cleanup
2 parents d2bc801 + 0a72d73 commit 392225c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mock/service/controller.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ func (s *service) ControllerUnpublishVolume(
159159
req *csi.ControllerUnpublishVolumeRequest) (
160160
*csi.ControllerUnpublishVolumeResponse, error) {
161161

162+
if len(req.VolumeId) == 0 {
163+
return nil, status.Error(codes.InvalidArgument, "Volume ID cannot be empty")
164+
}
165+
nodeID := req.NodeId
166+
if len(nodeID) == 0 {
167+
// If node id is empty, no failure as per Spec
168+
nodeID = s.nodeID
169+
}
170+
171+
if req.NodeId != s.nodeID {
172+
return nil, status.Errorf(codes.NotFound, "Node ID %s does not match to expected Node ID %s", req.NodeId, s.nodeID)
173+
}
174+
162175
s.volsRWL.Lock()
163176
defer s.volsRWL.Unlock()
164177

@@ -170,7 +183,7 @@ func (s *service) ControllerUnpublishVolume(
170183
// devPathKey is the key in the volume's attributes that is set to a
171184
// mock device path if the volume has been published by the controller
172185
// to the specified node.
173-
devPathKey := path.Join(req.NodeId, "dev")
186+
devPathKey := path.Join(nodeID, "dev")
174187

175188
// Check to see if the volume is already unpublished.
176189
if v.Attributes[devPathKey] == "" {

pkg/sanity/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
729729

730730
serverError, ok := status.FromError(err)
731731
Expect(ok).To(BeTrue())
732-
Expect(serverError.Code()).To(Equal(codes.NotFound))
732+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
733733
})
734734

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

0 commit comments

Comments
 (0)