Skip to content

Commit

Permalink
Merge branch 'master' into mockgen-update
Browse files Browse the repository at this point in the history
  • Loading branch information
lpabon authored Jul 2, 2018
2 parents 34a59f2 + b69d828 commit aed04a1
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
matrix:
include:
- go: 1.x
- go: 1.10.3
script:
- go fmt $(go list ./... | grep -v vendor) | wc -l | grep 0
- go vet $(go list ./... | grep -v vendor)
Expand Down
33 changes: 31 additions & 2 deletions mock/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

const (
MaxStorageCapacity = tib
ReadOnlyKey = "readonly"
)

func (s *service) CreateVolume(
Expand Down Expand Up @@ -135,21 +136,48 @@ func (s *service) ControllerPublishVolume(

// Check to see if the volume is already published.
if device := v.Attributes[devPathKey]; device != "" {
var volRo bool
var roVal string
if ro, ok := v.Attributes[ReadOnlyKey]; ok {
roVal = ro
}

if roVal == "true" {
volRo = true
} else {
volRo = false
}

// Check if readonly flag is compatible with the publish request.
if req.GetReadonly() != volRo {
return nil, status.Error(codes.AlreadyExists, "Volume published but has incompatible readonly flag")
}

return &csi.ControllerPublishVolumeResponse{
PublishInfo: map[string]string{
"device": device,
"device": device,
"readonly": roVal,
},
}, nil
}

var roVal string
if req.GetReadonly() {
roVal = "true"
} else {
roVal = "false"
}

// Publish the volume.
device := "/dev/mock"
v.Attributes[devPathKey] = device
v.Attributes[ReadOnlyKey] = roVal
s.vols[i] = v

return &csi.ControllerPublishVolumeResponse{
PublishInfo: map[string]string{
"device": device,
"device": device,
"readonly": roVal,
},
}, nil
}
Expand Down Expand Up @@ -192,6 +220,7 @@ func (s *service) ControllerUnpublishVolume(

// Unpublish the volume.
delete(v.Attributes, devPathKey)
delete(v.Attributes, ReadOnlyKey)
s.vols[i] = v

return &csi.ControllerUnpublishVolumeResponse{}, nil
Expand Down
5 changes: 4 additions & 1 deletion mock/service/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"golang.org/x/net/context"

"github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/golang/protobuf/ptypes/wrappers"
)

func (s *service) GetPluginInfo(
Expand All @@ -23,7 +24,9 @@ func (s *service) Probe(
req *csi.ProbeRequest) (
*csi.ProbeResponse, error) {

return &csi.ProbeResponse{}, nil
return &csi.ProbeResponse{
Ready: &wrappers.BoolValue{Value: true},
}, nil
}

func (s *service) GetPluginCapabilities(
Expand Down
233 changes: 233 additions & 0 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ var _ = Describe("ControllerGetCapabilities [Controller Server]", func() {
case csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME:
case csi.ControllerServiceCapability_RPC_LIST_VOLUMES:
case csi.ControllerServiceCapability_RPC_GET_CAPACITY:
case csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT:
case csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS:
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType()))
}
Expand Down Expand Up @@ -645,6 +647,31 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() {
_, err = c.DeleteVolume(context.Background(), delReq)
Expect(err).NotTo(HaveOccurred())
})

It("should fail when the requested volume does not exist", func() {

_, err := c.ValidateVolumeCapabilities(
context.Background(),
&csi.ValidateVolumeCapabilitiesRequest{
VolumeId: "some-vol-id",
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
},
)
Expect(err).To(HaveOccurred())

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

var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
Expand Down Expand Up @@ -806,6 +833,212 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
_, err = c.DeleteVolume(context.Background(), delReq)
Expect(err).NotTo(HaveOccurred())
})

It("should fail when the volume does not exist", func() {

By("calling controller publish on a non-existent volume")

pubReq := &csi.ControllerPublishVolumeRequest{
VolumeId: "some-vol-id",
NodeId: "some-node-id",
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
Readonly: false,
}

if secrets != nil {
pubReq.ControllerPublishSecrets = secrets.ControllerPublishVolumeSecret
}

conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq)
Expect(err).To(HaveOccurred())
Expect(conpubvol).To(BeNil())

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

It("should fail when the node does not exist", func() {

// Create Volume First
By("creating a single node writer volume")
name := "sanity"
req := &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,
},
},
},
}

if secrets != nil {
req.ControllerCreateSecrets = secrets.CreateVolumeSecret
}

vol, err := c.CreateVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())

// ControllerPublishVolume
By("calling controllerpublish on that volume")

pubReq := &csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
NodeId: "some-fake-node-id",
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
Readonly: false,
}

if secrets != nil {
pubReq.ControllerPublishSecrets = secrets.ControllerPublishVolumeSecret
}

conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq)
Expect(err).To(HaveOccurred())
Expect(conpubvol).To(BeNil())

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

By("cleaning up deleting the volume")

delReq := &csi.DeleteVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
}

if secrets != nil {
delReq.ControllerDeleteSecrets = secrets.DeleteVolumeSecret
}

_, err = c.DeleteVolume(context.Background(), delReq)
Expect(err).NotTo(HaveOccurred())
})

It("should fail when the volume is already published but is incompatible", func() {

// Create Volume First
By("creating a single node writer volume")
name := "sanity"
req := &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,
},
},
},
}

if secrets != nil {
req.ControllerCreateSecrets = secrets.CreateVolumeSecret
}

vol, err := c.CreateVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())

By("getting a node id")
nid, err := n.NodeGetId(
context.Background(),
&csi.NodeGetIdRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

// ControllerPublishVolume
By("calling controllerpublish on that volume")

pubReq := &csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
NodeId: nid.GetNodeId(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
Readonly: false,
}

if secrets != nil {
pubReq.ControllerPublishSecrets = secrets.ControllerPublishVolumeSecret
}

conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq)
Expect(err).NotTo(HaveOccurred())
Expect(conpubvol).NotTo(BeNil())

// Publish again with different attributes.
pubReq.Readonly = true

conpubvol, err = c.ControllerPublishVolume(context.Background(), pubReq)
Expect(err).To(HaveOccurred())
Expect(conpubvol).To(BeNil())

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

By("cleaning up unpublishing the volume")

unpubReq := &csi.ControllerUnpublishVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
// NodeID is optional in ControllerUnpublishVolume
NodeId: nid.GetNodeId(),
}

if secrets != nil {
unpubReq.ControllerUnpublishSecrets = secrets.ControllerUnpublishVolumeSecret
}

conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq)
Expect(err).NotTo(HaveOccurred())
Expect(conunpubvol).NotTo(BeNil())

By("cleaning up deleting the volume")

delReq := &csi.DeleteVolumeRequest{
VolumeId: vol.GetVolume().GetId(),
}

if secrets != nil {
delReq.ControllerDeleteSecrets = secrets.DeleteVolumeSecret
}

_, err = c.DeleteVolume(context.Background(), delReq)
Expect(err).NotTo(HaveOccurred())
})
})

var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
Expand Down
6 changes: 6 additions & 0 deletions pkg/sanity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var _ = Describe("GetPluginCapabilities [Identity Service]", func() {
for _, cap := range res.GetCapabilities() {
switch cap.GetService().GetType() {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
case csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS:
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetService().GetType()))
}
Expand Down Expand Up @@ -79,6 +80,11 @@ var _ = Describe("Probe [Identity Service]", func() {
Expect(ok).To(BeTrue())
Expect(serverError.Code() == codes.FailedPrecondition ||
serverError.Code() == codes.OK).To(BeTrue())

if res.GetReady() != nil {
Expect(res.GetReady().GetValue() == true ||
res.GetReady().GetValue() == false).To(BeTrue())
}
})
})

Expand Down
Loading

0 comments on commit aed04a1

Please sign in to comment.