From 79ddbe8ed41bc369e0fe7827f2f022b59df05ec8 Mon Sep 17 00:00:00 2001 From: Artsiom Koltun Date: Tue, 31 Oct 2023 14:42:00 +0100 Subject: [PATCH] feat(storage): run tests for a part of frontend partition Signed-off-by: Artsiom Koltun --- cmd/storage-test.go | 44 ++++++++++++++++++++++- storage/frontend.go | 88 +++++++++++++++++++++++++++++++-------------- 2 files changed, 104 insertions(+), 28 deletions(-) diff --git a/cmd/storage-test.go b/cmd/storage-test.go index 273264a..27d4136 100644 --- a/cmd/storage-test.go +++ b/cmd/storage-test.go @@ -38,6 +38,7 @@ func newStorageTestCommand() *cobra.Command { runTests( c, allStoragePartitions, + storage.AllFrontendPartitions, ) }, } @@ -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 } @@ -74,6 +113,7 @@ func newStorageTestBackendCommand() *cobra.Command { runTests( c, []storagePartition{storagePartitionBackend}, + nil, ) }, } @@ -90,6 +130,7 @@ func newStorageTestMiddleendCommand() *cobra.Command { runTests( c, []storagePartition{storagePartitionMiddleend}, + nil, ) }, } @@ -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 { @@ -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: diff --git a/storage/frontend.go b/storage/frontend.go index 2229768..183cc25 100644 --- a/storage/frontend.go +++ b/storage/frontend.go @@ -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 @@ -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 }