Skip to content

Commit

Permalink
Test QoS on virtio-blk creation.
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun committed Jun 2, 2023
1 parent cff728e commit 5bfe3ef
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions pkg/frontend/blk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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"
)

type stubQosProvider struct {
Expand All @@ -42,38 +43,69 @@ var (
VolumeId: &pc.ObjectKey{Value: "Malloc42"},
MaxIoQps: 1,
}
testVirtioCtrlWithQos = pb.VirtioBlk{
PcieId: &pb.PciEndpoint{PhysicalFunction: 42},
VolumeId: &pc.ObjectKey{Value: "Malloc42"},
MaxIoQps: 1,
MaxLimit: &pb.QosLimit{
RwBandwidthMbs: 1,
},
}
)

func TestFrontEnd_CreateVirtioBlk(t *testing.T) {
tests := map[string]struct {
in *pb.VirtioBlk
out *pb.VirtioBlk
spdk []string
expectedErr error
in *pb.VirtioBlk
out *pb.VirtioBlk
spdk []string
expectedErr error
qosCreateErr error
}{
"valid virtio-blk creation": {
in: &testVirtioCtrl,
out: &testVirtioCtrl,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`},
expectedErr: status.Error(codes.OK, ""),
in: &testVirtioCtrl,
out: &testVirtioCtrl,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`},
expectedErr: status.Error(codes.OK, ""),
qosCreateErr: nil,
},
"spdk virtio-blk creation error": {
in: &testVirtioCtrl,
out: nil,
spdk: []string{`{"id":%d,"error":{"code":1,"message":"some internal error"},"result":false}`},
expectedErr: spdk.ErrFailedSpdkCall,
in: &testVirtioCtrl,
out: nil,
spdk: []string{`{"id":%d,"error":{"code":1,"message":"some internal error"},"result":false}`},
expectedErr: spdk.ErrFailedSpdkCall,
qosCreateErr: nil,
},
"spdk virtio-blk creation returned false response with no error": {
in: &testVirtioCtrl,
out: nil,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":false}`},
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
in: &testVirtioCtrl,
out: nil,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":false}`},
expectedErr: spdk.ErrUnexpectedSpdkCallResult,
qosCreateErr: nil,
},
"valid virtio-blk creation with qos limits": {
in: &testVirtioCtrlWithQos,
out: &testVirtioCtrlWithQos,
spdk: []string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`},
expectedErr: status.Error(codes.OK, ""),
qosCreateErr: nil,
},
"valid virtio-blk creation with qos limits failure": {
in: &testVirtioCtrlWithQos,
out: nil,
spdk: []string{},
expectedErr: status.Error(codes.InvalidArgument, "invalid argument"),
qosCreateErr: status.Error(codes.InvalidArgument, "invalid argument"),
},
}

for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
testEnv := createTestEnvironment(true, test.spdk)
test.in = server.ProtoClone(test.in)
test.out = server.ProtoClone(test.out)

testEnv := createTestEnvironmentWithVirtioBlkQosProvider(
true, test.spdk, stubQosProvider{test.qosCreateErr},
)
defer testEnv.Close()

if test.out != nil {
Expand Down

0 comments on commit 5bfe3ef

Please sign in to comment.