Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#60 from sbezverk/mock_driver_part_3
Browse files Browse the repository at this point in the history
Controller Publish/Unpublish cleanup
  • Loading branch information
lpabon authored Mar 15, 2018
2 parents 17560b6 + 4ab94a0 commit d5c4a75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion mock/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ func (s *service) ControllerUnpublishVolume(
req *csi.ControllerUnpublishVolumeRequest) (
*csi.ControllerUnpublishVolumeResponse, error) {

if len(req.VolumeId) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID cannot be empty")
}
nodeID := req.NodeId
if len(nodeID) == 0 {
// If node id is empty, no failure as per Spec
nodeID = s.nodeID
}

if req.NodeId != s.nodeID {
return nil, status.Errorf(codes.NotFound, "Node ID %s does not match to expected Node ID %s", req.NodeId, s.nodeID)
}

s.volsRWL.Lock()
defer s.volsRWL.Unlock()

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

// Check to see if the volume is already unpublished.
if v.Attributes[devPathKey] == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.NotFound))
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

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

0 comments on commit d5c4a75

Please sign in to comment.