Skip to content

Commit

Permalink
Merge pull request ceph#372 from Madhu-1/fix-err
Browse files Browse the repository at this point in the history
Fix error string as per golang standard
  • Loading branch information
humblec authored Jun 10, 2019
2 parents af7a6e9 + 2838148 commit 43da740
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pkg/cephfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func (cs *ControllerServer) validateCreateVolumeRequest(req *csi.CreateVolumeReq
}

if req.GetName() == "" {
return status.Error(codes.InvalidArgument, "Volume Name cannot be empty")
return status.Error(codes.InvalidArgument, "volume Name cannot be empty")
}

reqCaps := req.GetVolumeCapabilities()
if reqCaps == nil {
return status.Error(codes.InvalidArgument, "Volume Capabilities cannot be empty")
return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty")
}

for _, cap := range reqCaps {
Expand Down
28 changes: 14 additions & 14 deletions pkg/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func (cs *ControllerServer) validateVolumeReq(req *csi.CreateVolumeRequest) erro
}
// Check sanity of request Name, Volume Capabilities
if len(req.Name) == 0 {
return status.Error(codes.InvalidArgument, "Volume Name cannot be empty")
return status.Error(codes.InvalidArgument, "volume Name cannot be empty")
}
if req.VolumeCapabilities == nil {
return status.Error(codes.InvalidArgument, "Volume Capabilities cannot be empty")
return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty")
}
options := req.GetParameters()
if value, ok := options["clusterID"]; !ok || len(value) == 0 {
return status.Error(codes.InvalidArgument, "Missing or empty cluster ID to provision volume from")
return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from")
}
if value, ok := options["pool"]; !ok || len(value) == 0 {
return status.Error(codes.InvalidArgument, "Missing or empty pool name to provision volume from")
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
}
return nil
}
Expand Down Expand Up @@ -190,20 +190,20 @@ func (cs *ControllerServer) createBackingImage(rbdVol *rbdVolume, req *csi.Creat
func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) error {
snapshot := req.VolumeContentSource.GetSnapshot()
if snapshot == nil {
return status.Error(codes.InvalidArgument, "Volume Snapshot cannot be empty")
return status.Error(codes.InvalidArgument, "volume Snapshot cannot be empty")
}

snapshotID := snapshot.GetSnapshotId()
if len(snapshotID) == 0 {
return status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty")
return status.Error(codes.InvalidArgument, "volume Snapshot ID cannot be empty")
}

rbdSnap := &rbdSnapshot{}
if err := genSnapFromSnapID(rbdSnap, snapshotID, req.GetSecrets()); err != nil {
if _, ok := err.(ErrSnapNotFound); !ok {
return status.Error(codes.Internal, err.Error())
}
return status.Error(codes.InvalidArgument, "Missing requested Snapshot ID")
return status.Error(codes.InvalidArgument, "missing requested Snapshot ID")
}

err := restoreSnapshot(rbdVol, rbdSnap, rbdVol.AdminID, req.GetSecrets())
Expand All @@ -224,7 +224,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
// For now the image get unconditionally deleted, but here retention policy can be checked
volumeID := req.GetVolumeId()
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request")
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
volumeIDMutex.LockKey(volumeID)
defer func() {
Expand Down Expand Up @@ -287,11 +287,11 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
// are supported.
func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
if req.GetVolumeId() == "" {
return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request")
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}

if len(req.VolumeCapabilities) == 0 {
return nil, status.Error(codes.InvalidArgument, "Empty volume capabilities in request")
return nil, status.Error(codes.InvalidArgument, "empty volume capabilities in request")
}

for _, cap := range req.VolumeCapabilities {
Expand Down Expand Up @@ -326,7 +326,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
err := genVolFromVolID(rbdVol, req.GetSourceVolumeId(), req.GetSecrets())
if err != nil {
if _, ok := err.(ErrImageNotFound); ok {
return nil, status.Errorf(codes.NotFound, "Source Volume ID %s not found", req.GetSourceVolumeId())
return nil, status.Errorf(codes.NotFound, "source Volume ID %s not found", req.GetSourceVolumeId())
}
return nil, status.Errorf(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -402,10 +402,10 @@ func (cs *ControllerServer) validateSnapshotReq(req *csi.CreateSnapshotRequest)

// Check sanity of request Snapshot Name, Source Volume Id
if len(req.Name) == 0 {
return status.Error(codes.InvalidArgument, "Snapshot Name cannot be empty")
return status.Error(codes.InvalidArgument, "snapshot Name cannot be empty")
}
if len(req.SourceVolumeId) == 0 {
return status.Error(codes.InvalidArgument, "Source Volume ID cannot be empty")
return status.Error(codes.InvalidArgument, "source Volume ID cannot be empty")
}

return nil
Expand Down Expand Up @@ -467,7 +467,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS

snapshotID := req.GetSnapshotId()
if len(snapshotID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Snapshot ID cannot be empty")
return nil, status.Error(codes.InvalidArgument, "snapshot ID cannot be empty")
}

snapshotIDMutex.LockKey(snapshotID)
Expand Down
14 changes: 7 additions & 7 deletions pkg/rbd/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"regexp"
"strings"

"github.com/ceph/ceph-csi/pkg/csi-common"
csicommon "github.com/ceph/ceph-csi/pkg/csi-common"
"github.com/ceph/ceph-csi/pkg/util"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand All @@ -46,15 +46,15 @@ type NodeServer struct {
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
if targetPath == "" {
return nil, status.Error(codes.InvalidArgument, "Empty target path in request")
return nil, status.Error(codes.InvalidArgument, "empty target path in request")
}

if req.GetVolumeCapability() == nil {
return nil, status.Error(codes.InvalidArgument, "Empty volume capability in request")
return nil, status.Error(codes.InvalidArgument, "empty volume capability in request")
}

if req.GetVolumeId() == "" {
return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request")
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}

targetPathMutex.LockKey(targetPath)
Expand Down Expand Up @@ -190,11 +190,11 @@ func (ns *NodeServer) createTargetPath(targetPath string, isBlock bool) (bool, e
func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
if targetPath == "" {
return nil, status.Error(codes.InvalidArgument, "Empty target path in request")
return nil, status.Error(codes.InvalidArgument, "empty target path in request")
}

if req.GetVolumeId() == "" {
return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request")
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}

targetPathMutex.LockKey(targetPath)
Expand All @@ -217,7 +217,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
if notMnt {
// TODO should consider deleting path instead of returning error,
// once all codes become ready for csi 1.0.
return nil, status.Error(codes.NotFound, "Volume not mounted")
return nil, status.Error(codes.NotFound, "volume not mounted")
}

devicePath, cnt, err := mount.GetDeviceNameFromMount(ns.mounter, targetPath)
Expand Down
7 changes: 4 additions & 3 deletions pkg/util/cephcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"k8s.io/klog"
"os"
"os/exec"
"strings"

"k8s.io/klog"
)

// ExecCommand executes passed in program with args and returns seperate stdout and stderr streams
// ExecCommand executes passed in program with args and returns separate stdout and stderr streams
func ExecCommand(program string, args ...string) (stdout, stderr []byte, err error) {
var (
cmd = exec.Command(program, args...) // nolint: gosec
Expand Down Expand Up @@ -191,7 +192,7 @@ func GetOMapValue(monitors, adminID, key, poolName, namespace, oMapName, oMapKey
klog.Errorf("failed getting omap value for key (%s) from omap (%s) in pool (%s): (%v)",
oMapKey, oMapName, poolName, err)

return "", fmt.Errorf("error (%v) occured, command output streams is (%s)",
return "", fmt.Errorf("error (%v) occurred, command output streams is (%s)",
err.Error(), stdoutanderr)
}

Expand Down

0 comments on commit 43da740

Please sign in to comment.