Skip to content

Commit

Permalink
Cloud Restores to avoid InternalErr for ErrExists (libopenstorage#1192)…
Browse files Browse the repository at this point in the history
… (libopenstorage#1197)

Signed-off-by: veda <[email protected]>
  • Loading branch information
talakad authored Aug 15, 2019
1 parent 89493a2 commit ef18633
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/server/sdk/cloud_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (s *CloudBackupServer) Restore(
Name: req.GetTaskId(),
})
if err != nil {
if err == volume.ErrExist {
return nil, status.Errorf(codes.AlreadyExists, "Restore task with this name already exists: %v", err)
}
return nil, status.Errorf(codes.Internal, "Failed to restore backup: %v", err)
}

Expand Down
39 changes: 39 additions & 0 deletions api/server/sdk/cloud_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/golang/protobuf/ptypes"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/volume"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -208,6 +209,44 @@ func TestSdkCloudRestoreCreate(t *testing.T) {
assert.NoError(t, err)
}

func TestSdkCloudRestoreCreateErrorCheck(t *testing.T) {

// Create server and client connection
s := newTestServer(t)
defer s.Stop()

backupid := "backupid"
taskId := "restore-task"
uuid := "uuid"
req := &api.SdkCloudBackupRestoreRequest{
BackupId: backupid,
CredentialId: uuid,
TaskId: taskId,
}

// Create response
s.MockDriver().
EXPECT().
CloudBackupRestore(&api.CloudBackupRestoreRequest{
ID: backupid,
CredentialUUID: uuid,
Name: taskId,
}).
Return(nil, volume.ErrExist).
Times(1)
setupExpectedCredentialsPassing(s, uuid)

// Setup client
c := api.NewOpenStorageCloudBackupClient(s.Conn())

// Get info
_, err := c.Restore(context.Background(), req)
serverError, ok := status.FromError(err)
assert.True(t, ok)
assert.Equal(t, serverError.Code(), codes.AlreadyExists)
assert.Contains(t, serverError.Message(), "Restore task with this name already exists")
}

func TestSdkCloudBackupRestoreBadArguments(t *testing.T) {

// Create server and client connection
Expand Down

0 comments on commit ef18633

Please sign in to comment.