Skip to content

Commit

Permalink
Move name volume construction into function.
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun authored and glimchb committed Jun 5, 2023
1 parent f8ecca3 commit 021e9f6
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pkg/backend/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Server) CreateAioController(_ context.Context, in *pb.CreateAioControll
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.AioControllerId, in.AioController.Name)
resourceID = in.AioControllerId
}
in.AioController.Name = fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
in.AioController.Name = server.ResourceIDToVolumeName(resourceID)
// idempotent API when called with same key, should return same object
volume, ok := s.Volumes.AioVolumes[in.AioController.Name]
if ok {
Expand Down
11 changes: 6 additions & 5 deletions pkg/backend/aio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ 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/server"
)

var (
testAioVolumeID = "mytest"
testAioVolumeName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testAioVolumeID)
testAioVolumeName = server.ResourceIDToVolumeName(testAioVolumeID)
testAioVolume = pb.AioController{
BlockSize: 512,
BlocksCount: 12,
Expand Down Expand Up @@ -219,15 +220,15 @@ func TestBackEnd_UpdateAioController(t *testing.T) {
},
"valid request with unknown key": {
&pb.AioController{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
BlockSize: 512,
BlocksCount: 12,
Filename: "/tmp/aio_bdev_file",
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down Expand Up @@ -726,7 +727,7 @@ func TestBackEnd_DeleteAioController(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
false,
},
Expand All @@ -747,7 +748,7 @@ func TestBackEnd_DeleteAioController(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.Volumes.AioVolumes[testAioVolumeName] = &testAioVolume

request := &pb.DeleteAioControllerRequest{Name: fname1, AllowMissing: tt.missing}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Server) CreateNullDebug(_ context.Context, in *pb.CreateNullDebugReques
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NullDebugId, in.NullDebug.Name)
resourceID = in.NullDebugId
}
in.NullDebug.Name = fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
in.NullDebug.Name = server.ResourceIDToVolumeName(resourceID)
// idempotent API when called with same key, should return same object
volume, ok := s.Volumes.NullVolumes[in.NullDebug.Name]
if ok {
Expand Down
11 changes: 6 additions & 5 deletions pkg/backend/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ 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/server"
)

var (
testNullVolumeID = "mytest"
testNullVolumeName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testNullVolumeID)
testNullVolumeName = server.ResourceIDToVolumeName(testNullVolumeID)
testNullVolume = pb.NullDebug{
BlockSize: 512,
BlocksCount: 64,
Expand Down Expand Up @@ -218,14 +219,14 @@ func TestBackEnd_UpdateNullDebug(t *testing.T) {
},
"valid request with unknown key": {
&pb.NullDebug{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
BlockSize: 512,
BlocksCount: 64,
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down Expand Up @@ -736,7 +737,7 @@ func TestBackEnd_DeleteNullDebug(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
false,
},
Expand All @@ -757,7 +758,7 @@ func TestBackEnd_DeleteNullDebug(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.Volumes.NullVolumes[testNullVolumeName] = &testNullVolume

request := &pb.DeleteNullDebugRequest{Name: fname1, AllowMissing: tt.missing}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Server) CreateNVMfRemoteController(_ context.Context, in *pb.CreateNVMf
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvMfRemoteControllerId, in.NvMfRemoteController.Name)
resourceID = in.NvMfRemoteControllerId
}
in.NvMfRemoteController.Name = fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
in.NvMfRemoteController.Name = server.ResourceIDToVolumeName(resourceID)
// idempotent API when called with same key, should return same object
volume, ok := s.Volumes.NvmeVolumes[in.NvMfRemoteController.Name]
if ok {
Expand Down
7 changes: 4 additions & 3 deletions pkg/backend/nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ 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/server"
)

var (
controllerID = "OpiNvme8"
controllerName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", controllerID)
controllerName = server.ResourceIDToVolumeName(controllerID)
controller = pb.NVMfRemoteController{
Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TCP,
Adrfam: pb.NvmeAddressFamily_NVMF_ADRFAM_IPV4,
Expand Down Expand Up @@ -643,7 +644,7 @@ func TestBackEnd_DeleteNVMfRemoteController(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
false,
},
Expand All @@ -664,7 +665,7 @@ func TestBackEnd_DeleteNVMfRemoteController(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.Volumes.NvmeVolumes[controllerName] = &controller

request := &pb.DeleteNVMfRemoteControllerRequest{Name: fname1, AllowMissing: tt.missing}
Expand Down
7 changes: 4 additions & 3 deletions pkg/frontend/blk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"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"
)

var (
testVirtioCtrlID = "virtio-blk-42"
testVirtioCtrName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testVirtioCtrlID)
testVirtioCtrName = server.ResourceIDToVolumeName(testVirtioCtrlID)
testVirtioCtrl = pb.VirtioBlk{
PcieId: &pb.PciEndpoint{PhysicalFunction: 42},
VolumeId: &pc.ObjectKey{Value: "Malloc42"},
Expand Down Expand Up @@ -115,15 +116,15 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) {
},
"valid request with unknown key": {
&pb.VirtioBlk{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
PcieId: &pb.PciEndpoint{PhysicalFunction: 42},
VolumeId: &pc.ObjectKey{Value: "Malloc42"},
MaxIoQps: 1,
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/frontend/nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ 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/server"
)

var (
testSubsystemID = "subsystem-test"
testSubsystemName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testSubsystemID)
testSubsystemName = server.ResourceIDToVolumeName(testSubsystemID)
testSubsystem = pb.NvmeSubsystem{
Spec: &pb.NvmeSubsystemSpec{
Nqn: "nqn.2022-09.io.spdk:opi3",
},
}
testControllerID = "controller-test"
testControllerName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testControllerID)
testControllerName = server.ResourceIDToVolumeName(testControllerID)
testController = pb.NvmeController{
Spec: &pb.NvmeControllerSpec{
SubsystemId: &pc.ObjectKey{Value: testSubsystemID},
Expand All @@ -43,7 +44,7 @@ var (
},
}
testNamespaceID = "namespace-test"
testNamespaceName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", testNamespaceID)
testNamespaceName = server.ResourceIDToVolumeName(testNamespaceID)
testNamespace = pb.NvmeNamespace{
Spec: &pb.NvmeNamespaceSpec{
HostNsid: 22,
Expand Down Expand Up @@ -215,15 +216,15 @@ func TestFrontEnd_UpdateNvmeSubsystem(t *testing.T) {
},
"valid request with unknown key": {
&pb.NvmeSubsystem{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
Spec: &pb.NvmeSubsystemSpec{
Nqn: "nqn.2022-09.io.spdk:opi3",
},
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down Expand Up @@ -804,13 +805,13 @@ func TestFrontEnd_UpdateNvmeController(t *testing.T) {
},
"valid request with unknown key": {
&pb.NvmeController{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
Spec: spec,
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down Expand Up @@ -1244,13 +1245,13 @@ func TestFrontEnd_UpdateNvmeNamespace(t *testing.T) {
},
"valid request with unknown key": {
&pb.NvmeNamespace{
Name: "//storage.opiproject.org/volumes/unknown-id",
Name: server.ResourceIDToVolumeName("unknown-id"),
Spec: spec,
},
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/middleend/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Server) CreateEncryptedVolume(_ context.Context, in *pb.CreateEncrypted
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.EncryptedVolumeId, in.EncryptedVolume.Name)
resourceID = in.EncryptedVolumeId
}
in.EncryptedVolume.Name = fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
in.EncryptedVolume.Name = server.ResourceIDToVolumeName(resourceID)

if err := s.verifyEncryptedVolume(in.EncryptedVolume); err != nil {
log.Printf("error: %v", err)
Expand Down
13 changes: 7 additions & 6 deletions pkg/middleend/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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/server"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -809,7 +810,7 @@ func TestMiddleEnd_GetEncryptedVolume(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand All @@ -820,7 +821,7 @@ func TestMiddleEnd_GetEncryptedVolume(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.volumes.encVolumes[encryptedVolumeName] = &encryptedVolume

request := &pb.GetEncryptedVolumeRequest{Name: fname1}
Expand Down Expand Up @@ -915,7 +916,7 @@ func TestMiddleEnd_EncryptedVolumeStats(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
},
}
Expand All @@ -926,7 +927,7 @@ func TestMiddleEnd_EncryptedVolumeStats(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.volumes.encVolumes[encryptedVolumeName] = &encryptedVolume

request := &pb.EncryptedVolumeStatsRequest{EncryptedVolumeId: &pc.ObjectKey{Value: fname1}}
Expand Down Expand Up @@ -1038,7 +1039,7 @@ func TestMiddleEnd_DeleteEncryptedVolume(t *testing.T) {
nil,
[]string{""},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "//storage.opiproject.org/volumes/unknown-id"),
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
false,
},
Expand All @@ -1059,7 +1060,7 @@ func TestMiddleEnd_DeleteEncryptedVolume(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
defer testEnv.Close()

fname1 := fmt.Sprintf("//storage.opiproject.org/volumes/%s", tt.in)
fname1 := server.ResourceIDToVolumeName(tt.in)
testEnv.opiSpdkServer.volumes.encVolumes[encryptedVolumeName] = &encryptedVolume

request := &pb.DeleteEncryptedVolumeRequest{Name: fname1, AllowMissing: tt.missing}
Expand Down
3 changes: 1 addition & 2 deletions pkg/middleend/middleend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package middleend

import (
"context"
"fmt"
"log"
"net"
"os"
Expand Down Expand Up @@ -91,7 +90,7 @@ func dialer(opiSpdkServer *Server) func(context.Context, string) (net.Conn, erro

var (
encryptedVolumeID = "crypto-test"
encryptedVolumeName = fmt.Sprintf("//storage.opiproject.org/volumes/%s", encryptedVolumeID)
encryptedVolumeName = server.ResourceIDToVolumeName(encryptedVolumeID)
encryptedVolume = pb.EncryptedVolume{
VolumeId: &pc.ObjectKey{Value: "volume-test"},
Key: []byte("0123456789abcdef0123456789abcdef"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/middleend/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *Server) CreateQosVolume(_ context.Context, in *pb.CreateQosVolumeReques
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.QosVolumeId, in.QosVolume.Name)
resourceID = in.QosVolumeId
}
in.QosVolume.Name = fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
in.QosVolume.Name = server.ResourceIDToVolumeName(resourceID)

if err := s.verifyQosVolume(in.QosVolume); err != nil {
log.Println("error:", err)
Expand Down
Loading

0 comments on commit 021e9f6

Please sign in to comment.