Should fail when the volume source snapshot is not found
Fix CSI sanity test failure.
@@ -95,6 +95,9 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
case *csi.VolumeContentSource_Snapshot:
if snapshot := volumeSource.GetSnapshot(); snapshot != nil {
csiSnapshotType, sourceVolumeName, id := decodeSnapshotID(snapshot.SnapshotId)
+ if id == "" {
+ return nil, status.Errorf(codes.NotFound, "volume source snapshot %v is not found", snapshot.SnapshotId)
+ }
if csiSnapshotType == csiSnapshotTypeLonghornSnapshot {
dataSource, _ := types.NewVolumeDataSource(longhorn.VolumeDataSourceTypeSnapshot, map[string]string{types.VolumeNameKey: sourceVolumeName, types.SnapshotNameKey: id})
volumeParameters["dataSource"] = string(dataSource)
@@ -750,12 +753,12 @@ func encodeSnapshotID(csiSnapshotType, sourceVolumeName, id string) string {
func decodeSnapshotID(snapshotID string) (csiSnapshotType, sourceVolumeName, id string) {
split := strings.Split(snapshotID, "://")
if len(split) < 2 {
- return "", "", snapshotID
+ return "", "", ""
}
csiSnapshotType = split[0]
split = strings.Split(split[1], "/")
if len(split) < 2 {
- return "", "", snapshotID
+ return "", "", ""
}
sourceVolumeName = split[0]
id = split[1]
@@ -777,6 +780,9 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
}
csiSnapshotType, sourceVolumeName, id := decodeSnapshotID(snapshotID)
+ if id == "" {
+ return nil, status.Errorf(codes.NotFound, "volume source snapshot %v is not found", snapshotID)
+ }
if csiSnapshotType == csiSnapshotTypeLonghornSnapshot {
volume, err := cs.apiClient.Volume.ById(sourceVolumeName)
if err != nil {
