Skip to content

Controller: cleaning up e2e tests #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2018
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
8 changes: 7 additions & 1 deletion mock/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func (s *service) CreateVolume(

// Check to see if the volume already exists.
if i, v := s.findVolByName(ctx, req.Name); i >= 0 {
// Requested volume name already exists, need to check if the existing volume's
// capacity is more or equal to new request's capacity.
if v.GetCapacityBytes() < req.GetCapacityRange().GetRequiredBytes() {
return nil, status.Error(codes.AlreadyExists,
fmt.Sprintf("Volume with name %s already exists", req.GetName()))
}
return &csi.CreateVolumeResponse{Volume: &v}, nil
}

Expand Down Expand Up @@ -280,7 +286,7 @@ func (s *service) GetCapacity(
*csi.GetCapacityResponse, error) {

return &csi.GetCapacityResponse{
AvailableCapacity: tib100,
AvailableCapacity: MaxStorageCapacity,
}, nil
}

Expand Down
167 changes: 161 additions & 6 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
Expect(err).NotTo(HaveOccurred())
})

// Pending fix in mock file
It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() {

By("creating a volume")
Expand All @@ -240,12 +239,20 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
RequiredBytes: size,
},
})
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())
Expect(vol.GetVolume().GetCapacityBytes()).To(Equal(size))
if serverError, ok := status.FromError(err); ok {
if serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented {
Skip("Required bytes not supported")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else {
Expect(err).NotTo(HaveOccurred())
}
} else {

Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())
Expect(vol.GetVolume().GetCapacityBytes()).To(Equal(size))
}
By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
Expand All @@ -254,6 +261,154 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
})
Expect(err).NotTo(HaveOccurred())
})
It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but the only thing is that an error may be returned if the driver does not support RequiredBytes, like NFS. You will want to check the error returned to be either OUT_OF_RANGE or UNIMPLEMENTED.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpabon thanks a lot for your review, I will address it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


By("creating a volume")
name := "sanity"
size := int64(1 * 1024 * 1024 * 1024)
vol1, 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).NotTo(HaveOccurred())
Expect(vol1).NotTo(BeNil())
Expect(vol1.GetVolume()).NotTo(BeNil())
Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty())
Expect(vol1.GetVolume().GetCapacityBytes()).To(Equal(size))
vol2, 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).NotTo(HaveOccurred())
Expect(vol2).NotTo(BeNil())
Expect(vol2.GetVolume()).NotTo(BeNil())
Expect(vol2.GetVolume().GetId()).NotTo(BeEmpty())
Expect(vol2.GetVolume().GetCapacityBytes()).To(Equal(size))
Expect(vol1.GetVolume().GetId()).To(Equal(vol2.GetVolume().GetId()))

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
VolumeId: vol1.GetVolume().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})
It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() {

By("creating a volume")
name := "sanity"
size1 := int64(1 * 1024 * 1024 * 1024)
vol1, 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: size1,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(vol1).NotTo(BeNil())
Expect(vol1.GetVolume()).NotTo(BeNil())
Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty())
size2 := int64(2 * 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: size2,
},
})
Expect(err).To(HaveOccurred())
serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.AlreadyExists))

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
VolumeId: vol1.GetVolume().GetId(),
})
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