Fix csi sanity check - ControllerPublishVolume
* Check request at start of function to ensure correct
err code is returned.
```
Expected
<codes.Code>: 5
to equal
<codes.Code>: 3
```
@@ -282,19 +282,18 @@ func (cs *ControllerServer) isNodeReady(nodeID string) bool {
// ControllerPublishVolume will attach the volume to the specified node
func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
logrus.Infof("ControllerServer ControllerPublishVolume req: %v", req)
- existVol, err := cs.apiClient.Volume.ById(req.GetVolumeId())
- if err != nil {
- return nil, status.Error(codes.Internal, err.Error())
- }
- if existVol == nil {
- msg := fmt.Sprintf("ControllerPublishVolume: the volume %s not exists", req.GetVolumeId())
+
+ if req.GetNodeId() == "" {
+ msg := "ControllerPublishVolume: missing node id in request"
logrus.Warn(msg)
- return nil, status.Error(codes.NotFound, msg)
+ return nil, status.Error(codes.InvalidArgument, msg)
}
volumeCapability := req.GetVolumeCapability()
if volumeCapability == nil {
- return nil, status.Error(codes.InvalidArgument, "Volume capability not provided")
+ msg := fmt.Sprint("ControllerPublishVolume: missing volume capability in request")
+ logrus.Warn(msg)
+ return nil, status.Error(codes.InvalidArgument, msg)
}
if !cs.isNodeReady(req.GetNodeId()) {
@@ -304,6 +303,16 @@ func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *cs
return nil, status.Error(codes.NotFound, msg)
}
+ existVol, err := cs.apiClient.Volume.ById(req.GetVolumeId())
+ if err != nil {
+ return nil, status.Error(codes.Internal, err.Error())
+ }
+ if existVol == nil {
+ msg := fmt.Sprintf("ControllerPublishVolume: the volume %s not exists", req.GetVolumeId())
+ logrus.Warn(msg)
+ return nil, status.Error(codes.NotFound, msg)
+ }
+
if existVol.RestoreRequired {
return nil, status.Errorf(codes.Aborted, "The volume %s is restoring backup", req.GetVolumeId())
}
