Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions cmd/csi-sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ const (
)

var (
VERSION = "(dev)"
endpoint string
mountDir string
version bool
VERSION = "(dev)"
version bool
config sanity.Config
)

func init() {
flag.StringVar(&endpoint, prefix+"endpoint", "", "CSI endpoint")
flag.StringVar(&config.Address, prefix+"endpoint", "", "CSI endpoint")
flag.BoolVar(&version, prefix+"version", false, "Version of this program")
flag.StringVar(&mountDir, prefix+"mountdir", os.TempDir()+"/csi", "Mount point for NodePublish")
flag.StringVar(&config.TargetPath, prefix+"mountdir", os.TempDir()+"/csi", "Mount point for NodePublish")
flag.StringVar(&config.StagingPath, prefix+"stagingdir", os.TempDir()+"/csi", "Mount point for NodeStage if staging is supported")
flag.Parse()
}

Expand All @@ -47,8 +47,9 @@ func TestSanity(t *testing.T) {
fmt.Printf("Version = %s\n", VERSION)
return
}
if len(endpoint) == 0 {
fmt.Println(config)
if len(config.Address) == 0 {
t.Fatalf("--%sendpoint must be provided with an CSI endpoint", prefix)
}
sanity.Test(t, endpoint, mountDir)
sanity.Test(t, &config)
}
28 changes: 0 additions & 28 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,34 +381,6 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
})
Expect(err).NotTo(HaveOccurred())
})
It("should fail when requesting to create a volume exceeding Maximum Capacity", func() {

By("creating a volume")
name := "sanity"
size := int64(10 * 1024 * 1024 * 1024 * 1024)
_, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
})
Expect(err).To(HaveOccurred())
serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.OutOfRange))
})
})

var _ = Describe("DeleteVolume [Controller Server]", func() {
Expand Down
20 changes: 14 additions & 6 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
s,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
if nodeStageSupported {
err := createMountTargetLocation(config.StagingPath)
Expect(err).NotTo(HaveOccurred())
}
})

It("should fail when no volume id is provided", func() {
Expand Down Expand Up @@ -150,7 +154,7 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: "id",
TargetPath: csiTargetPath,
TargetPath: config.TargetPath,
})
Expect(err).To(HaveOccurred())

Expand Down Expand Up @@ -179,6 +183,10 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() {
s,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
if nodeStageSupported {
err := createMountTargetLocation(config.StagingPath)
Expect(err).NotTo(HaveOccurred())
}
})

It("should fail when no volume id is provided", func() {
Expand Down Expand Up @@ -278,7 +286,7 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
StagingTargetPath: csiStagingTargetPath,
StagingTargetPath: config.StagingPath,
}
if controllerPublishSupported {
nodeStageVolReq.PublishInfo = conpubvol.GetPublishInfo()
Expand All @@ -292,7 +300,7 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
By("publishing the volume on a node")
nodepubvolRequest := &csi.NodePublishVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
TargetPath: csiTargetPath,
TargetPath: config.TargetPath,
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand All @@ -303,7 +311,7 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
},
}
if nodeStageSupported {
nodepubvolRequest.StagingTargetPath = csiStagingTargetPath
nodepubvolRequest.StagingTargetPath = config.StagingPath
}
if controllerPublishSupported {
nodepubvolRequest.PublishInfo = conpubvol.GetPublishInfo()
Expand All @@ -318,7 +326,7 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
context.Background(),
&csi.NodeUnpublishVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
TargetPath: csiTargetPath,
TargetPath: config.TargetPath,
})
Expect(err).NotTo(HaveOccurred())
Expect(nodeunpubvol).NotTo(BeNil())
Expand All @@ -329,7 +337,7 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
context.Background(),
&csi.NodeUnstageVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
StagingTargetPath: csiStagingTargetPath,
StagingTargetPath: config.StagingPath,
},
)
Expect(err).NotTo(HaveOccurred())
Expand Down
38 changes: 14 additions & 24 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package sanity
import (
"fmt"
"os"
"path/filepath"
"sync"
"testing"

Expand All @@ -32,23 +31,24 @@ import (
)

var (
driverAddress string
csiMountDir string
csiTargetPath string
csiStagingTargetPath string
conn *grpc.ClientConn
lock sync.Mutex
config *Config
conn *grpc.ClientConn
lock sync.Mutex
)

// Config provides the configuration for the sanity tests
type Config struct {
TargetPath string
StagingPath string
Address string
}

// Test will test the CSI driver at the specified address
func Test(t *testing.T, address, mountDir string) {
func Test(t *testing.T, reqConfig *Config) {
lock.Lock()
defer lock.Unlock()

driverAddress = address
csiMountDir = mountDir
csiTargetPath = filepath.Join(mountDir, "mount")
csiStagingTargetPath = filepath.Join(mountDir, "stage")
config = reqConfig
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Driver Test Suite")
}
Expand All @@ -57,26 +57,16 @@ var _ = BeforeSuite(func() {
var err error

By("connecting to CSI driver")
conn, err = utils.Connect(driverAddress)
Expect(err).NotTo(HaveOccurred())

By("creating mount directory")
err = createMountTargetLocation(csiMountDir)
conn, err = utils.Connect(config.Address)
Expect(err).NotTo(HaveOccurred())

By("creating mount and staging directories")
err = createMountTargetLocation(csiTargetPath)
Expect(err).NotTo(HaveOccurred())
err = createMountTargetLocation(csiStagingTargetPath)
err = createMountTargetLocation(config.TargetPath)
Expect(err).NotTo(HaveOccurred())

})

var _ = AfterSuite(func() {
conn.Close()
os.Remove(csiTargetPath)
os.Remove(csiStagingTargetPath)
os.Remove(csiMountDir)
})

func createMountTargetLocation(targetPath string) error {
Expand Down