Skip to content

Commit

Permalink
refactor: funs moved to utils pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb authored and artek-koltun committed Oct 5, 2023
1 parent 0afa814 commit c428fea
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 37 deletions.
7 changes: 3 additions & 4 deletions pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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/utils"
)

Expand Down Expand Up @@ -95,7 +94,7 @@ func dialer(opiSpdkServer *Server) func(context.Context, string) (net.Conn, erro

var (
testSubsystemID = "subsystem-test"
testSubsystemName = frontend.ResourceIDToSubsystemName(testSubsystemID)
testSubsystemName = utils.ResourceIDToSubsystemName(testSubsystemID)
testSubsystem = pb.NvmeSubsystem{
Spec: &pb.NvmeSubsystemSpec{
Nqn: "nqn.2022-09.io.spdk:opi3",
Expand All @@ -110,7 +109,7 @@ var (
}

testControllerID = "controller-test"
testControllerName = frontend.ResourceIDToControllerName(testSubsystemID, testControllerID)
testControllerName = utils.ResourceIDToControllerName(testSubsystemID, testControllerID)
testController = pb.NvmeController{
Spec: &pb.NvmeControllerSpec{
Endpoint: &pb.NvmeControllerSpec_PcieId{
Expand All @@ -133,7 +132,7 @@ var (
}

testNamespaceID = "namespace-test"
testNamespaceName = frontend.ResourceIDToNamespaceName(testSubsystemID, testNamespaceID)
testNamespaceName = utils.ResourceIDToNamespaceName(testSubsystemID, testNamespaceID)
testNamespace = pb.NvmeNamespace{
Spec: &pb.NvmeNamespaceSpec{
HostNsid: 22,
Expand Down
9 changes: 4 additions & 5 deletions pkg/frontend/nvme_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

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

"github.com/google/uuid"
Expand Down Expand Up @@ -46,8 +45,8 @@ func (s *Server) CreateNvmeController(_ context.Context, in *pb.CreateNvmeContro
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeControllerId, in.NvmeController.Name)
resourceID = in.NvmeControllerId
}
in.NvmeController.Name = frontend.ResourceIDToControllerName(
frontend.GetSubsystemIDFromNvmeName(in.Parent), resourceID,
in.NvmeController.Name = utils.ResourceIDToControllerName(
utils.GetSubsystemIDFromNvmeName(in.Parent), resourceID,
)
// idempotent API when called with same key, should return same object
controller, ok := s.Controllers[in.NvmeController.Name]
Expand Down Expand Up @@ -101,8 +100,8 @@ func (s *Server) DeleteNvmeController(_ context.Context, in *pb.DeleteNvmeContro
}
return nil, fmt.Errorf("error finding controller %s", in.Name)
}
subsysName := frontend.ResourceIDToSubsystemName(
frontend.GetSubsystemIDFromNvmeName(in.Name),
subsysName := utils.ResourceIDToSubsystemName(
utils.GetSubsystemIDFromNvmeName(in.Name),
)
subsys, ok := s.Subsystems[subsysName]
if !ok {
Expand Down
13 changes: 6 additions & 7 deletions pkg/frontend/nvme_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"google.golang.org/protobuf/types/known/fieldmaskpb"

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/utils"
)

Expand Down Expand Up @@ -419,13 +418,13 @@ func TestFrontEnd_UpdateNvmeController(t *testing.T) {
"valid request with unknown key": {
mask: nil,
in: &pb.NvmeController{
Name: frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
Name: utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
Spec: testController.Spec,
},
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
},
"malformed name": {
mask: nil,
Expand Down Expand Up @@ -617,11 +616,11 @@ func TestFrontEnd_ListNvmeControllers(t *testing.T) {
token: "",
},
"valid request with unknown key": {
in: frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
in: utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
size: 0,
token: "",
},
Expand Down Expand Up @@ -725,11 +724,11 @@ func TestFrontEnd_GetNvmeController(t *testing.T) {
errMsg: "",
},
"valid request with unknown key": {
in: frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
in: utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id"),
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToControllerName(testSubsystemID, "unknown-controller-id")),
},
"malformed name": {
in: "-ABC-DEF",
Expand Down
13 changes: 6 additions & 7 deletions pkg/frontend/nvme_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

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

"github.com/google/uuid"
Expand Down Expand Up @@ -46,8 +45,8 @@ func (s *Server) CreateNvmeNamespace(_ context.Context, in *pb.CreateNvmeNamespa
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeNamespaceId, in.NvmeNamespace.Name)
resourceID = in.NvmeNamespaceId
}
in.NvmeNamespace.Name = frontend.ResourceIDToNamespaceName(
frontend.GetSubsystemIDFromNvmeName(in.Parent), resourceID,
in.NvmeNamespace.Name = utils.ResourceIDToNamespaceName(
utils.GetSubsystemIDFromNvmeName(in.Parent), resourceID,
)
// idempotent API when called with same key, should return same object
namespace, ok := s.Namespaces[in.NvmeNamespace.Name]
Expand Down Expand Up @@ -103,8 +102,8 @@ func (s *Server) DeleteNvmeNamespace(_ context.Context, in *pb.DeleteNvmeNamespa
err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name)
return nil, err
}
subsysName := frontend.ResourceIDToSubsystemName(
frontend.GetSubsystemIDFromNvmeName(in.Name),
subsysName := utils.ResourceIDToSubsystemName(
utils.GetSubsystemIDFromNvmeName(in.Name),
)
subsys, ok := s.Subsystems[subsysName]
if !ok {
Expand Down Expand Up @@ -211,8 +210,8 @@ func (s *Server) GetNvmeNamespace(_ context.Context, in *pb.GetNvmeNamespaceRequ
err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name)
return nil, err
}
subsysName := frontend.ResourceIDToSubsystemName(
frontend.GetSubsystemIDFromNvmeName(in.Name),
subsysName := utils.ResourceIDToSubsystemName(
utils.GetSubsystemIDFromNvmeName(in.Name),
)
subsys, ok := s.Subsystems[subsysName]
if !ok {
Expand Down
13 changes: 6 additions & 7 deletions pkg/frontend/nvme_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

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/utils"
)

Expand Down Expand Up @@ -387,13 +386,13 @@ func TestFrontEnd_UpdateNvmeNamespace(t *testing.T) {
"valid request with unknown key": {
mask: nil,
in: &pb.NvmeNamespace{
Name: frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
Name: utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
Spec: testNamespace.Spec,
},
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
},
"malformed name": {
mask: nil,
Expand Down Expand Up @@ -594,11 +593,11 @@ func TestFrontEnd_ListNvmeNamespaces(t *testing.T) {
token: "",
},
"valid request with unknown key": {
in: frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
in: utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
size: 0,
token: "",
},
Expand Down Expand Up @@ -710,11 +709,11 @@ func TestFrontEnd_GetNvmeNamespace(t *testing.T) {
errMsg: "",
},
"valid request with unknown key": {
in: frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
in: utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id"),
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToNamespaceName(testSubsystemID, "unknown-namespace-id")),
},
"malformed name": {
in: "-ABC-DEF",
Expand Down
3 changes: 1 addition & 2 deletions pkg/frontend/nvme_subsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

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

"github.com/google/uuid"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (s *Server) CreateNvmeSubsystem(_ context.Context, in *pb.CreateNvmeSubsyst
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeSubsystemId, in.NvmeSubsystem.Name)
resourceID = in.NvmeSubsystemId
}
in.NvmeSubsystem.Name = frontend.ResourceIDToSubsystemName(resourceID)
in.NvmeSubsystem.Name = utils.ResourceIDToSubsystemName(resourceID)
// idempotent API when called with same key, should return same object
subsys, ok := s.Subsystems[in.NvmeSubsystem.Name]
if ok {
Expand Down
9 changes: 4 additions & 5 deletions pkg/frontend/nvme_subsystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"google.golang.org/protobuf/types/known/fieldmaskpb"

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/utils"
)

Expand Down Expand Up @@ -387,15 +386,15 @@ func TestFrontEnd_UpdateNvmeSubsystem(t *testing.T) {
"valid request with unknown key": {
mask: nil,
in: &pb.NvmeSubsystem{
Name: frontend.ResourceIDToSubsystemName("unknown-subsystem-id"),
Name: utils.ResourceIDToSubsystemName("unknown-subsystem-id"),
Spec: &pb.NvmeSubsystemSpec{
Nqn: "nqn.2022-09.io.spdk:opi3",
},
},
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToSubsystemName("unknown-subsystem-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToSubsystemName("unknown-subsystem-id")),
},
"malformed name": {
mask: nil,
Expand Down Expand Up @@ -687,11 +686,11 @@ func TestFrontEnd_GetNvmeSubsystem(t *testing.T) {
errMsg: "",
},
"valid request with unknown key": {
in: frontend.ResourceIDToSubsystemName("unknown-subsystem-id"),
in: utils.ResourceIDToSubsystemName("unknown-subsystem-id"),
out: nil,
spdk: []string{},
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", frontend.ResourceIDToSubsystemName("unknown-subsystem-id")),
errMsg: fmt.Sprintf("unable to find key %v", utils.ResourceIDToSubsystemName("unknown-subsystem-id")),
},
"malformed name": {
in: "-ABC-DEF",
Expand Down

0 comments on commit c428fea

Please sign in to comment.