Skip to content

Commit

Permalink
[backend] Update - use AllowMissing
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
glimchb committed Jun 16, 2023
1 parent c8a51bd commit d0543ce
Showing 4 changed files with 63 additions and 12 deletions.
23 changes: 22 additions & 1 deletion pkg/backend/aio.go
Original file line number Diff line number Diff line change
@@ -142,7 +142,28 @@ func (s *Server) UpdateAioController(_ context.Context, in *pb.UpdateAioControll
volume, ok := s.Volumes.AioVolumes[in.AioController.Name]
if !ok {
if in.AllowMissing {
log.Printf("TODO: in case of AllowMissing, create a new resource, don;t return error")
log.Printf("Got AllowMissing, create a new resource, don't return error when resource not found")
params := spdk.BdevAioCreateParams{
Name: path.Base(in.AioController.Name),
BlockSize: 512,
Filename: in.AioController.Filename,
}
var result spdk.BdevAioCreateResult
err := s.rpc.Call("bdev_aio_create", &params, &result)
if err != nil {
log.Printf("error: %v", err)
return nil, err
}
log.Printf("Received from SPDK: %v", result)
if result == "" {
msg := fmt.Sprintf("Could not create Aio Dev: %s", params.Name)
log.Print(msg)
return nil, status.Errorf(codes.InvalidArgument, msg)
}
response := server.ProtoClone(in.AioController)
s.Volumes.AioVolumes[in.AioController.Name] = response
log.Printf("CreateAioController: Sending to client: %v", response)
return response, nil
}
err := status.Errorf(codes.NotFound, "unable to find key %s", in.AioController.Name)
log.Printf("error: %v", err)
15 changes: 10 additions & 5 deletions pkg/backend/aio_test.go
Original file line number Diff line number Diff line change
@@ -289,11 +289,16 @@ func TestBackEnd_UpdateAioController(t *testing.T) {
BlocksCount: 12,
Filename: "/tmp/aio_bdev_file",
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
&pb.AioController{
Name: server.ResourceIDToVolumeName("unknown-id"),
BlockSize: 512,
BlocksCount: 12,
Filename: "/tmp/aio_bdev_file",
},
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":"mytest"}`},
codes.OK,
"",
true,
true,
},
}
23 changes: 22 additions & 1 deletion pkg/backend/null.go
Original file line number Diff line number Diff line change
@@ -143,7 +143,28 @@ func (s *Server) UpdateNullDebug(_ context.Context, in *pb.UpdateNullDebugReques
volume, ok := s.Volumes.NullVolumes[in.NullDebug.Name]
if !ok {
if in.AllowMissing {
log.Printf("TODO: in case of AllowMissing, create a new resource, don;t return error")
log.Printf("Got AllowMissing, create a new resource, don't return error when resource not found")
params := spdk.BdevNullCreateParams{
Name: path.Base(in.NullDebug.Name),
BlockSize: 512,
NumBlocks: 64,
}
var result spdk.BdevNullCreateResult
err := s.rpc.Call("bdev_null_create", &params, &result)
if err != nil {
log.Printf("error: %v", err)
return nil, err
}
log.Printf("Received from SPDK: %v", result)
if result == "" {
msg := fmt.Sprintf("Could not create Null Dev: %s", params.Name)
log.Print(msg)
return nil, status.Errorf(codes.InvalidArgument, msg)
}
response := server.ProtoClone(in.NullDebug)
s.Volumes.NullVolumes[in.NullDebug.Name] = response
log.Printf("CreateNullDebug: Sending to client: %v", response)
return response, nil
}
err := status.Errorf(codes.NotFound, "unable to find key %s", in.NullDebug.Name)
log.Printf("error: %v", err)
14 changes: 9 additions & 5 deletions pkg/backend/null_test.go
Original file line number Diff line number Diff line change
@@ -286,11 +286,15 @@ func TestBackEnd_UpdateNullDebug(t *testing.T) {
BlockSize: 512,
BlocksCount: 64,
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
&pb.NullDebug{
Name: server.ResourceIDToVolumeName("unknown-id"),
BlockSize: 512,
BlocksCount: 64,
},
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":"mytest"}`},
codes.OK,
"",
true,
true,
},
}

0 comments on commit d0543ce

Please sign in to comment.