Skip to content
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

use MakeCreateVolumeReq() #524

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
213 changes: 26 additions & 187 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
name := "sanity"

// Create a new volume.
req := &csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
}

req := MakeCreateVolumeReq(sc, name)
vol := r.MustCreateVolume(context.Background(), req)

// List volumes and check for the newly created volume.
Expand Down Expand Up @@ -291,15 +283,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
By("creating required new volumes")
for i := initialTotalVols; i < minVolCount; i++ {
name := "sanity" + strconv.Itoa(i)
req := &csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
}

req := MakeCreateVolumeReq(sc, name)
vol, err := r.CreateVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expand Down Expand Up @@ -335,15 +319,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
}

By("creating a new volume")
req := &csi.CreateVolumeRequest{
Name: "new-addition",
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
}
vol := r.MustCreateVolume(context.Background(), req)
vol := r.MustCreateVolume(context.Background(), MakeCreateVolumeReq(sc, "new-addition"))
existing_vols[vol.Volume.VolumeId] = true

vols, err = r.ListVolumes(
Expand Down Expand Up @@ -399,21 +375,11 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

By("creating a volume")
name := UniqueString("sanity-controller-create-single-no-capacity")
req := MakeCreateVolumeReq(sc, name)
// req.CapacityRange = nil
// FIXME: We should set it to nil, but this may break existing tests

r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
r.MustCreateVolume(context.Background(), req)
})

It("should return appropriate values SingleNodeWriter WithCapacity 1Gi", func() {
Expand All @@ -423,17 +389,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

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: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)
if serverError, ok := status.FromError(err); ok &&
(serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented) {
Expand All @@ -454,34 +410,14 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol1 := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

Expect(vol1.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero()))

vol2 := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)
Expect(vol2.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero()))
Expect(vol1.GetVolume().GetVolumeId()).To(Equal(vol2.GetVolume().GetVolumeId()))
Expand All @@ -491,40 +427,17 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

By("creating a volume")
name := UniqueString("sanity-controller-create-twice-different")
size1 := TestVolumeSize(sc)

r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size1,
LimitBytes: size1,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)
size2 := 2 * TestVolumeSize(sc)

rsp, err := r.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size2,
LimitBytes: size2,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
req2 := MakeCreateVolumeReq(sc, name)
req2.CapacityRange = &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc) * 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to fix MakeCreateVolumeReq to take CapacityRange as input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have 41 usages of MakeCreateVolumeReq now. Do we really want to make 40 invocations more complex to simplify one case?

}
rsp, err := r.CreateVolume(context.Background(), req2)
ExpectErrorCode(rsp, err, codes.AlreadyExists)
})

Expand All @@ -535,17 +448,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)
Expect(vol.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero()))
})
Expand Down Expand Up @@ -714,17 +617,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

// Delete Volume
Expand Down Expand Up @@ -760,17 +653,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

rsp, err := r.ValidateVolumeCapabilities(
Expand All @@ -791,17 +674,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

// ValidateVolumeCapabilities
Expand Down Expand Up @@ -949,14 +822,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

// ControllerPublishVolume
Expand Down Expand Up @@ -991,14 +857,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
MakeCreateVolumeReq(sc, name),
)

By("getting a node id")
Expand Down Expand Up @@ -1503,17 +1362,7 @@ var _ = DescribeSanity("ExpandVolume [Controller Server]", func(sc *TestContext)
name := UniqueString("sanity-expand-volume")

// Create a new volume.
req := &csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Parameters: sc.Config.TestVolumeParameters,
Secrets: sc.Secrets.CreateVolumeSecret,
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
}
req := MakeCreateVolumeReq(sc, name)
vol := r.MustCreateVolume(context.Background(), req)

By("expanding the volume")
Expand Down Expand Up @@ -1640,7 +1489,6 @@ func MakeCreateVolumeReq(sc *TestContext, name string) *csi.CreateVolumeRequest
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: size1,
LimitBytes: size1,
},
Parameters: sc.Config.TestVolumeParameters,
}
Expand Down Expand Up @@ -1754,19 +1602,10 @@ func VolumeLifecycle(r *Resources, sc *TestContext, count int) {
// Create Volume First
By("creating a single node writer volume")
name := UniqueString(fmt.Sprintf("sanity-controller-publish-%d", count))
req := MakeCreateVolumeReq(sc, name)
req.AccessibilityRequirements = accReqs

vol := r.MustCreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
AccessibilityRequirements: accReqs,
},
)
vol := r.MustCreateVolume(context.Background(), req)

// ControllerPublishVolume
for i := 0; i < count; i++ {
Expand Down
Loading