From 4ab94a032a85653643f48881da495916515ead74 Mon Sep 17 00:00:00 2001 From: Serguei Bezverkhi Date: Tue, 13 Mar 2018 23:55:07 -0400 Subject: [PATCH] Controller Publish/Unpublish cleanup --- mock/service/controller.go | 15 ++++++++++++++- pkg/sanity/controller.go | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mock/service/controller.go b/mock/service/controller.go index e2d802d7..5923c168 100644 --- a/mock/service/controller.go +++ b/mock/service/controller.go @@ -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() @@ -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] == "" { diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index e6c6ad9b..2188a815 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -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() {