Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller Publish/Unpublish cleanup #60

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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