Skip to content

Commit

Permalink
remove start spdk flag from frontend tests
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 Jul 19, 2023
1 parent bae288a commit 04a6aa7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 253 deletions.
76 changes: 19 additions & 57 deletions pkg/frontend/blk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestFrontEnd_CreateVirtioBlk(t *testing.T) {

for testName, tt := range tests {
t.Run(testName, func(t *testing.T) {
testEnv := createTestEnvironment(true, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

if tt.out != nil {
Expand Down Expand Up @@ -111,7 +111,6 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) {
spdk []string
errCode codes.Code
errMsg string
start bool
missing bool
}{
"invalid fieldmask": {
Expand All @@ -120,23 +119,21 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) {
Name: testVirtioCtrlName,
},
nil,
[]string{""},
[]string{},
codes.Unknown,
fmt.Sprintf("invalid field path: %s", "'*' must not be used with other paths"),
false,
false,
},
"unimplemented method": {
nil,
&pb.VirtioBlk{
Name: testVirtioCtrlName,
},
nil,
[]string{""},
[]string{},
codes.Unimplemented,
fmt.Sprintf("%v method is not implemented", "UpdateVirtioBlk"),
false,
false,
},
"valid request with unknown key": {
nil,
Expand All @@ -147,11 +144,10 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) {
MaxIoQps: 1,
},
nil,
[]string{""},
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
false,
},
"unknown key with missing allowed": {
nil,
Expand All @@ -162,28 +158,26 @@ func TestFrontEnd_UpdateVirtioBlk(t *testing.T) {
MaxIoQps: 1,
},
nil,
[]string{""},
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find key %v", server.ResourceIDToVolumeName("unknown-id")),
false,
true,
},
"malformed name": {
nil,
&pb.VirtioBlk{Name: "-ABC-DEF"},
nil,
[]string{""},
[]string{},
codes.Unknown,
fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
false,
false,
},
}

// run tests
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Virt.BlkCtrls[testVirtioCtrlName] = &testVirtioCtrl
Expand Down Expand Up @@ -216,7 +210,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
spdk []string
errCode codes.Code
errMsg string
start bool
size int32
token string
}{
Expand All @@ -226,7 +219,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":[]}`},
codes.OK,
"",
true,
0,
"",
},
Expand All @@ -236,7 +228,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{""},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "EOF"),
true,
0,
"",
},
Expand All @@ -246,7 +237,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{`{"id":0,"error":{"code":0,"message":""},"result":[]}`},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "json response ID mismatch"),
true,
0,
"",
},
Expand All @@ -256,7 +246,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{`{"id":%d,"error":{"code":1,"message":"myopierr"},"result":[]}`},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "json response error: myopierr"),
true,
0,
"",
},
Expand Down Expand Up @@ -286,7 +275,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
`],"error":{"code":0,"message":""}}`},
codes.OK,
"",
true,
0,
"",
},
Expand All @@ -312,7 +300,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]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":""}}`},
codes.OK,
"",
true,
1000,
"",
},
Expand All @@ -322,7 +309,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{},
codes.InvalidArgument,
"negative PageSize is not allowed",
false,
-10,
"",
},
Expand All @@ -332,7 +318,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find pagination token %s", "unknown-pagination-token"),
false,
0,
"unknown-pagination-token",
},
Expand All @@ -348,7 +333,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]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":""}}`},
codes.OK,
"",
true,
1,
"",
},
Expand All @@ -364,7 +348,6 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
[]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":""}}`},
codes.OK,
"",
true,
1,
"existing-pagination-token",
},
Expand All @@ -373,7 +356,7 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
// run tests
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Pagination["existing-pagination-token"] = 1
Expand Down Expand Up @@ -411,39 +394,34 @@ func TestFrontEnd_GetVirtioBlk(t *testing.T) {
spdk []string
errCode codes.Code
errMsg string
start bool
}{
"valid request with invalid SPDK response": {
testVirtioCtrlName,
nil,
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":[]}`},
codes.InvalidArgument,
fmt.Sprintf("expecting exactly 1 result, got %d", 0),
true,
},
"valid request with empty SPDK response": {
testVirtioCtrlName,
nil,
[]string{""},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "EOF"),
true,
},
"valid request with ID mismatch SPDK response": {
testVirtioCtrlName,
nil,
[]string{`{"id":0,"error":{"code":0,"message":""},"result":[]}`},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "json response ID mismatch"),
true,
},
"valid request with error code from SPDK response": {
testVirtioCtrlName,
nil,
[]string{`{"id":%d,"error":{"code":1,"message":"myopierr"},"result":[]}`},
codes.Unknown,
fmt.Sprintf("vhost_get_controllers: %v", "json response error: myopierr"),
true,
},
"valid request with valid SPDK response": {
testVirtioCtrlName,
Expand All @@ -455,30 +433,27 @@ func TestFrontEnd_GetVirtioBlk(t *testing.T) {
[]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,
"",
true,
},
"valid request with unknown key": {
"unknown-id",
nil,
[]string{""},
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "unknown-id"),
false,
},
"malformed name": {
"-ABC-DEF",
nil,
[]string{""},
[]string{},
codes.Unknown,
fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
false,
},
}

// run tests
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Virt.BlkCtrls[testVirtioCtrlName] = &testVirtioCtrl
Expand Down Expand Up @@ -512,38 +487,34 @@ func TestFrontEnd_VirtioBlkStats(t *testing.T) {
spdk []string
errCode codes.Code
errMsg string
start bool
}{
"unimplemented method": {
testVirtioCtrlID,
nil,
[]string{""},
[]string{},
codes.Unimplemented,
fmt.Sprintf("%v method is not implemented", "VirtioBlkStats"),
false,
},
"valid request with unknown key": {
"unknown-id",
nil,
[]string{""},
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "unknown-id"),
false,
},
"malformed name": {
"-ABC-DEF",
nil,
[]string{""},
[]string{},
codes.Unknown,
fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
false,
},
}

// run tests
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Virt.BlkCtrls[testVirtioCtrlID] = &testVirtioCtrl
Expand Down Expand Up @@ -576,7 +547,6 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
spdk []string
errCode codes.Code
errMsg string
start bool
missing bool
}{
"valid request with invalid SPDK response": {
Expand All @@ -585,7 +555,6 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":false}`},
codes.InvalidArgument,
fmt.Sprintf("Could not delete virtio-blk: %s", testVirtioCtrlID),
true,
false,
},
"valid request with empty SPDK response": {
Expand All @@ -594,7 +563,6 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
[]string{""},
codes.Unknown,
fmt.Sprintf("vhost_delete_controller: %v", "EOF"),
true,
false,
},
"valid request with ID mismatch SPDK response": {
Expand All @@ -603,7 +571,6 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
[]string{`{"id":0,"error":{"code":0,"message":""},"result":false}`},
codes.Unknown,
fmt.Sprintf("vhost_delete_controller: %v", "json response ID mismatch"),
true,
false,
},
"valid request with error code from SPDK response": {
Expand All @@ -612,7 +579,6 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
[]string{`{"id":%d,"error":{"code":1,"message":"myopierr"},"result":false}`},
codes.Unknown,
fmt.Sprintf("vhost_delete_controller: %v", "json response error: myopierr"),
true,
false,
},
"valid request with valid SPDK response": {
Expand All @@ -621,42 +587,38 @@ func TestFrontEnd_DeleteVirtioBlk(t *testing.T) {
[]string{`{"id":%d,"error":{"code":0,"message":""},"result":true}`}, // `{"jsonrpc": "2.0", "id": 1, "result": True}`,
codes.OK,
"",
true,
false,
},
"valid request with unknown key": {
"unknown-id",
nil,
[]string{""},
[]string{},
codes.NotFound,
fmt.Sprintf("unable to find key %v", "unknown-id"),
false,
false,
},
"unknown key with missing allowed": {
"unknown-id",
&emptypb.Empty{},
[]string{""},
[]string{},
codes.OK,
"",
false,
true,
},
"malformed name": {
"-ABC-DEF",
&emptypb.Empty{},
[]string{""},
[]string{},
codes.Unknown,
fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
false,
false,
},
}

// run tests
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
testEnv := createTestEnvironment(tt.start, tt.spdk)
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Virt.BlkCtrls[testVirtioCtrlID] = &testVirtioCtrl
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (e *testEnv) Close() {
}
}

func createTestEnvironment(startSpdkServer bool, spdkResponses []string) *testEnv {
func createTestEnvironment(spdkResponses []string) *testEnv {
env := &testEnv{}
env.testSocket = server.GenerateSocketName("frontend")
env.ln, env.jsonRPC = server.CreateTestSpdkServer(env.testSocket, spdkResponses)
Expand Down
Loading

0 comments on commit 04a6aa7

Please sign in to comment.