diff --git a/hack/e2e.sh b/hack/e2e.sh index 0af42702..a3ae9162 100755 --- a/hack/e2e.sh +++ b/hack/e2e.sh @@ -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 @@ -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 diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 2e7b7e97..4120080e 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -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" @@ -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(), @@ -116,14 +106,10 @@ 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) { @@ -131,10 +117,6 @@ var _ = Describe("GetCapacity [Controller Server]", func() { } }) - AfterEach(func() { - conn.Close() - }) - It("should fail when no version is provided", func() { By("failing when there is no version") @@ -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") @@ -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)) + }) +}) diff --git a/pkg/sanity/identity.go b/pkg/sanity/identity.go index b3a72262..facdf39d 100644 --- a/pkg/sanity/identity.go +++ b/pkg/sanity/identity.go @@ -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" @@ -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(), @@ -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()) diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index 745e6a82..ecf88b19 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -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 ) @@ -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() +})