From 599a0893c321fce788cbe0811632e88ad16eaef0 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Wed, 2 Aug 2023 19:00:13 +0300 Subject: [PATCH] refactor(storage): latest API changes ObjectStats -> StatsObject VolumeId -> VolumeNameRef remove pc.ObjectKey Signed-off-by: Boris Glimcher --- README.md | 8 +- docker-compose.yml | 2 +- go.mod | 10 +- go.sum | 28 +++--- pkg/backend/aio.go | 14 +-- pkg/backend/aio_test.go | 7 +- pkg/backend/null.go | 14 +-- pkg/backend/null_test.go | 6 +- pkg/backend/nvme_controller.go | 10 +- pkg/backend/nvme_controller_test.go | 12 +-- pkg/backend/nvme_path.go | 8 +- pkg/backend/nvme_path_test.go | 30 +++--- pkg/frontend/blk.go | 29 +++--- pkg/frontend/blk_test.go | 93 +++++++++--------- pkg/frontend/nvme_controller.go | 8 +- pkg/frontend/nvme_controller_test.go | 6 +- pkg/frontend/nvme_namespace.go | 8 +- pkg/frontend/nvme_namespace_test.go | 6 +- pkg/frontend/nvme_subsystem.go | 14 +-- pkg/frontend/nvme_subsystem_test.go | 6 +- pkg/frontend/scsi.go | 24 ++--- pkg/frontend/scsi_test.go | 4 +- pkg/kvm/blk_test.go | 35 ++++--- pkg/middleend/encryption.go | 18 ++-- pkg/middleend/encryption_test.go | 135 +++++++++++++-------------- pkg/middleend/middleend_test.go | 7 +- pkg/middleend/qos.go | 19 ++-- pkg/middleend/qos_test.go | 17 ++-- 28 files changed, 284 insertions(+), 294 deletions(-) diff --git a/README.md b/README.md index e7a021be..c87eefca 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ docker run --network=host --rm -it namely/grpc-cli call --json_input --json_outp docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 CreateNvmeNamespace "{nvme_namespace : {spec : {subsystem_name_ref : '//storage.opiproject.org/volumes/subsystem2', volume_name_ref : 'Malloc0', 'host_nsid' : '10', uuid:{value : '1b4e28ba-2fa1-11d2-883f-b9a761bde3fb'}, nguid: '1b4e28ba-2fa1-11d2-883f-b9a761bde3fb', eui64: 1967554867335598546 } }, nvme_namespace_id: 'namespace1'}" docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 ListNvmeNamespaces "{parent : '//storage.opiproject.org/volumes/subsystem2'}" docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 GetNvmeNamespace "{name : '//storage.opiproject.org/volumes/namespace1'}" -docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 NvmeNamespaceStats "{name : '//storage.opiproject.org/volumes/namespace1'}" +docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 StatsNvmeNamespace "{name : '//storage.opiproject.org/volumes/namespace1'}" docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 CreateNvmeRemoteController "{nvme_remote_controller : {multipath: 'NVME_MULTIPATH_MULTIPATH'}, nvme_remote_controller_id: 'nvmetcp12'}" docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 ListNvmeRemoteControllers "{parent : 'todo'}" docker run --network=host --rm -it namely/grpc-cli call --json_input --json_output 10.10.10.10:50051 GetNvmeRemoteController "{name: '//storage.opiproject.org/volumes/nvmetcp12'}" @@ -140,19 +140,19 @@ service FrontendNvmeService { rpc UpdateNvmeSubsystem(opi_api.storage.v1.UpdateNvmeSubsystemRequest) returns (opi_api.storage.v1.NvmeSubsystem) {} rpc ListNvmeSubsystem(opi_api.storage.v1.ListNvmeSubsystemRequest) returns (opi_api.storage.v1.ListNvmeSubsystemResponse) {} rpc GetNvmeSubsystem(opi_api.storage.v1.GetNvmeSubsystemRequest) returns (opi_api.storage.v1.NvmeSubsystem) {} - rpc NvmeSubsystemStats(opi_api.storage.v1.NvmeSubsystemStatsRequest) returns (opi_api.storage.v1.NvmeSubsystemStatsResponse) {} + rpc StatsNvmeSubsystem(opi_api.storage.v1.StatsNvmeSubsystemRequest) returns (opi_api.storage.v1.StatsNvmeSubsystemResponse) {} rpc CreateNvmeController(opi_api.storage.v1.CreateNvmeControllerRequest) returns (opi_api.storage.v1.NvmeController) {} rpc DeleteNvmeController(opi_api.storage.v1.DeleteNvmeControllerRequest) returns (google.protobuf.Empty) {} rpc UpdateNvmeController(opi_api.storage.v1.UpdateNvmeControllerRequest) returns (opi_api.storage.v1.NvmeController) {} rpc ListNvmeController(opi_api.storage.v1.ListNvmeControllerRequest) returns (opi_api.storage.v1.ListNvmeControllerResponse) {} rpc GetNvmeController(opi_api.storage.v1.GetNvmeControllerRequest) returns (opi_api.storage.v1.NvmeController) {} - rpc NvmeControllerStats(opi_api.storage.v1.NvmeControllerStatsRequest) returns (opi_api.storage.v1.NvmeControllerStatsResponse) {} + rpc StatsNvmeController(opi_api.storage.v1.StatsNvmeControllerRequest) returns (opi_api.storage.v1.StatsNvmeControllerResponse) {} rpc CreateNvmeNamespace(opi_api.storage.v1.CreateNvmeNamespaceRequest) returns (opi_api.storage.v1.NvmeNamespace) {} rpc DeleteNvmeNamespace(opi_api.storage.v1.DeleteNvmeNamespaceRequest) returns (google.protobuf.Empty) {} rpc UpdateNvmeNamespace(opi_api.storage.v1.UpdateNvmeNamespaceRequest) returns (opi_api.storage.v1.NvmeNamespace) {} rpc ListNvmeNamespace(opi_api.storage.v1.ListNvmeNamespaceRequest) returns (opi_api.storage.v1.ListNvmeNamespaceResponse) {} rpc GetNvmeNamespace(opi_api.storage.v1.GetNvmeNamespaceRequest) returns (opi_api.storage.v1.NvmeNamespace) {} - rpc NvmeNamespaceStats(opi_api.storage.v1.NvmeNamespaceStatsRequest) returns (opi_api.storage.v1.NvmeNamespaceStatsResponse) {} + rpc StatsNvmeNamespace(opi_api.storage.v1.StatsNvmeNamespaceRequest) returns (opi_api.storage.v1.StatsNvmeNamespaceResponse) {} } ``` diff --git a/docker-compose.yml b/docker-compose.yml index 83d75b0d..26b8e9e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,7 +68,7 @@ services: test: grpcurl -plaintext localhost:50051 list || exit 1 opi-spdk-client: - image: ghcr.io/opiproject/godpu:main@sha256:c35775b11f5bafbdc3a24d5f7ad01de0ea31050592e040a3f55ec2b5911ee972 + image: ghcr.io/opiproject/godpu:main@sha256:ec7d7ccf40c02cf13dd9afbd874f7de2d0350b0ae8f61e8e943ac45aa3a75919 networks: - opi depends_on: diff --git a/go.mod b/go.mod index 873eb516..e42b99d9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/digitalocean/go-qemu v0.0.0-20230711162256-2e3d0186973e github.com/google/uuid v1.3.0 github.com/opiproject/gospdk v0.0.0-20230724125810-f9b59208a93e - github.com/opiproject/opi-api v0.0.0-20230728150746-cc0946b7cec4 + github.com/opiproject/opi-api v0.0.0-20230802143709-76c2f23d70d5 go.einride.tech/aip v0.61.0 google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 @@ -15,10 +15,10 @@ require ( require ( github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e // indirect github.com/golang/protobuf v1.5.3 // indirect - golang.org/x/net v0.12.0 // indirect + golang.org/x/net v0.13.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect - google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e // indirect + google.golang.org/genproto v0.0.0-20230731193218-e0aa005b6bdf // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230731193218-e0aa005b6bdf // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect ) diff --git a/go.sum b/go.sum index c2481578..19d119d3 100644 --- a/go.sum +++ b/go.sum @@ -11,20 +11,16 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/opiproject/gospdk v0.0.0-20230721162442-5187c4c6663b h1:MYk4lS7uUpJwT89WJgjqg9RCXywslytpBDmZcWy626I= -github.com/opiproject/gospdk v0.0.0-20230721162442-5187c4c6663b/go.mod h1:RqA5Ix7+x0Is8UckJE+6Ji5kCfk6yujWWaTMoRlZv3w= github.com/opiproject/gospdk v0.0.0-20230724125810-f9b59208a93e h1:y27NgCS0+ESFLR40iwWm7OM0qi++zTjRDuQt09+iie8= github.com/opiproject/gospdk v0.0.0-20230724125810-f9b59208a93e/go.mod h1:RqA5Ix7+x0Is8UckJE+6Ji5kCfk6yujWWaTMoRlZv3w= -github.com/opiproject/opi-api v0.0.0-20230728150746-cc0946b7cec4 h1:wOsrhHoOo5h1S7BwcPoQsWPPb0ILV6QNX8Fc53GqQ/o= -github.com/opiproject/opi-api v0.0.0-20230728150746-cc0946b7cec4/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= +github.com/opiproject/opi-api v0.0.0-20230802143709-76c2f23d70d5 h1:L0TDC4GEqKUpoiZAqEezI/Cha5sstiXg4ZNqLgYUPn0= +github.com/opiproject/opi-api v0.0.0-20230802143709-76c2f23d70d5/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.einride.tech/aip v0.60.0 h1:h6bgabZ5BCfAptbGex8jbh3VvPBRLa6xq+pQ1CAjHYw= -go.einride.tech/aip v0.60.0/go.mod h1:SdLbSbgSU60Xkb4TMkmsZEQPHeEWx0ikBoq5QnqZvdg= go.einride.tech/aip v0.61.0 h1:H7r59BtQDcj8kGNa0Dytw88so1iWrzp6mSOEQgcIJWI= go.einride.tech/aip v0.61.0/go.mod h1:YVrCQRL7SCB5Mv7i2ZF1R6vkLPh844RQBCLrrLcefaU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -33,8 +29,8 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -56,14 +52,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e h1:xIXmWJ303kJCuogpj0bHq+dcjcZHU+XFyc1I0Yl9cRg= -google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:0ggbjUrZYpy1q+ANUS30SEoGZ53cdfwtbuG7Ptgy108= -google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:z3vDksarJxsAKM5dmEGv0GHwE2hKJ096wZra71Vs4sw= -google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e h1:S83+ibolgyZ0bqz7KEsUOPErxcv4VzlszxY+31OfB/E= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= -google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/genproto v0.0.0-20230731193218-e0aa005b6bdf h1:v5Cf4E9+6tawYrs/grq1q1hFpGtzlGFzgWHqwt6NFiU= +google.golang.org/genproto v0.0.0-20230731193218-e0aa005b6bdf/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= +google.golang.org/genproto/googleapis/api v0.0.0-20230731193218-e0aa005b6bdf h1:xkVZ5FdZJF4U82Q/JS+DcZA83s/GRVL+QrFMlexk9Yo= +google.golang.org/genproto/googleapis/api v0.0.0-20230731193218-e0aa005b6bdf/go.mod h1:5DZzOUPCLYL3mNkQ0ms0F3EuUNZ7py1Bqeq6sxzI7/Q= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf h1:guOdSPaeFgN+jEJwTo1dQ71hdBm+yKSCCKuTRkJzcVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf/go.mod h1:zBEcrKX2ZOcEkHWxBPAIvYUWOKKMIhYcmNiUIu2ji3I= google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= @@ -73,4 +67,4 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= diff --git a/pkg/backend/aio.go b/pkg/backend/aio.go index 0e045bb9..66409216 100644 --- a/pkg/backend/aio.go +++ b/pkg/backend/aio.go @@ -288,23 +288,23 @@ func (s *Server) GetAioVolume(_ context.Context, in *pb.GetAioVolumeRequest) (*p return &pb.AioVolume{Name: result[0].Name, BlockSize: result[0].BlockSize, BlocksCount: result[0].NumBlocks}, nil } -// AioVolumeStats gets an Aio volume stats -func (s *Server) AioVolumeStats(_ context.Context, in *pb.AioVolumeStatsRequest) (*pb.AioVolumeStatsResponse, error) { - log.Printf("AioVolumeStats: Received from client: %v", in) +// StatsAioVolume gets an Aio volume stats +func (s *Server) StatsAioVolume(_ context.Context, in *pb.StatsAioVolumeRequest) (*pb.StatsAioVolumeResponse, error) { + log.Printf("StatsAioVolume: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.Handle.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Volumes.AioVolumes[in.Handle.Value] + volume, ok := s.Volumes.AioVolumes[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.Handle.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } @@ -325,7 +325,7 @@ func (s *Server) AioVolumeStats(_ context.Context, in *pb.AioVolumeStatsRequest) log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.AioVolumeStatsResponse{Stats: &pb.VolumeStats{ + return &pb.StatsAioVolumeResponse{Stats: &pb.VolumeStats{ ReadBytesCount: int32(result.Bdevs[0].BytesRead), ReadOpsCount: int32(result.Bdevs[0].NumReadOps), WriteBytesCount: int32(result.Bdevs[0].BytesWritten), diff --git a/pkg/backend/aio_test.go b/pkg/backend/aio_test.go index b02c8e99..1d84f8ac 100644 --- a/pkg/backend/aio_test.go +++ b/pkg/backend/aio_test.go @@ -17,7 +17,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - 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" ) @@ -617,7 +616,7 @@ func TestBackEnd_GetAioVolume(t *testing.T) { } } -func TestBackEnd_AioVolumeStats(t *testing.T) { +func TestBackEnd_StatsAioVolume(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -698,8 +697,8 @@ func TestBackEnd_AioVolumeStats(t *testing.T) { testEnv.opiSpdkServer.Volumes.AioVolumes[testAioVolumeID] = &testAioVolume - request := &pb.AioVolumeStatsRequest{Handle: &pc.ObjectKey{Value: tt.in}} - response, err := testEnv.client.AioVolumeStats(testEnv.ctx, request) + request := &pb.StatsAioVolumeRequest{Name: tt.in} + response, err := testEnv.client.StatsAioVolume(testEnv.ctx, request) if !proto.Equal(tt.out, response.GetStats()) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/backend/null.go b/pkg/backend/null.go index 7132e189..95c49b30 100644 --- a/pkg/backend/null.go +++ b/pkg/backend/null.go @@ -289,23 +289,23 @@ func (s *Server) GetNullVolume(_ context.Context, in *pb.GetNullVolumeRequest) ( return &pb.NullVolume{Name: result[0].Name, Uuid: &pc.Uuid{Value: result[0].UUID}, BlockSize: result[0].BlockSize, BlocksCount: result[0].NumBlocks}, nil } -// NullVolumeStats gets a Null volume instance stats -func (s *Server) NullVolumeStats(_ context.Context, in *pb.NullVolumeStatsRequest) (*pb.NullVolumeStatsResponse, error) { - log.Printf("NullVolumeStats: Received from client: %v", in) +// StatsNullVolume gets a Null volume instance stats +func (s *Server) StatsNullVolume(_ context.Context, in *pb.StatsNullVolumeRequest) (*pb.StatsNullVolumeResponse, error) { + log.Printf("StatsNullVolume: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.Handle.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Volumes.NullVolumes[in.Handle.Value] + volume, ok := s.Volumes.NullVolumes[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.Handle.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } @@ -326,7 +326,7 @@ func (s *Server) NullVolumeStats(_ context.Context, in *pb.NullVolumeStatsReques log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.NullVolumeStatsResponse{Stats: &pb.VolumeStats{ + return &pb.StatsNullVolumeResponse{Stats: &pb.VolumeStats{ ReadBytesCount: int32(result.Bdevs[0].BytesRead), ReadOpsCount: int32(result.Bdevs[0].NumReadOps), WriteBytesCount: int32(result.Bdevs[0].BytesWritten), diff --git a/pkg/backend/null_test.go b/pkg/backend/null_test.go index 267a302f..376a0d1e 100644 --- a/pkg/backend/null_test.go +++ b/pkg/backend/null_test.go @@ -623,7 +623,7 @@ func TestBackEnd_GetNullVolume(t *testing.T) { } } -func TestBackEnd_NullVolumeStats(t *testing.T) { +func TestBackEnd_StatsNullVolume(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -704,8 +704,8 @@ func TestBackEnd_NullVolumeStats(t *testing.T) { testEnv.opiSpdkServer.Volumes.NullVolumes[testNullVolumeID] = &testNullVolume - request := &pb.NullVolumeStatsRequest{Handle: &pc.ObjectKey{Value: tt.in}} - response, err := testEnv.client.NullVolumeStats(testEnv.ctx, request) + request := &pb.StatsNullVolumeRequest{Name: tt.in} + response, err := testEnv.client.StatsNullVolume(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/backend/nvme_controller.go b/pkg/backend/nvme_controller.go index c9be0440..605bde8e 100644 --- a/pkg/backend/nvme_controller.go +++ b/pkg/backend/nvme_controller.go @@ -97,8 +97,8 @@ func (s *Server) DeleteNvmeRemoteController(_ context.Context, in *pb.DeleteNvme return &emptypb.Empty{}, nil } -// NvmeRemoteControllerReset resets an Nvme remote controller -func (s *Server) NvmeRemoteControllerReset(_ context.Context, in *pb.NvmeRemoteControllerResetRequest) (*emptypb.Empty, error) { +// ResetNvmeRemoteController resets an Nvme remote controller +func (s *Server) ResetNvmeRemoteController(_ context.Context, in *pb.ResetNvmeRemoteControllerRequest) (*emptypb.Empty, error) { log.Printf("Received: %v", in.GetName()) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { @@ -169,8 +169,8 @@ func (s *Server) GetNvmeRemoteController(_ context.Context, in *pb.GetNvmeRemote return response, nil } -// NvmeRemoteControllerStats gets Nvme remote controller stats -func (s *Server) NvmeRemoteControllerStats(_ context.Context, in *pb.NvmeRemoteControllerStatsRequest) (*pb.NvmeRemoteControllerStatsResponse, error) { +// StatsNvmeRemoteController gets Nvme remote controller stats +func (s *Server) StatsNvmeRemoteController(_ context.Context, in *pb.StatsNvmeRemoteControllerRequest) (*pb.StatsNvmeRemoteControllerResponse, error) { log.Printf("Received: %v", in.GetName()) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { @@ -191,5 +191,5 @@ func (s *Server) NvmeRemoteControllerStats(_ context.Context, in *pb.NvmeRemoteC } name := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", name) - return &pb.NvmeRemoteControllerStatsResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil + return &pb.StatsNvmeRemoteControllerResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil } diff --git a/pkg/backend/nvme_controller_test.go b/pkg/backend/nvme_controller_test.go index f0250a1a..bf62be4e 100644 --- a/pkg/backend/nvme_controller_test.go +++ b/pkg/backend/nvme_controller_test.go @@ -108,7 +108,7 @@ func TestBackEnd_CreateNvmeRemoteController(t *testing.T) { } } -func TestBackEnd_NvmeRemoteControllerReset(t *testing.T) { +func TestBackEnd_ResetNvmeRemoteController(t *testing.T) { tests := map[string]struct { in string out *emptypb.Empty @@ -131,8 +131,8 @@ func TestBackEnd_NvmeRemoteControllerReset(t *testing.T) { testEnv := createTestEnvironment(tt.spdk) defer testEnv.Close() - request := &pb.NvmeRemoteControllerResetRequest{Name: tt.in} - response, err := testEnv.client.NvmeRemoteControllerReset(testEnv.ctx, request) + request := &pb.ResetNvmeRemoteControllerRequest{Name: tt.in} + response, err := testEnv.client.ResetNvmeRemoteController(testEnv.ctx, request) if !proto.Equal(response, tt.out) { t.Error("response: expected", tt.out, "received", response) @@ -367,7 +367,7 @@ func TestBackEnd_GetNvmeRemoteController(t *testing.T) { } } -func TestBackEnd_NvmeRemoteControllerStats(t *testing.T) { +func TestBackEnd_StatsNvmeRemoteController(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -409,8 +409,8 @@ func TestBackEnd_NvmeRemoteControllerStats(t *testing.T) { testEnv.opiSpdkServer.Volumes.NvmeControllers[testNvmeCtrlID] = &testNvmeCtrl - request := &pb.NvmeRemoteControllerStatsRequest{Name: tt.in} - response, err := testEnv.client.NvmeRemoteControllerStats(testEnv.ctx, request) + request := &pb.StatsNvmeRemoteControllerRequest{Name: tt.in} + response, err := testEnv.client.StatsNvmeRemoteController(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/backend/nvme_path.go b/pkg/backend/nvme_path.go index 42a5de96..bb601d7f 100644 --- a/pkg/backend/nvme_path.go +++ b/pkg/backend/nvme_path.go @@ -275,9 +275,9 @@ func (s *Server) GetNvmePath(_ context.Context, in *pb.GetNvmePathRequest) (*pb. return nil, status.Errorf(codes.InvalidArgument, msg) } -// NvmePathStats gets Nvme path stats -func (s *Server) NvmePathStats(_ context.Context, in *pb.NvmePathStatsRequest) (*pb.NvmePathStatsResponse, error) { - log.Printf("NvmePathStats: Received from client: %v", in) +// StatsNvmePath gets Nvme path stats +func (s *Server) StatsNvmePath(_ context.Context, in *pb.StatsNvmePathRequest) (*pb.StatsNvmePathResponse, error) { + log.Printf("StatsNvmePath: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) @@ -304,7 +304,7 @@ func (s *Server) NvmePathStats(_ context.Context, in *pb.NvmePathStatsRequest) ( return nil, err } log.Printf("Received from SPDK: %v", result) - return &pb.NvmePathStatsResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil + return &pb.StatsNvmePathResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil } func (s *Server) opiTransportToSpdk(transport pb.NvmeTransportType) string { diff --git a/pkg/backend/nvme_path_test.go b/pkg/backend/nvme_path_test.go index 8fd0eb6e..395f5f91 100644 --- a/pkg/backend/nvme_path_test.go +++ b/pkg/backend/nvme_path_test.go @@ -378,11 +378,12 @@ func TestBackEnd_UpdateNvmePath(t *testing.T) { "valid request with unknown key": { nil, &pb.NvmePath{ - Name: server.ResourceIDToVolumeName("unknown-id"), - Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TCP, - Adrfam: pb.NvmeAddressFamily_NVME_ADRFAM_IPV4, - Traddr: "127.0.0.1", - Trsvcid: 4444, + Name: server.ResourceIDToVolumeName("unknown-id"), + Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TCP, + Adrfam: pb.NvmeAddressFamily_NVME_ADRFAM_IPV4, + Traddr: "127.0.0.1", + Trsvcid: 4444, + ControllerNameRef: "TBD", }, nil, []string{}, @@ -393,11 +394,12 @@ func TestBackEnd_UpdateNvmePath(t *testing.T) { "unknown key with missing allowed": { nil, &pb.NvmePath{ - Name: server.ResourceIDToVolumeName("unknown-id"), - Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TCP, - Adrfam: pb.NvmeAddressFamily_NVME_ADRFAM_IPV4, - Traddr: "127.0.0.1", - Trsvcid: 4444, + Name: server.ResourceIDToVolumeName("unknown-id"), + Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TCP, + Adrfam: pb.NvmeAddressFamily_NVME_ADRFAM_IPV4, + Traddr: "127.0.0.1", + Trsvcid: 4444, + ControllerNameRef: "TBD", }, nil, []string{}, @@ -407,7 +409,7 @@ func TestBackEnd_UpdateNvmePath(t *testing.T) { }, "malformed name": { nil, - &pb.NvmePath{Name: "-ABC-DEF"}, + &pb.NvmePath{Name: "-ABC-DEF", ControllerNameRef: "TBD"}, nil, []string{}, codes.Unknown, @@ -757,7 +759,7 @@ func TestBackEnd_GetNvmePath(t *testing.T) { } } -func TestBackEnd_NvmePathStats(t *testing.T) { +func TestBackEnd_StatsNvmePath(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -838,8 +840,8 @@ func TestBackEnd_NvmePathStats(t *testing.T) { testEnv.opiSpdkServer.Volumes.NvmePaths[testNvmePathID] = &testNvmePath - request := &pb.NvmePathStatsRequest{Name: tt.in} - response, err := testEnv.client.NvmePathStats(testEnv.ctx, request) + request := &pb.StatsNvmePathRequest{Name: tt.in} + response, err := testEnv.client.StatsNvmePath(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/frontend/blk.go b/pkg/frontend/blk.go index aa77bbc8..c8278c8f 100644 --- a/pkg/frontend/blk.go +++ b/pkg/frontend/blk.go @@ -13,7 +13,6 @@ import ( "sort" "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" @@ -63,7 +62,7 @@ func (s *Server) CreateVirtioBlk(_ context.Context, in *pb.CreateVirtioBlkReques // not found, so create a new one params := spdk.VhostCreateBlkControllerParams{ Ctrlr: resourceID, - DevName: in.VirtioBlk.VolumeId.Value, + DevName: in.VirtioBlk.VolumeNameRef, } var result spdk.VhostCreateBlkControllerResult err := s.rpc.Call("vhost_create_blk_controller", ¶ms, &result) @@ -191,9 +190,9 @@ func (s *Server) ListVirtioBlks(_ context.Context, in *pb.ListVirtioBlksRequest) for i := range result { r := &result[i] Blobarray[i] = &pb.VirtioBlk{ - Name: server.ResourceIDToVolumeName(r.Ctrlr), - PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, - VolumeId: &pc.ObjectKey{Value: "TBD"}} + Name: server.ResourceIDToVolumeName(r.Ctrlr), + PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, + VolumeNameRef: "TBD"} } sortVirtioBlks(Blobarray) @@ -237,32 +236,32 @@ func (s *Server) GetVirtioBlk(_ context.Context, in *pb.GetVirtioBlkRequest) (*p return nil, status.Errorf(codes.InvalidArgument, msg) } return &pb.VirtioBlk{ - Name: in.Name, - PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, - VolumeId: &pc.ObjectKey{Value: "TBD"}}, nil + Name: in.Name, + PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, + VolumeNameRef: "TBD"}, nil } -// VirtioBlkStats gets a Virtio block device stats -func (s *Server) VirtioBlkStats(_ context.Context, in *pb.VirtioBlkStatsRequest) (*pb.VirtioBlkStatsResponse, error) { - log.Printf("VirtioBlkStats: Received from client: %v", in) +// StatsVirtioBlk gets a Virtio block device stats +func (s *Server) StatsVirtioBlk(_ context.Context, in *pb.StatsVirtioBlkRequest) (*pb.StatsVirtioBlkResponse, error) { + log.Printf("StatsVirtioBlk: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.ControllerId.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Virt.BlkCtrls[in.ControllerId.Value] + volume, ok := s.Virt.BlkCtrls[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.ControllerId.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } resourceID := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", resourceID) - return nil, status.Errorf(codes.Unimplemented, "VirtioBlkStats method is not implemented") + return nil, status.Errorf(codes.Unimplemented, "StatsVirtioBlk method is not implemented") } diff --git a/pkg/frontend/blk_test.go b/pkg/frontend/blk_test.go index b47b2a9c..5ce83965 100644 --- a/pkg/frontend/blk_test.go +++ b/pkg/frontend/blk_test.go @@ -16,7 +16,6 @@ import ( "google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/fieldmaskpb" - 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" ) @@ -25,9 +24,9 @@ var ( testVirtioCtrlID = "virtio-blk-42" testVirtioCtrlName = server.ResourceIDToVolumeName(testVirtioCtrlID) testVirtioCtrl = pb.VirtioBlk{ - PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, } ) @@ -124,7 +123,8 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) { "invalid fieldmask": { &fieldmaskpb.FieldMask{Paths: []string{"*", "author"}}, &pb.VirtioBlk{ - Name: testVirtioCtrlName, + Name: testVirtioCtrlName, + VolumeNameRef: "TBD", }, nil, []string{}, @@ -135,7 +135,8 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) { "unimplemented method": { nil, &pb.VirtioBlk{ - Name: testVirtioCtrlName, + Name: testVirtioCtrlName, + VolumeNameRef: "TBD", }, nil, []string{}, @@ -146,10 +147,10 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) { "valid request with unknown key": { nil, &pb.VirtioBlk{ - Name: server.ResourceIDToVolumeName("unknown-id"), - PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + Name: server.ResourceIDToVolumeName("unknown-id"), + PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, nil, []string{}, @@ -160,10 +161,10 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) { "unknown key with missing allowed": { nil, &pb.VirtioBlk{ - Name: server.ResourceIDToVolumeName("unknown-id"), - PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + Name: server.ResourceIDToVolumeName("unknown-id"), + PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, nil, []string{}, @@ -173,7 +174,7 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) { }, "malformed name": { nil, - &pb.VirtioBlk{Name: "-ABC-DEF"}, + &pb.VirtioBlk{Name: "-ABC-DEF", VolumeNameRef: "TBD"}, nil, []string{}, codes.Unknown, @@ -261,19 +262,19 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) { "subsystem-test", []*pb.VirtioBlk{ { - Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, { - Name: server.ResourceIDToVolumeName("VblkEmu0pf2"), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName("VblkEmu0pf2"), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, { - Name: server.ResourceIDToVolumeName(testVirtioCtrlID), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName(testVirtioCtrlID), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, }, []string{`{"jsonrpc":"2.0","id":%d,"result":[` + @@ -290,19 +291,19 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) { "subsystem-test", []*pb.VirtioBlk{ { - Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, { - Name: server.ResourceIDToVolumeName("VblkEmu0pf2"), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName("VblkEmu0pf2"), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, { - Name: testVirtioCtrlName, - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: testVirtioCtrlName, + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, }, []string{`{"jsonrpc":"2.0","id":%d,"result":[{"ctrlr":"VblkEmu0pf0","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"virtio-blk-42","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"VblkEmu0pf2","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"}],"error":{"code":0,"message":""}}`}, @@ -333,9 +334,9 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) { "subsystem-test", []*pb.VirtioBlk{ { - Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: server.ResourceIDToVolumeName("VblkEmu0pf0"), + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, }, []string{`{"jsonrpc":"2.0","id":%d,"result":[{"ctrlr":"VblkEmu0pf0","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"virtio-blk-42","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"VblkEmu0pf2","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"}],"error":{"code":0,"message":""}}`}, @@ -348,9 +349,9 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) { "subsystem-test", []*pb.VirtioBlk{ { - Name: testVirtioCtrlName, - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: testVirtioCtrlName, + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, }, []string{`{"jsonrpc":"2.0","id":%d,"result":[{"ctrlr":"VblkEmu0pf0","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"virtio-blk-42","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"},{"ctrlr":"VblkEmu0pf2","emulation_manager":"mlx5_0","type":"virtio_blk","pci_index":0,"pci_bdf":"ca:00.4"}],"error":{"code":0,"message":""}}`}, @@ -443,9 +444,9 @@ func TestFrontEnd_GetVirtioBlk(t *testing.T) { "valid request with valid SPDK response": { testVirtioCtrlName, &pb.VirtioBlk{ - Name: testVirtioCtrlName, - PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, - VolumeId: &pc.ObjectKey{Value: "TBD"}, + Name: testVirtioCtrlName, + PcieId: &pb.PciEndpoint{PhysicalFunction: int32(1)}, + VolumeNameRef: "TBD", }, []string{`{"jsonrpc":"2.0","id":%d,"result":[{"ctrlr":"virtio-blk-42","iops_threshold":60000,"cpumask":"0x2","delay_base_us":100}],"error":{"code":0,"message":""}}`}, codes.OK, @@ -504,7 +505,7 @@ func TestFrontEnd_GetVirtioBlk(t *testing.T) { } } -func TestFrontEnd_VirtioBlkStats(t *testing.T) { +func TestFrontEnd_StatsVirtioBlk(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -517,7 +518,7 @@ func TestFrontEnd_VirtioBlkStats(t *testing.T) { nil, []string{}, codes.Unimplemented, - fmt.Sprintf("%v method is not implemented", "VirtioBlkStats"), + fmt.Sprintf("%v method is not implemented", "StatsVirtioBlk"), }, "valid request with unknown key": { "unknown-id", @@ -543,8 +544,8 @@ func TestFrontEnd_VirtioBlkStats(t *testing.T) { testEnv.opiSpdkServer.Virt.BlkCtrls[testVirtioCtrlID] = &testVirtioCtrl - request := &pb.VirtioBlkStatsRequest{ControllerId: &pc.ObjectKey{Value: tt.in}} - response, err := testEnv.client.VirtioBlkStats(testEnv.ctx, request) + request := &pb.StatsVirtioBlkRequest{Name: tt.in} + response, err := testEnv.client.StatsVirtioBlk(testEnv.ctx, request) if !proto.Equal(tt.out, response.GetStats()) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/frontend/nvme_controller.go b/pkg/frontend/nvme_controller.go index 956f1a2d..7d184ba2 100644 --- a/pkg/frontend/nvme_controller.go +++ b/pkg/frontend/nvme_controller.go @@ -270,9 +270,9 @@ func (s *Server) GetNvmeController(_ context.Context, in *pb.GetNvmeControllerRe return &pb.NvmeController{Name: in.Name, Spec: &pb.NvmeControllerSpec{NvmeControllerId: controller.Spec.NvmeControllerId}, Status: &pb.NvmeControllerStatus{Active: true}}, nil } -// NvmeControllerStats gets an Nvme controller stats -func (s *Server) NvmeControllerStats(_ context.Context, in *pb.NvmeControllerStatsRequest) (*pb.NvmeControllerStatsResponse, error) { - log.Printf("NvmeControllerStats: Received from client: %v", in) +// StatsNvmeController gets an Nvme controller stats +func (s *Server) StatsNvmeController(_ context.Context, in *pb.StatsNvmeControllerRequest) (*pb.StatsNvmeControllerResponse, error) { + log.Printf("StatsNvmeController: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) @@ -292,5 +292,5 @@ func (s *Server) NvmeControllerStats(_ context.Context, in *pb.NvmeControllerSta } resourceID := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", resourceID) - return &pb.NvmeControllerStatsResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil + return &pb.StatsNvmeControllerResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil } diff --git a/pkg/frontend/nvme_controller_test.go b/pkg/frontend/nvme_controller_test.go index ea8bebea..7f69e799 100644 --- a/pkg/frontend/nvme_controller_test.go +++ b/pkg/frontend/nvme_controller_test.go @@ -605,7 +605,7 @@ func TestFrontEnd_GetNvmeController(t *testing.T) { } } -func TestFrontEnd_NvmeControllerStats(t *testing.T) { +func TestFrontEnd_StatsNvmeController(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -647,8 +647,8 @@ func TestFrontEnd_NvmeControllerStats(t *testing.T) { testEnv.opiSpdkServer.Nvme.Controllers[testControllerName] = &testController - request := &pb.NvmeControllerStatsRequest{Name: tt.in} - response, err := testEnv.client.NvmeControllerStats(testEnv.ctx, request) + request := &pb.StatsNvmeControllerRequest{Name: tt.in} + response, err := testEnv.client.StatsNvmeController(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/frontend/nvme_namespace.go b/pkg/frontend/nvme_namespace.go index 2eacfe47..928db06d 100644 --- a/pkg/frontend/nvme_namespace.go +++ b/pkg/frontend/nvme_namespace.go @@ -306,9 +306,9 @@ func (s *Server) GetNvmeNamespace(_ context.Context, in *pb.GetNvmeNamespaceRequ return nil, status.Errorf(codes.InvalidArgument, msg) } -// NvmeNamespaceStats gets an Nvme namespace stats -func (s *Server) NvmeNamespaceStats(_ context.Context, in *pb.NvmeNamespaceStatsRequest) (*pb.NvmeNamespaceStatsResponse, error) { - log.Printf("NvmeNamespaceStats: Received from client: %v", in) +// StatsNvmeNamespace gets an Nvme namespace stats +func (s *Server) StatsNvmeNamespace(_ context.Context, in *pb.StatsNvmeNamespaceRequest) (*pb.StatsNvmeNamespaceResponse, error) { + log.Printf("StatsNvmeNamespace: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) @@ -328,5 +328,5 @@ func (s *Server) NvmeNamespaceStats(_ context.Context, in *pb.NvmeNamespaceStats } resourceID := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", resourceID) - return &pb.NvmeNamespaceStatsResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil + return &pb.StatsNvmeNamespaceResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil } diff --git a/pkg/frontend/nvme_namespace_test.go b/pkg/frontend/nvme_namespace_test.go index b236551a..0086e72a 100644 --- a/pkg/frontend/nvme_namespace_test.go +++ b/pkg/frontend/nvme_namespace_test.go @@ -733,7 +733,7 @@ func TestFrontEnd_GetNvmeNamespace(t *testing.T) { } } -func TestFrontEnd_NvmeNamespaceStats(t *testing.T) { +func TestFrontEnd_StatsNvmeNamespace(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -775,8 +775,8 @@ func TestFrontEnd_NvmeNamespaceStats(t *testing.T) { testEnv.opiSpdkServer.Nvme.Namespaces[testNamespaceName] = &testNamespace - request := &pb.NvmeNamespaceStatsRequest{Name: tt.in} - response, err := testEnv.client.NvmeNamespaceStats(testEnv.ctx, request) + request := &pb.StatsNvmeNamespaceRequest{Name: tt.in} + response, err := testEnv.client.StatsNvmeNamespace(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/frontend/nvme_subsystem.go b/pkg/frontend/nvme_subsystem.go index fa399777..e24a1a90 100644 --- a/pkg/frontend/nvme_subsystem.go +++ b/pkg/frontend/nvme_subsystem.go @@ -251,23 +251,23 @@ func (s *Server) GetNvmeSubsystem(_ context.Context, in *pb.GetNvmeSubsystemRequ return nil, status.Errorf(codes.InvalidArgument, msg) } -// NvmeSubsystemStats gets Nvme Subsystem stats -func (s *Server) NvmeSubsystemStats(_ context.Context, in *pb.NvmeSubsystemStatsRequest) (*pb.NvmeSubsystemStatsResponse, error) { - log.Printf("NvmeSubsystemStats: Received from client: %v", in) +// StatsNvmeSubsystem gets Nvme Subsystem stats +func (s *Server) StatsNvmeSubsystem(_ context.Context, in *pb.StatsNvmeSubsystemRequest) (*pb.StatsNvmeSubsystemResponse, error) { + log.Printf("StatsNvmeSubsystem: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.SubsystemNameRef); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Nvme.Subsystems[in.SubsystemNameRef] + volume, ok := s.Nvme.Subsystems[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.SubsystemNameRef) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } @@ -280,5 +280,5 @@ func (s *Server) NvmeSubsystemStats(_ context.Context, in *pb.NvmeSubsystemStats return nil, err } log.Printf("Received from SPDK: %v", result) - return &pb.NvmeSubsystemStatsResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil + return &pb.StatsNvmeSubsystemResponse{Stats: &pb.VolumeStats{ReadOpsCount: -1, WriteOpsCount: -1}}, nil } diff --git a/pkg/frontend/nvme_subsystem_test.go b/pkg/frontend/nvme_subsystem_test.go index 8ee3262b..b6fe96c9 100644 --- a/pkg/frontend/nvme_subsystem_test.go +++ b/pkg/frontend/nvme_subsystem_test.go @@ -681,7 +681,7 @@ func TestFrontEnd_GetNvmeSubsystem(t *testing.T) { } } -func TestFrontEnd_NvmeSubsystemStats(t *testing.T) { +func TestFrontEnd_StatsNvmeSubsystem(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -743,8 +743,8 @@ func TestFrontEnd_NvmeSubsystemStats(t *testing.T) { defer testEnv.Close() testEnv.opiSpdkServer.Nvme.Subsystems[testSubsystemName] = &testSubsystem - request := &pb.NvmeSubsystemStatsRequest{SubsystemNameRef: tt.in} - response, err := testEnv.client.NvmeSubsystemStats(testEnv.ctx, request) + request := &pb.StatsNvmeSubsystemRequest{Name: tt.in} + response, err := testEnv.client.StatsNvmeSubsystem(testEnv.ctx, request) if !proto.Equal(response.GetStats(), tt.out) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/frontend/scsi.go b/pkg/frontend/scsi.go index 9704b2b5..0b74b18a 100644 --- a/pkg/frontend/scsi.go +++ b/pkg/frontend/scsi.go @@ -230,8 +230,8 @@ func (s *Server) GetVirtioScsiController(_ context.Context, in *pb.GetVirtioScsi return &pb.VirtioScsiController{Name: server.ResourceIDToVolumeName(result[0].Ctrlr)}, nil } -// VirtioScsiControllerStats gets a Virtio SCSI controller stats -func (s *Server) VirtioScsiControllerStats(_ context.Context, in *pb.VirtioScsiControllerStatsRequest) (*pb.VirtioScsiControllerStatsResponse, error) { +// StatsVirtioScsiController gets a Virtio SCSI controller stats +func (s *Server) StatsVirtioScsiController(_ context.Context, in *pb.StatsVirtioScsiControllerRequest) (*pb.StatsVirtioScsiControllerResponse, error) { log.Printf("Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { @@ -239,20 +239,20 @@ func (s *Server) VirtioScsiControllerStats(_ context.Context, in *pb.VirtioScsiC return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.ControllerId.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Virt.ScsiCtrls[in.ControllerId.Value] + volume, ok := s.Virt.ScsiCtrls[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.ControllerId.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } resourceID := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", resourceID) - return &pb.VirtioScsiControllerStatsResponse{}, nil + return &pb.StatsVirtioScsiControllerResponse{}, nil } // CreateVirtioScsiLun creates a Virtio SCSI LUN @@ -459,8 +459,8 @@ func (s *Server) GetVirtioScsiLun(_ context.Context, in *pb.GetVirtioScsiLunRequ return &pb.VirtioScsiLun{VolumeId: &pc.ObjectKey{Value: server.ResourceIDToVolumeName(result[0].Ctrlr)}}, nil } -// VirtioScsiLunStats gets a Virtio SCSI LUN stats -func (s *Server) VirtioScsiLunStats(_ context.Context, in *pb.VirtioScsiLunStatsRequest) (*pb.VirtioScsiLunStatsResponse, error) { +// StatsVirtioScsiLun gets a Virtio SCSI LUN stats +func (s *Server) StatsVirtioScsiLun(_ context.Context, in *pb.StatsVirtioScsiLunRequest) (*pb.StatsVirtioScsiLunResponse, error) { log.Printf("Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { @@ -468,18 +468,18 @@ func (s *Server) VirtioScsiLunStats(_ context.Context, in *pb.VirtioScsiLunStats return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.ControllerId.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.Virt.ScsiLuns[in.ControllerId.Value] + volume, ok := s.Virt.ScsiLuns[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.ControllerId.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } resourceID := path.Base(volume.Name) log.Printf("TODO: send name to SPDK and get back stats: %v", resourceID) - return &pb.VirtioScsiLunStatsResponse{}, nil + return &pb.StatsVirtioScsiLunResponse{}, nil } diff --git a/pkg/frontend/scsi_test.go b/pkg/frontend/scsi_test.go index 7a3a425f..ca1efc58 100644 --- a/pkg/frontend/scsi_test.go +++ b/pkg/frontend/scsi_test.go @@ -28,7 +28,7 @@ func TestFrontEnd_GetVirtioScsiController(_ *testing.T) { } -func TestFrontEnd_VirtioScsiControllerStats(_ *testing.T) { +func TestFrontEnd_StatsVirtioScsiController(_ *testing.T) { } @@ -52,6 +52,6 @@ func TestFrontEnd_GetVirtioScsiLun(_ *testing.T) { } -func TestFrontEnd_VirtioScsiLunStats(_ *testing.T) { +func TestFrontEnd_StatsVirtioScsiLun(_ *testing.T) { } diff --git a/pkg/kvm/blk_test.go b/pkg/kvm/blk_test.go index a37f0b99..e61c0919 100644 --- a/pkg/kvm/blk_test.go +++ b/pkg/kvm/blk_test.go @@ -9,7 +9,6 @@ import ( "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/frontend" "github.com/opiproject/opi-spdk-bridge/pkg/server" @@ -22,10 +21,10 @@ var ( testVirtioBlkID = "virtio-blk-42" testVirtioBlkName = server.ResourceIDToVolumeName(testVirtioBlkID) testCreateVirtioBlkRequest = &pb.CreateVirtioBlkRequest{VirtioBlkId: testVirtioBlkID, VirtioBlk: &pb.VirtioBlk{ - Name: "", - PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + Name: "", + PcieId: &pb.PciEndpoint{PhysicalFunction: 42}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }} testDeleteVirtioBlkRequest = &pb.DeleteVirtioBlkRequest{Name: testVirtioBlkName} ) @@ -88,15 +87,15 @@ func TestCreateVirtioBlk(t *testing.T) { }, "valid virtio-blk creation with on first bus location": { in: &pb.CreateVirtioBlkRequest{VirtioBlk: &pb.VirtioBlk{ - PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, VirtioBlkId: testVirtioBlkID}, out: &pb.VirtioBlk{ - Name: testVirtioBlkName, - PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + Name: testVirtioBlkName, + PcieId: &pb.PciEndpoint{PhysicalFunction: 1}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, jsonRPC: alwaysSuccessfulJSONRPC, buses: []string{"pci.opi.0", "pci.opi.1"}, @@ -125,9 +124,9 @@ func TestCreateVirtioBlk(t *testing.T) { }, "negative physical function": { in: &pb.CreateVirtioBlkRequest{VirtioBlk: &pb.VirtioBlk{ - PcieId: &pb.PciEndpoint{PhysicalFunction: -1}, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + PcieId: &pb.PciEndpoint{PhysicalFunction: -1}, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, VirtioBlkId: testVirtioBlkID}, out: nil, errCode: status.Convert(errDeviceEndpoint).Code(), @@ -137,9 +136,9 @@ func TestCreateVirtioBlk(t *testing.T) { }, "nil pcie endpoint": { in: &pb.CreateVirtioBlkRequest{VirtioBlk: &pb.VirtioBlk{ - PcieId: nil, - VolumeId: &pc.ObjectKey{Value: "Malloc42"}, - MaxIoQps: 1, + PcieId: nil, + VolumeNameRef: "Malloc42", + MaxIoQps: 1, }, VirtioBlkId: testVirtioBlkID}, out: nil, errCode: status.Convert(errNoPcieEndpoint).Code(), diff --git a/pkg/middleend/encryption.go b/pkg/middleend/encryption.go index 1f4a18e0..18bed71b 100644 --- a/pkg/middleend/encryption.go +++ b/pkg/middleend/encryption.go @@ -82,7 +82,7 @@ func (s *Server) CreateEncryptedVolume(_ context.Context, in *pb.CreateEncrypted // create bdev now params := spdk.BdevCryptoCreateParams{ Name: resourceID, - BaseBdevName: in.EncryptedVolume.VolumeId.Value, + BaseBdevName: in.EncryptedVolume.VolumeNameRef, KeyName: resourceID, } var result spdk.BdevCryptoCreateResult @@ -230,7 +230,7 @@ func (s *Server) UpdateEncryptedVolume(_ context.Context, in *pb.UpdateEncrypted // create bdev now params3 := spdk.BdevCryptoCreateParams{ Name: resourceID, - BaseBdevName: in.EncryptedVolume.VolumeId.Value, + BaseBdevName: in.EncryptedVolume.VolumeNameRef, KeyName: resourceID, } var result3 spdk.BdevCryptoCreateResult @@ -327,23 +327,23 @@ func (s *Server) GetEncryptedVolume(_ context.Context, in *pb.GetEncryptedVolume return &pb.EncryptedVolume{Name: result[0].Name}, nil } -// EncryptedVolumeStats gets an encrypted volume stats -func (s *Server) EncryptedVolumeStats(_ context.Context, in *pb.EncryptedVolumeStatsRequest) (*pb.EncryptedVolumeStatsResponse, error) { - log.Printf("EncryptedVolumeStats: Received from client: %v", in) +// StatsEncryptedVolume gets an encrypted volume stats +func (s *Server) StatsEncryptedVolume(_ context.Context, in *pb.StatsEncryptedVolumeRequest) (*pb.StatsEncryptedVolumeResponse, error) { + log.Printf("StatsEncryptedVolume: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.EncryptedVolumeId.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.volumes.encVolumes[in.EncryptedVolumeId.Value] + volume, ok := s.volumes.encVolumes[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.EncryptedVolumeId.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } @@ -364,7 +364,7 @@ func (s *Server) EncryptedVolumeStats(_ context.Context, in *pb.EncryptedVolumeS log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.EncryptedVolumeStatsResponse{Stats: &pb.VolumeStats{ + return &pb.StatsEncryptedVolumeResponse{Stats: &pb.VolumeStats{ ReadBytesCount: int32(result.Bdevs[0].BytesRead), ReadOpsCount: int32(result.Bdevs[0].NumReadOps), WriteBytesCount: int32(result.Bdevs[0].BytesWritten), diff --git a/pkg/middleend/encryption_test.go b/pkg/middleend/encryption_test.go index 686f8cc4..70b918bf 100644 --- a/pkg/middleend/encryption_test.go +++ b/pkg/middleend/encryption_test.go @@ -10,7 +10,6 @@ import ( "reflect" "testing" - 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" "google.golang.org/grpc/codes" @@ -123,9 +122,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with AES_XTS_192 cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_192, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_192, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -136,14 +135,14 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "valid request with valid SPDK response and AES_XTS_256 cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), }, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), }, []string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`, `{"id":%d,"error":{"code":0,"message":""},"result":"my_crypto_bdev"}`}, codes.OK, @@ -153,9 +152,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with AES_CBC_128 cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_128, - Key: []byte("0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_128, + Key: []byte("0123456789abcdef"), }, nil, []string{}, @@ -166,9 +165,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with AES_CBC_192 cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_192, - Key: []byte("0123456789abcdef01234567"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_192, + Key: []byte("0123456789abcdef01234567"), }, nil, []string{}, @@ -179,9 +178,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with AES_CBC_256 cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_256, - Key: []byte("0123456789abcdef0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_256, + Key: []byte("0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -192,9 +191,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with unspecified cipher": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_UNSPECIFIED, - Key: []byte("0123456789abcdef0123456789abcdef"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_UNSPECIFIED, + Key: []byte("0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -205,9 +204,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with invalid key size for AES_XTS_128": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, - Key: []byte("1234"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, + Key: []byte("1234"), }, nil, []string{}, @@ -218,9 +217,9 @@ func TestMiddleEnd_CreateEncryptedVolume(t *testing.T) { "invalid request with invalid key size for AES_XTS_256": { encryptedVolumeID, &pb.EncryptedVolume{ - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("1234"), + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("1234"), }, nil, []string{}, @@ -457,10 +456,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use AES_XTS_192 cipher": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_192, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_192, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -471,16 +470,16 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use AES_XTS_256 cipher ; bdev delete ok ; key delete ok ; key create ok ; bdev create ok": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), }, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), }, []string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`, `{"id":%d,"error":{"code":0,"message":""},"result":true}`, `{"id":%d,"error":{"code":0,"message":""},"result":true}`, `{"id":%d,"error":{"code":0,"message":""},"result":"mytest"}`}, codes.OK, @@ -490,10 +489,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use AES_CBC_128 cipher": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_128, - Key: []byte("0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_128, + Key: []byte("0123456789abcdef"), }, nil, []string{}, @@ -504,10 +503,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use AES_CBC_192 cipher": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_192, - Key: []byte("0123456789abcdef01234567"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_192, + Key: []byte("0123456789abcdef01234567"), }, nil, []string{}, @@ -518,10 +517,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use AES_CBC_256 cipher": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_256, - Key: []byte("0123456789abcdef0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_CBC_256, + Key: []byte("0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -532,10 +531,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "use UNSPECIFIED cipher": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_UNSPECIFIED, - Key: []byte("0123456789abcdef0123456789abcdef"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_UNSPECIFIED, + Key: []byte("0123456789abcdef0123456789abcdef"), }, nil, []string{}, @@ -546,10 +545,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "invalid key size for AES_XTS_128": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, - Key: []byte("1234"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, + Key: []byte("1234"), }, nil, []string{}, @@ -560,10 +559,10 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { "invalid key size for AES_XTS_256": { nil, &pb.EncryptedVolume{ - Name: encryptedVolumeID, - VolumeId: encryptedVolume.VolumeId, - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, - Key: []byte("1234"), + Name: encryptedVolumeID, + VolumeNameRef: encryptedVolume.VolumeNameRef, + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_256, + Key: []byte("1234"), }, nil, []string{}, @@ -573,7 +572,7 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) { }, "malformed name": { nil, - &pb.EncryptedVolume{Name: "-ABC-DEF"}, + &pb.EncryptedVolume{Name: "-ABC-DEF", VolumeNameRef: encryptedVolume.VolumeNameRef}, nil, []string{}, codes.Unknown, @@ -891,7 +890,7 @@ func TestMiddleEnd_GetEncryptedVolume(t *testing.T) { } } -func TestMiddleEnd_EncryptedVolumeStats(t *testing.T) { +func TestMiddleEnd_StatsEncryptedVolume(t *testing.T) { tests := map[string]struct { in string out *pb.VolumeStats @@ -973,8 +972,8 @@ func TestMiddleEnd_EncryptedVolumeStats(t *testing.T) { fname1 := server.ResourceIDToVolumeName(tt.in) testEnv.opiSpdkServer.volumes.encVolumes[encryptedVolumeName] = &encryptedVolume - request := &pb.EncryptedVolumeStatsRequest{EncryptedVolumeId: &pc.ObjectKey{Value: fname1}} - response, err := testEnv.client.EncryptedVolumeStats(testEnv.ctx, request) + request := &pb.StatsEncryptedVolumeRequest{Name: fname1} + response, err := testEnv.client.StatsEncryptedVolume(testEnv.ctx, request) if !proto.Equal(tt.out, response.GetStats()) { t.Error("response: expected", tt.out, "received", response.GetStats()) diff --git a/pkg/middleend/middleend_test.go b/pkg/middleend/middleend_test.go index 8f1b8538..80dbb718 100644 --- a/pkg/middleend/middleend_test.go +++ b/pkg/middleend/middleend_test.go @@ -16,7 +16,6 @@ import ( "google.golang.org/grpc/test/bufconn" "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" ) @@ -92,8 +91,8 @@ var ( encryptedVolumeID = "crypto-test" encryptedVolumeName = server.ResourceIDToVolumeName(encryptedVolumeID) encryptedVolume = pb.EncryptedVolume{ - VolumeId: &pc.ObjectKey{Value: "volume-test"}, - Key: []byte("0123456789abcdef0123456789abcdef"), - Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, + VolumeNameRef: "volume-test", + Key: []byte("0123456789abcdef0123456789abcdef"), + Cipher: pb.EncryptionType_ENCRYPTION_TYPE_AES_XTS_128, } ) diff --git a/pkg/middleend/qos.go b/pkg/middleend/qos.go index e3468da7..ba660659 100644 --- a/pkg/middleend/qos.go +++ b/pkg/middleend/qos.go @@ -192,26 +192,26 @@ func (s *Server) GetQosVolume(_ context.Context, in *pb.GetQosVolumeRequest) (*p return volume, nil } -// QosVolumeStats gets a QoS volume stats -func (s *Server) QosVolumeStats(_ context.Context, in *pb.QosVolumeStatsRequest) (*pb.QosVolumeStatsResponse, error) { - log.Printf("QosVolumeStats: Received from client: %v", in) +// StatsQosVolume gets a QoS volume stats +func (s *Server) StatsQosVolume(_ context.Context, in *pb.StatsQosVolumeRequest) (*pb.StatsQosVolumeResponse, error) { + log.Printf("StatsQosVolume: Received from client: %v", in) // check required fields if err := fieldbehavior.ValidateRequiredFields(in); err != nil { log.Printf("error: %v", err) return nil, err } - if in.VolumeId == nil || in.VolumeId.Value == "" { + if in.Name == "" { return nil, status.Error(codes.InvalidArgument, "volume_id cannot be empty") } // Validate that a resource name conforms to the restrictions outlined in AIP-122. - if err := resourcename.Validate(in.VolumeId.Value); err != nil { + if err := resourcename.Validate(in.Name); err != nil { log.Printf("error: %v", err) return nil, err } // fetch object from the database - volume, ok := s.volumes.qosVolumes[in.VolumeId.Value] + volume, ok := s.volumes.qosVolumes[in.Name] if !ok { - err := status.Errorf(codes.NotFound, "unable to find key %s", in.VolumeId.Value) + err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name) log.Printf("error: %v", err) return nil, err } @@ -230,7 +230,7 @@ func (s *Server) QosVolumeStats(_ context.Context, in *pb.QosVolumeStatsRequest) return nil, spdk.ErrUnexpectedSpdkCallResult } - return &pb.QosVolumeStatsResponse{ + return &pb.StatsQosVolumeResponse{ Stats: &pb.VolumeStats{ ReadBytesCount: int32(result.Bdevs[0].BytesRead), ReadOpsCount: int32(result.Bdevs[0].NumReadOps), @@ -241,8 +241,7 @@ func (s *Server) QosVolumeStats(_ context.Context, in *pb.QosVolumeStatsRequest) ReadLatencyTicks: int32(result.Bdevs[0].ReadLatencyTicks), WriteLatencyTicks: int32(result.Bdevs[0].WriteLatencyTicks), UnmapLatencyTicks: int32(result.Bdevs[0].UnmapLatencyTicks), - }, - Id: in.VolumeId}, nil + }}, nil } func (s *Server) verifyQosVolume(volume *pb.QosVolume) error { diff --git a/pkg/middleend/qos_test.go b/pkg/middleend/qos_test.go index 34a13957..edb0b202 100644 --- a/pkg/middleend/qos_test.go +++ b/pkg/middleend/qos_test.go @@ -947,20 +947,20 @@ func TestMiddleEnd_GetQosVolume(t *testing.T) { } } -func TestMiddleEnd_QosVolumeStats(t *testing.T) { +func TestMiddleEnd_StatsQosVolume(t *testing.T) { tests := map[string]struct { in *_go.ObjectKey - out *pb.QosVolumeStatsResponse + out *pb.StatsQosVolumeResponse spdk []string errCode codes.Code errMsg string }{ "empty QoS volume id is not allowed ": { - in: nil, + in: &_go.ObjectKey{Value: ""}, out: nil, spdk: []string{}, - errCode: codes.InvalidArgument, - errMsg: "volume_id cannot be empty", + errCode: codes.Unknown, + errMsg: "missing required field: name", }, "unknown QoS volume Id": { in: &_go.ObjectKey{Value: "unknown-qos-volume-id"}, @@ -985,11 +985,10 @@ func TestMiddleEnd_QosVolumeStats(t *testing.T) { }, "successful QoS volume stats": { in: &_go.ObjectKey{Value: testQosVolumeName}, - out: &pb.QosVolumeStatsResponse{ + out: &pb.StatsQosVolumeResponse{ Stats: &pb.VolumeStats{ ReadBytesCount: 36864, }, - Id: &_go.ObjectKey{Value: testQosVolumeName}, }, spdk: []string{ `{"id":%d,"error":{"code":0,"message":""},"result":{"tick_rate": 3300000000,"ticks": 5,` + @@ -1013,8 +1012,8 @@ func TestMiddleEnd_QosVolumeStats(t *testing.T) { testEnv.opiSpdkServer.volumes.qosVolumes[testQosVolumeName] = testQosVolume - request := &pb.QosVolumeStatsRequest{VolumeId: tt.in} - response, err := testEnv.client.QosVolumeStats(testEnv.ctx, request) + request := &pb.StatsQosVolumeRequest{Name: tt.in.Value} + response, err := testEnv.client.StatsQosVolume(testEnv.ctx, request) if !proto.Equal(tt.out, response) { t.Error("response: expected", tt.out, "received", response)