Skip to content

Commit

Permalink
Replace opi-spdk-bridge/pkg/server -> gospdk/spdk
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Apr 24, 2023
1 parent 70fa09d commit c8bc75d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"log"
"net"

"github.com/opiproject/gospdk/spdk"
fe "github.com/opiproject/opi-intel-bridge/pkg/frontend"
me "github.com/opiproject/opi-intel-bridge/pkg/middleend"
"github.com/opiproject/opi-smbios-bridge/pkg/inventory"
"github.com/opiproject/opi-spdk-bridge/pkg/backend"
"github.com/opiproject/opi-spdk-bridge/pkg/frontend"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
"github.com/opiproject/opi-strongswan-bridge/pkg/ipsec"

pc "github.com/opiproject/opi-api/common/v1/gen/go"
Expand All @@ -41,7 +41,7 @@ func main() {

s := grpc.NewServer()

jsonRPC := server.NewSpdkJSONRPC(spdkAddress)
jsonRPC := spdk.NewSpdkJSONRPC(spdkAddress)
frontendOpiIntelServer := fe.NewServer(jsonRPC)
frontendOpiSpdkServer := frontend.NewServer(jsonRPC)
backendOpiSpdkServer := backend.NewServer(jsonRPC)
Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package frontend

import (
"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/frontend"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
)

// Server contains frontend related OPI services
Expand All @@ -17,7 +17,7 @@ type Server struct {
}

// NewServer creates initialized instance of NVMe server
func NewServer(jsonRPC server.JSONRPC) *Server {
func NewServer(jsonRPC spdk.JSONRPC) *Server {
opiSpdkServer := frontend.NewServerWithSubsystemListener(jsonRPC, NewSubsystemListener())
return &Server{
opiSpdkServer,
Expand Down
6 changes: 3 additions & 3 deletions pkg/frontend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package frontend
import (
"strconv"

"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/frontend"
"github.com/opiproject/opi-spdk-bridge/pkg/models"
)

type npiSubsystemListener struct {
Expand All @@ -20,8 +20,8 @@ func NewSubsystemListener() frontend.SubsystemListener {
return npiSubsystemListener{}
}

func (c npiSubsystemListener) Params(ctrlr *pb.NVMeController, nqn string) models.NvmfSubsystemAddListenerParams {
result := models.NvmfSubsystemAddListenerParams{}
func (c npiSubsystemListener) Params(ctrlr *pb.NVMeController, nqn string) spdk.NvmfSubsystemAddListenerParams {
result := spdk.NvmfSubsystemAddListenerParams{}
result.Nqn = nqn
result.ListenAddress.Trtype = "npi"
result.ListenAddress.Traddr = calculateTransportAddr(ctrlr.Spec.PcieId)
Expand Down
34 changes: 17 additions & 17 deletions pkg/middleend/middleend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"runtime/debug"
"strings"

"github.com/opiproject/gospdk/spdk"
pc "github.com/opiproject/opi-api/common/v1/gen/go"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
intelmodels "github.com/opiproject/opi-intel-bridge/pkg/models"
"github.com/opiproject/opi-intel-bridge/pkg/models"
"github.com/opiproject/opi-spdk-bridge/pkg/middleend"
spdkmodels "github.com/opiproject/opi-spdk-bridge/pkg/models"
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -32,11 +32,11 @@ var (
// Server contains middleend related OPI services
type Server struct {
pb.MiddleendEncryptionServiceServer
rpc server.JSONRPC
rpc spdk.JSONRPC
}

// NewServer creates initialized instance of middleend server
func NewServer(jsonRPC server.JSONRPC) *Server {
func NewServer(jsonRPC spdk.JSONRPC) *Server {
opiSpdkServer := middleend.NewServer(jsonRPC)
return &Server{
opiSpdkServer,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (s *Server) CreateEncryptedVolume(_ context.Context, in *pb.CreateEncrypted

half := len(in.EncryptedVolume.Key) / 2
tweakMode := "A"
params := &intelmodels.NpiBdevSetKeysParams{
params := &models.NpiBdevSetKeysParams{
UUID: bdevUUID,
Key: hex.EncodeToString(in.EncryptedVolume.Key[:half]),
Key2: hex.EncodeToString(in.EncryptedVolume.Key[half:]),
Expand All @@ -84,15 +84,15 @@ func (s *Server) CreateEncryptedVolume(_ context.Context, in *pb.CreateEncrypted
params = nil
}()

var result intelmodels.NpiBdevSetKeysResult
var result models.NpiBdevSetKeysResult
err = s.rpc.Call("npi_bdev_set_keys", params, &result)
if err != nil {
log.Println("error:", err)
return nil, server.ErrFailedSpdkCall
return nil, spdk.ErrFailedSpdkCall
}
if !result {
log.Println("Failed result on SPDK call:", result)
return nil, server.ErrUnexpectedSpdkCallResult
return nil, spdk.ErrUnexpectedSpdkCallResult
}

return &pb.EncryptedVolume{
Expand Down Expand Up @@ -154,10 +154,10 @@ func (s *Server) DeleteEncryptedVolume(_ context.Context, in *pb.DeleteEncrypted
log.Println("Failed to find UUID for bdev", in.Name)
return nil, err
}
params := intelmodels.NpiBdevClearKeysParams{
params := models.NpiBdevClearKeysParams{
UUID: bdevUUID,
}
var result intelmodels.NpiBdevClearKeysResult
var result models.NpiBdevClearKeysResult
err = s.rpc.Call("npi_bdev_clear_keys", params, &result)
if err != nil {
cryptoObjMissingErrMsg := "Could not find a crypto object for a given bdev"
Expand All @@ -166,26 +166,26 @@ func (s *Server) DeleteEncryptedVolume(_ context.Context, in *pb.DeleteEncrypted
return &emptypb.Empty{}, nil
}
log.Println(err)
return nil, server.ErrFailedSpdkCall
return nil, spdk.ErrFailedSpdkCall
}
if !result {
log.Println("Failed result on SPDK call:", result)
return nil, server.ErrUnexpectedSpdkCallResult
return nil, spdk.ErrUnexpectedSpdkCallResult
}
return &emptypb.Empty{}, nil
}

func (s *Server) getBdevUUIDByName(name string) (string, error) {
params := spdkmodels.BdevGetBdevsParams{Name: name}
var result []spdkmodels.BdevGetBdevsResult
params := spdk.BdevGetBdevsParams{Name: name}
var result []spdk.BdevGetBdevsResult
err := s.rpc.Call("bdev_get_bdevs", params, &result)
if err != nil {
log.Println("error:", err)
return "", server.ErrFailedSpdkCall
return "", spdk.ErrFailedSpdkCall
}
if len(result) != 1 {
log.Println("Found bdevs:", result, "under the name", params.Name)
return "", server.ErrUnexpectedSpdkCallResult
return "", spdk.ErrUnexpectedSpdkCallResult
}
return result[0].UUID, nil
}
19 changes: 10 additions & 9 deletions pkg/middleend/middleend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"testing"

"github.com/opiproject/gospdk/spdk"
pc "github.com/opiproject/opi-api/common/v1/gen/go"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
Expand All @@ -32,7 +33,7 @@ type testEnv struct {
testSocket string
ctx context.Context
conn *grpc.ClientConn
jsonRPC server.JSONRPC
jsonRPC spdk.JSONRPC
}

func (e *testEnv) Close() {
Expand Down Expand Up @@ -321,31 +322,31 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) {
out: nil,
spdk: []string{`{"id":%d,"error":{"code":-19,"message":"No such device"},"result":null}`},
expectedInKey: make([]byte, len(encryptedVolumeAesXts256.Key)),
expectedErr: server.ErrFailedSpdkCall,
expectedErr: spdk.ErrFailedSpdkCall,
start: true,
},
"find no bdev uuid by name": {
in: &pb.CreateEncryptedVolumeRequest{EncryptedVolume: &encryptedVolumeAesXts256},
out: nil,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":[]}`},
expectedInKey: make([]byte, len(encryptedVolumeAesXts256.Key)),
expectedErr: server.ErrUnexpectedSpdkCallResult,
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
start: true,
},
"internal SPDK failure": {
in: &pb.CreateEncryptedVolumeRequest{EncryptedVolume: &encryptedVolumeAesXts256},
out: nil,
spdk: []string{foundBdevResponse, `{"id":%d,"error":{"code":1,"message":"some internal error"},"result":true}`},
expectedInKey: make([]byte, len(encryptedVolumeAesXts256.Key)),
expectedErr: server.ErrFailedSpdkCall,
expectedErr: spdk.ErrFailedSpdkCall,
start: true,
},
"SPDK result false": {
in: &pb.CreateEncryptedVolumeRequest{EncryptedVolume: &encryptedVolumeAesXts256},
out: nil,
spdk: []string{foundBdevResponse, `{"id":%d,"error":{"code":0,"message":""},"result":false}`},
expectedInKey: make([]byte, len(encryptedVolumeAesXts256.Key)),
expectedErr: server.ErrUnexpectedSpdkCallResult,
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
start: true,
},
}
Expand Down Expand Up @@ -411,25 +412,25 @@ func TestMiddleEnd_DeleteEncryptedVolume(t *testing.T) {
"find bdev uuid by name internal SPDK failure": {
in: &pb.DeleteEncryptedVolumeRequest{Name: bdevName},
spdk: []string{`{"id":%d,"error":{"code":-19,"message":"No such device"},"result":null}`},
expectedErr: server.ErrFailedSpdkCall,
expectedErr: spdk.ErrFailedSpdkCall,
start: true,
},
"find no bdev uuid by name": {
in: &pb.DeleteEncryptedVolumeRequest{Name: bdevName},
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":[]}`},
expectedErr: server.ErrUnexpectedSpdkCallResult,
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
start: true,
},
"internal SPDK failure": {
in: &pb.DeleteEncryptedVolumeRequest{Name: bdevName},
spdk: []string{foundBdevResponse, `{"id":%d,"error":{"code":1,"message":"some internal error"},"result":true}`},
expectedErr: server.ErrFailedSpdkCall,
expectedErr: spdk.ErrFailedSpdkCall,
start: true,
},
"SPDK result false": {
in: &pb.DeleteEncryptedVolumeRequest{Name: bdevName},
spdk: []string{foundBdevResponse, `{"id":%d,"error":{"code":0,"message":""},"result":false}`},
expectedErr: server.ErrUnexpectedSpdkCallResult,
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
start: true,
},
"delete non-existing encrypted volume with missing allowed": {
Expand Down

0 comments on commit c8bc75d

Please sign in to comment.