Skip to content

Commit

Permalink
Check for negative size or inverted range
Browse files Browse the repository at this point in the history
The CSI spec requires that callers must pass non-negative sizes.  It
is also impossible to honor a request where the RequiredSize is larger
than the LimitSize.  For both of these, check that we get either
InvalidArgument or OutOfRange.

Signed-off-by: Eric Blake <[email protected]>
  • Loading branch information
ebblake committed Dec 31, 2024
1 parent a5b8eac commit 3ad33cb
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,62 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})

It("should fail with negative capacity", func() {

By("creating a volume")
name := UniqueString("sanity-controller-create-single-with-negative-capacity")

vol, err := r.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: -1 * TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
Expect(err).To(HaveOccurred())
Expect(vol).To(BeNil())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code() == codes.OutOfRange || serverError.Code() == codes.InvalidArgument, "unexpected error: %s", serverError.Message())
})

It("should fail with invalid capacity", func() {

By("creating a volume")
name := UniqueString("sanity-controller-create-single-with-invalid-capacity")

vol, err := r.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
// LimitBytes < RequiredBytes is impossible to honor
RequiredBytes: TestVolumeExpandSize(sc),
LimitBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
Expect(err).To(HaveOccurred())
Expect(vol).To(BeNil())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code() == codes.OutOfRange || serverError.Code() == codes.InvalidArgument, "unexpected error: %s", serverError.Message())
})

// whether CreateVolume request with no capacity should fail or not depends on driver implementation
It("should return appropriate values SingleNodeWriter NoCapacity", func() {

Expand Down

0 comments on commit 3ad33cb

Please sign in to comment.