Skip to content

Commit

Permalink
feat(storage): run tests for a part of frontend partition
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <artsiom.koltun@intel.com>
  • Loading branch information
artek-koltun authored and sandersms committed Jan 11, 2024
1 parent cd0d2a3 commit 79ddbe8
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 28 deletions.
44 changes: 43 additions & 1 deletion cmd/storage-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func newStorageTestCommand() *cobra.Command {
runTests(
c,
allStoragePartitions,
storage.AllFrontendPartitions,
)
},
}
Expand All @@ -58,10 +59,48 @@ func newStorageTestFrontendCommand() *cobra.Command {
runTests(
c,
[]storagePartition{storagePartitionFrontend},
storage.AllFrontendPartitions,
)
},
}

cmd.AddCommand(&cobra.Command{
Use: "nvme",
Short: "Tests storage frontend nvme API",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
runTests(
c,
[]storagePartition{storagePartitionFrontend},
[]storage.FrontendPartition{storage.FrontendPartitionNvme},
)
},
})
cmd.AddCommand(&cobra.Command{
Use: "virtio-blk",
Short: "Tests storage frontend virtio-blk API",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
runTests(
c,
[]storagePartition{storagePartitionFrontend},
[]storage.FrontendPartition{storage.FrontendPartitionVirtioBlk},
)
},
})
cmd.AddCommand(&cobra.Command{
Use: "scsi",
Short: "Tests storage frontend scsi API",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
runTests(
c,
[]storagePartition{storagePartitionFrontend},
[]storage.FrontendPartition{storage.FrontendPartitionScsi},
)
},
})

return cmd
}

Expand All @@ -74,6 +113,7 @@ func newStorageTestBackendCommand() *cobra.Command {
runTests(
c,
[]storagePartition{storagePartitionBackend},
nil,
)
},
}
Expand All @@ -90,6 +130,7 @@ func newStorageTestMiddleendCommand() *cobra.Command {
runTests(
c,
[]storagePartition{storagePartitionMiddleend},
nil,
)
},
}
Expand All @@ -100,6 +141,7 @@ func newStorageTestMiddleendCommand() *cobra.Command {
func runTests(
cmd *cobra.Command,
partitions []storagePartition,
frontendPartitions []storage.FrontendPartition,
) {
addr, err := cmd.Flags().GetString(addrCmdLineArg)
if err != nil {
Expand Down Expand Up @@ -135,7 +177,7 @@ func runTests(
var err error
switch partition {
case storagePartitionFrontend:
err = storage.DoFrontend(ctx, conn)
err = storage.DoFrontend(ctx, conn, frontendPartitions)
case storagePartitionBackend:
err = storage.DoBackend(ctx, conn)
case storagePartitionMiddleend:
Expand Down
88 changes: 61 additions & 27 deletions storage/frontend.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (C) 2023 Intel Corporation

// Package storage implements the go library for OPI to be used in storage, for example, CSI drivers
package storage
Expand All @@ -21,36 +22,69 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)

// FrontendPartition defines frontend API partition type
type FrontendPartition int

// Enumerates all frontend API partitions
const (
FrontendPartitionNvme FrontendPartition = iota + 1
FrontendPartitionVirtioBlk
FrontendPartitionScsi
)

// AllFrontendPartitions contains partitions to test entire frontend API
var AllFrontendPartitions = []FrontendPartition{
FrontendPartitionNvme,
FrontendPartitionVirtioBlk,
FrontendPartitionScsi,
}

// DoFrontend executes the front end code
func DoFrontend(ctx context.Context, conn grpc.ClientConnInterface) error {
nvme := pb.NewFrontendNvmeServiceClient(conn)
blk := pb.NewFrontendVirtioBlkServiceClient(conn)
scsi := pb.NewFrontendVirtioScsiServiceClient(conn)
func DoFrontend(
ctx context.Context,
conn grpc.ClientConnInterface,
partitionsToTest []FrontendPartition,
) error {
for _, partition := range partitionsToTest {
switch partition {
case FrontendPartitionNvme:
nvme := pb.NewFrontendNvmeServiceClient(conn)
err := executeNvmeSubsystem(ctx, nvme)
if err != nil {
return err
}
err = executeNvmeController(ctx, nvme)
if err != nil {
return err
}
err = executeNvmeNamespace(ctx, nvme)
if err != nil {
return err
}

err := executeNvmeSubsystem(ctx, nvme)
if err != nil {
return err
}
err = executeNvmeController(ctx, nvme)
if err != nil {
return err
}
err = executeNvmeNamespace(ctx, nvme)
if err != nil {
return err
}
err = executeVirtioBlk(ctx, blk)
if err != nil {
return err
}
err = executeVirtioScsiController(ctx, scsi)
if err != nil {
return err
}
err = executeVirtioScsiLun(ctx, scsi)
if err != nil {
return err
case FrontendPartitionVirtioBlk:
blk := pb.NewFrontendVirtioBlkServiceClient(conn)
err := executeVirtioBlk(ctx, blk)
if err != nil {
return err
}

case FrontendPartitionScsi:
scsi := pb.NewFrontendVirtioScsiServiceClient(conn)
err := executeVirtioScsiController(ctx, scsi)
if err != nil {
return err
}
err = executeVirtioScsiLun(ctx, scsi)
if err != nil {
return err
}

default:
return fmt.Errorf("unknown storage frontend partition: %v", partition)
}
}

return nil
}

Expand Down

0 comments on commit 79ddbe8

Please sign in to comment.