Skip to content

Commit

Permalink
Merge pull request #31 from lpabon/controller
Browse files Browse the repository at this point in the history
sanity: CreateVolume
  • Loading branch information
lpabon committed Jan 24, 2018
2 parents 72aca32 + 36fc189 commit 2e4b090
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 52 deletions.
3 changes: 1 addition & 2 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
CSI_ENDPOINTS="tcp://127.0.0.1:9998"
CSI_ENDPOINTS="$CSI_ENDPOINTS /tmp/e2e-csi-sanity.sock"
CSI_ENDPOINTS="$CSI_ENDPOINTS unix:///tmp/e2e-csi-sanity.sock"
CSI_ENDPOINTS="$CSI_ENDPOINTS e2e-csi-sanity.sock"

go get -u github.com/thecodeteam/gocsi/mock
cd cmd/csi-sanity
Expand All @@ -18,7 +17,7 @@ for endpoint in $CSI_ENDPOINTS ; do
CSI_ENDPOINT=$endpoint mock &
pid=$!

csi-sanity $@ --csi.endpoint=$endpoint ; ret=$?
csi-sanity $@ --ginkgo.skip=MOCKERRORS --csi.endpoint=$endpoint ; ret=$?
kill -9 $pid

if ! echo $endpoint | grep tcp > /dev/null 2>&1 ; then
Expand Down
143 changes: 113 additions & 30 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
"google.golang.org/grpc/status"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-test/utils"
context "golang.org/x/net/context"
"google.golang.org/grpc"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -61,21 +59,13 @@ func isCapabilitySupported(

var _ = Describe("ControllerGetCapabilities [Controller Server]", func() {
var (
c csi.ControllerClient
conn *grpc.ClientConn
c csi.ControllerClient
)

BeforeEach(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).ToNot(HaveOccurred())
c = csi.NewControllerClient(conn)
})

AfterEach(func() {
conn.Close()
})

It("should fail when no version is provided", func() {
_, err := c.ControllerGetCapabilities(
context.Background(),
Expand Down Expand Up @@ -116,25 +106,17 @@ var _ = Describe("ControllerGetCapabilities [Controller Server]", func() {

var _ = Describe("GetCapacity [Controller Server]", func() {
var (
c csi.ControllerClient
conn *grpc.ClientConn
c csi.ControllerClient
)

BeforeEach(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).ToNot(HaveOccurred())
c = csi.NewControllerClient(conn)

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_GET_CAPACITY) {
Skip("GetCapacity not supported")
}
})

AfterEach(func() {
conn.Close()
})

It("should fail when no version is provided", func() {

By("failing when there is no version")
Expand Down Expand Up @@ -163,25 +145,17 @@ var _ = Describe("GetCapacity [Controller Server]", func() {

var _ = Describe("ListVolumes [Controller Server]", func() {
var (
c csi.ControllerClient
conn *grpc.ClientConn
c csi.ControllerClient
)

BeforeEach(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).ToNot(HaveOccurred())
c = csi.NewControllerClient(conn)

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_VOLUMES) {
Skip("GetCapacity not supported")
Skip("ListVolumes not supported")
}
})

AfterEach(func() {
conn.Close()
})

It("should fail when no version is provided", func() {

By("failing when there is no version")
Expand Down Expand Up @@ -215,3 +189,112 @@ var _ = Describe("ListVolumes [Controller Server]", func() {
// TODO: Add test which checks list of volume is there when created,
// and not there when deleted.
})

var _ = Describe("CreateVolume [Controller Server]", func() {
var (
c csi.ControllerClient
)

BeforeEach(func() {
c = csi.NewControllerClient(conn)

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) {
Skip("CreateVolume not supported")
}
})

It("should fail when no version is provided", func() {

_, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no name is provided", func() {

_, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no volume capabilities are provided", func() {

_, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
Name: "name",
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() {
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
&csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())
})

// Pending fix in mock file
It("[MOCKERRORS] should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() {
name := "sanity"
size := uint64(1 * 1024 * 1024 * 1024)
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
&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).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())
Expect(vol.GetVolumeInfo().GetCapacityBytes()).To(Equal(size))
})
})
22 changes: 2 additions & 20 deletions pkg/sanity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
"google.golang.org/grpc/status"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-test/utils"
context "golang.org/x/net/context"
"google.golang.org/grpc"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -41,21 +39,13 @@ var (

var _ = Describe("GetSupportedVersions [Identity Server]", func() {
var (
c csi.IdentityClient
conn *grpc.ClientConn
c csi.IdentityClient
)

BeforeEach(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).ToNot(HaveOccurred())
c = csi.NewIdentityClient(conn)
})

AfterEach(func() {
conn.Close()
})

It("should return an array of supported versions", func() {
res, err := c.GetSupportedVersions(
context.Background(),
Expand All @@ -78,21 +68,13 @@ var _ = Describe("GetSupportedVersions [Identity Server]", func() {

var _ = Describe("GetPluginInfo [Identity Server]", func() {
var (
c csi.IdentityClient
conn *grpc.ClientConn
c csi.IdentityClient
)

BeforeEach(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).ToNot(HaveOccurred())
c = csi.NewIdentityClient(conn)
})

AfterEach(func() {
conn.Close()
})

It("should fail when no version is provided", func() {
_, err := c.GetPluginInfo(context.Background(), &csi.GetPluginInfoRequest{})
Expect(err).To(HaveOccurred())
Expand Down
15 changes: 15 additions & 0 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ import (
"sync"
"testing"

"github.com/kubernetes-csi/csi-test/utils"

"google.golang.org/grpc"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var (
driverAddress string
conn *grpc.ClientConn
lock sync.Mutex
)

Expand All @@ -38,3 +43,13 @@ func Test(t *testing.T, address string) {
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Driver Test Suite")
}

var _ = BeforeSuite(func() {
var err error
conn, err = utils.Connect(driverAddress)
Expect(err).NotTo(HaveOccurred())
})

var _ = AfterSuite(func() {
conn.Close()
})

0 comments on commit 2e4b090

Please sign in to comment.