mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-25 22:40:21 +00:00
util: return correct status code for VolumeGroupSnapshot
Fix status codes that are returned for Get/Delete RPC calls
for VolumeGroup/VolumeGroupSnapshot.
Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
(cherry picked from commit 18a62ec9de
)
This commit is contained in:
parent
09e298197e
commit
e7f5b8a28f
@ -61,6 +61,9 @@ var (
|
|||||||
|
|
||||||
// ErrQuiesceInProgress is returned when quiesce operation is in progress.
|
// ErrQuiesceInProgress is returned when quiesce operation is in progress.
|
||||||
ErrQuiesceInProgress = coreError.New("quiesce operation is in progress")
|
ErrQuiesceInProgress = coreError.New("quiesce operation is in progress")
|
||||||
|
|
||||||
|
// ErrGroupNotFound is returned when volume group snapshot is not found in the backend.
|
||||||
|
ErrGroupNotFound = coreError.New("volume group snapshot not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsCloneRetryError returns true if the clone error is pending,in-progress
|
// IsCloneRetryError returns true if the clone error is pending,in-progress
|
||||||
|
@ -721,12 +721,16 @@ func (cs *ControllerServer) DeleteVolumeGroupSnapshot(ctx context.Context,
|
|||||||
|
|
||||||
vgo, vgsi, err := store.NewVolumeGroupOptionsFromID(ctx, req.GetGroupSnapshotId(), cr)
|
vgo, vgsi, err := store.NewVolumeGroupOptionsFromID(ctx, req.GetGroupSnapshotId(), cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to get volume group options: %v", err)
|
if !errors.Is(err, cerrors.ErrGroupNotFound) {
|
||||||
err = extractDeleteVolumeGroupError(err)
|
log.ErrorLog(ctx, "failed to get volume group options: %v", err)
|
||||||
if err != nil {
|
err = extractDeleteVolumeGroupError(err)
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.ErrorLog(ctx, "VolumeGroupSnapshot %q doesn't exists", req.GetGroupSnapshotId())
|
||||||
|
|
||||||
return &csi.DeleteVolumeGroupSnapshotResponse{}, nil
|
return &csi.DeleteVolumeGroupSnapshotResponse{}, nil
|
||||||
}
|
}
|
||||||
vgo.Destroy()
|
vgo.Destroy()
|
||||||
|
@ -172,6 +172,12 @@ func NewVolumeGroupOptionsFromID(
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if groupAttributes.GroupName == "" {
|
||||||
|
log.ErrorLog(ctx, "volume group snapshot with id %v not found", volumeGroupSnapshotID)
|
||||||
|
|
||||||
|
return nil, nil, cerrors.ErrGroupNotFound
|
||||||
|
}
|
||||||
|
|
||||||
vgs.RequestName = groupAttributes.RequestName
|
vgs.RequestName = groupAttributes.RequestName
|
||||||
vgs.FsVolumeGroupSnapshotName = groupAttributes.GroupName
|
vgs.FsVolumeGroupSnapshotName = groupAttributes.GroupName
|
||||||
vgs.VolumeGroupSnapshotID = volumeGroupSnapshotID
|
vgs.VolumeGroupSnapshotID = volumeGroupSnapshotID
|
||||||
|
@ -195,7 +195,7 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup(
|
|||||||
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
||||||
log.DebugLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
|
log.ErrorLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
|
||||||
|
|
||||||
return &volumegroup.DeleteVolumeGroupResponse{}, nil
|
return &volumegroup.DeleteVolumeGroupResponse{}, nil
|
||||||
}
|
}
|
||||||
@ -433,9 +433,19 @@ func (vs *VolumeGroupServer) ControllerGetVolumeGroup(
|
|||||||
// resolve the volume group
|
// resolve the volume group
|
||||||
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
||||||
|
log.ErrorLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
|
||||||
|
|
||||||
|
return nil, status.Errorf(
|
||||||
|
codes.NotFound,
|
||||||
|
"could not find volume group %q: %s",
|
||||||
|
req.GetVolumeGroupId(),
|
||||||
|
err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return nil, status.Errorf(
|
return nil, status.Errorf(
|
||||||
codes.NotFound,
|
codes.Internal,
|
||||||
"could not find volume group %q: %s",
|
"could not fetch volume group %q: %s",
|
||||||
req.GetVolumeGroupId(),
|
req.GetVolumeGroupId(),
|
||||||
err.Error())
|
err.Error())
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package group
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
@ -69,6 +70,12 @@ func GetVolumeGroupSnapshot(
|
|||||||
|
|
||||||
attrs, err := vgs.getVolumeGroupAttributes(ctx)
|
attrs, err := vgs.getVolumeGroupAttributes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, ErrRBDGroupNotFound) {
|
||||||
|
log.ErrorLog(ctx, "%v, returning empty volume group snapshot %q", vgs, err)
|
||||||
|
|
||||||
|
return vgs, err
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("failed to get volume attributes for id %q: %w", vgs, err)
|
return nil, fmt.Errorf("failed to get volume attributes for id %q: %w", vgs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ func (cvg *commonVolumeGroup) getVolumeGroupAttributes(ctx context.Context) (*jo
|
|||||||
attrs = &journal.VolumeGroupAttributes{}
|
attrs = &journal.VolumeGroupAttributes{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if attrs.GroupName == "" || attrs.CreationTime == nil {
|
if attrs.GroupName == "" {
|
||||||
log.ErrorLog(ctx, "volume group with id %v not found", cvg.id)
|
log.ErrorLog(ctx, "volume group with id %v not found", cvg.id)
|
||||||
|
|
||||||
return nil, ErrRBDGroupNotFound
|
return nil, ErrRBDGroupNotFound
|
||||||
|
@ -77,7 +77,7 @@ func GetVolumeGroup(
|
|||||||
|
|
||||||
attrs, err := vg.getVolumeGroupAttributes(ctx)
|
attrs, err := vg.getVolumeGroupAttributes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, librbd.ErrNotFound) {
|
if errors.Is(err, ErrRBDGroupNotFound) {
|
||||||
log.ErrorLog(ctx, "%v, returning empty volume group %q", vg, err)
|
log.ErrorLog(ctx, "%v, returning empty volume group %q", vg, err)
|
||||||
|
|
||||||
return vg, err
|
return vg, err
|
||||||
|
@ -18,11 +18,13 @@ package rbd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
|
"github.com/ceph/ceph-csi/internal/rbd/group"
|
||||||
"github.com/ceph/ceph-csi/internal/rbd/types"
|
"github.com/ceph/ceph-csi/internal/rbd/types"
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
"github.com/ceph/ceph-csi/internal/util/log"
|
"github.com/ceph/ceph-csi/internal/util/log"
|
||||||
@ -213,10 +215,17 @@ func (cs *ControllerServer) DeleteVolumeGroupSnapshot(
|
|||||||
|
|
||||||
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
|
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
||||||
|
log.ErrorLog(ctx, "VolumeGroupSnapshot %q doesn't exists", groupSnapshotID)
|
||||||
|
|
||||||
|
return &csi.DeleteVolumeGroupSnapshotResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, status.Errorf(
|
return nil, status.Errorf(
|
||||||
codes.Internal,
|
codes.Internal,
|
||||||
"failed to get volume group snapshot with id %q: %v",
|
"could not fetch volume group snapshot with id %q: %s",
|
||||||
groupSnapshotID, err)
|
groupSnapshotID,
|
||||||
|
err.Error())
|
||||||
}
|
}
|
||||||
defer groupSnapshot.Destroy(ctx)
|
defer groupSnapshot.Destroy(ctx)
|
||||||
|
|
||||||
@ -252,10 +261,20 @@ func (cs *ControllerServer) GetVolumeGroupSnapshot(
|
|||||||
|
|
||||||
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
|
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
||||||
|
log.ErrorLog(ctx, "VolumeGroupSnapshot %q doesn't exists", groupSnapshotID)
|
||||||
|
|
||||||
|
return nil, status.Errorf(
|
||||||
|
codes.NotFound,
|
||||||
|
"failed to get volume group snapshot with id %q: %v",
|
||||||
|
groupSnapshotID, err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, status.Errorf(
|
return nil, status.Errorf(
|
||||||
codes.Internal,
|
codes.Internal,
|
||||||
"failed to get volume group snapshot with id %q: %v",
|
"could not fetch volume group snapshot with id %q: %s",
|
||||||
groupSnapshotID, err)
|
groupSnapshotID,
|
||||||
|
err.Error())
|
||||||
}
|
}
|
||||||
defer groupSnapshot.Destroy(ctx)
|
defer groupSnapshot.Destroy(ctx)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user