Skip to content
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
65 changes: 30 additions & 35 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
Expect(vol.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", TestVolumeSize(sc)), BeZero()))
})

It("should not fail when topology is not provided", func(ctx SpecContext) {

if sc.NodeInfo.AccessibleTopology == nil {
Skip("Topology not supported")
}
By("creating a volume")
name := UniqueString("sanity-controller-create-no-topology")

req := MakeCreateVolumeReq(sc, name)
req.AccessibilityRequirements = nil

vol := r.MustCreateVolume(ctx, req)
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
})

It("should not fail when requesting to create a volume with already existing name and same capacity", func() {

By("creating a volume")
Expand Down Expand Up @@ -772,12 +789,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
Skip("testnodevolumeattachlimit not enabled")
}

By("getting node info")
nodeInfo, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nodeInfo).NotTo(BeNil())
nodeInfo := sc.NodeInfo

if nodeInfo.MaxVolumesPerNode <= 0 {
Skip("No MaxVolumesPerNode")
Expand All @@ -800,7 +812,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
extraVolName := UniqueString("sanity-max-attach-limit-vol+1")
vol := r.MustCreateVolume(context.Background(), MakeCreateVolumeReq(sc, extraVolName))

_, err = r.ControllerPublishVolume(
_, err := r.ControllerPublishVolume(
context.Background(),
MakeControllerPublishVolumeReq(sc, vol.Volume.VolumeId, nid),
)
Expand Down Expand Up @@ -870,31 +882,23 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
MakeCreateVolumeReq(sc, name),
)

By("getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
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().GetVolumeId(),
NodeId: nid.GetNodeId(),
NodeId: sc.NodeInfo.GetNodeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
Readonly: false,
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
}

conpubvol := r.MustControllerPublishVolume(context.Background(), pubReq)
r.MustControllerPublishVolume(context.Background(), pubReq)

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

conpubvol, err = r.ControllerPublishVolume(context.Background(), pubReq)
conpubvol, err := r.ControllerPublishVolume(context.Background(), pubReq)
ExpectErrorCode(conpubvol, err, codes.AlreadyExists)
})
})
Expand Down Expand Up @@ -1503,6 +1507,13 @@ func MakeCreateVolumeReq(sc *TestContext, name string) *csi.CreateVolumeRequest
Parameters: sc.Config.TestVolumeParameters,
}

if sc.NodeInfo.AccessibleTopology != nil {
// Topology requirements are honored if provided by the driver
req.AccessibilityRequirements = &csi.TopologyRequirement{
Requisite: []*csi.Topology{sc.NodeInfo.AccessibleTopology},
}
}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.CreateVolumeSecret
}
Expand Down Expand Up @@ -1593,27 +1604,11 @@ func MakeModifyVolumeReq(sc *TestContext, volID string) *csi.ControllerModifyVol
func VolumeLifecycle(r *Resources, sc *TestContext, count int) {
// CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform
// meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported
By("getting node information")
ni, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(ni).NotTo(BeNil())
Expect(ni.GetNodeId()).NotTo(BeEmpty())

var accReqs *csi.TopologyRequirement
if ni.AccessibleTopology != nil {
// Topology requirements are honored if provided by the driver
accReqs = &csi.TopologyRequirement{
Requisite: []*csi.Topology{ni.AccessibleTopology},
}
}

// 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(), req)

Expand All @@ -1624,7 +1619,7 @@ func VolumeLifecycle(r *Resources, sc *TestContext, count int) {
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
NodeId: ni.GetNodeId(),
NodeId: sc.NodeInfo.GetNodeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
Readonly: false,
Expand Down
52 changes: 6 additions & 46 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,21 @@ func runControllerTest(sc *TestContext, r *Resources, controllerPublishSupported

name := UniqueString(fmt.Sprintf("sanity-node-full-%d", count))

By("getting node information")
ni, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(ni).NotTo(BeNil())
Expect(ni.GetNodeId()).NotTo(BeEmpty())

var accReqs *csi.TopologyRequirement
if ni.AccessibleTopology != nil {
// Topology requirements are honored if provided by the driver
accReqs = &csi.TopologyRequirement{
Requisite: []*csi.Topology{ni.AccessibleTopology},
}
}

// Create Volume First
By("creating a single node writer volume")
req := MakeCreateVolumeReq(sc, name)
req.AccessibilityRequirements = accReqs
vol := r.MustCreateVolume(context.Background(), req)

var conpubvol *csi.ControllerPublishVolumeResponse
var err error
if controllerPublishSupported {
By("controller publishing volume")

conpubvol, err = r.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
NodeId: ni.GetNodeId(),
NodeId: sc.NodeInfo.GetNodeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
Readonly: false,
Expand Down Expand Up @@ -425,16 +409,8 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
volid := vol.GetVolume().GetVolumeId()
volpath := sc.TargetPath + "/target"

By("Getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

By("Staging and publishing a volume")
conpubvol := controllerPublishVolume(name, vol, nid)
conpubvol := controllerPublishVolume(name, vol, sc.NodeInfo)
_ = nodeStageVolume(name, vol, conpubvol)
_ = nodePublishVolume(name, vol, conpubvol)

Expand Down Expand Up @@ -605,15 +581,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {

vol := createVolume(name)

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

conpubvol := controllerPublishVolume(name, vol, nid)
conpubvol := controllerPublishVolume(name, vol, sc.NodeInfo)

// NodeStageVolume
_ = nodeStageVolume(name, vol, conpubvol)
Expand Down Expand Up @@ -701,15 +669,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
Expect(rsp.GetCapacityBytes()).To(Equal(TestVolumeExpandSize(sc)))
}

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

conpubvol := controllerPublishVolume(name, vol, nid)
conpubvol := controllerPublishVolume(name, vol, sc.NodeInfo)

// NodeStageVolume
_ = nodeStageVolume(name, vol, conpubvol)
Expand All @@ -718,7 +678,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
_ = nodePublishVolume(name, vol, conpubvol)

By("expanding the volume on a node")
_, err = r.NodeExpandVolume(
_, err := r.NodeExpandVolume(
context.Background(),
&csi.NodeExpandVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
Expand Down
9 changes: 8 additions & 1 deletion pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-test/v5/utils"
yaml "gopkg.in/yaml.v2"

Expand Down Expand Up @@ -182,6 +183,8 @@ type TestContext struct {
ControllerConn *grpc.ClientConn
Secrets *CSISecrets

NodeInfo *csi.NodeGetInfoResponse

connAddress string
controllerConnAddress string

Expand Down Expand Up @@ -243,7 +246,7 @@ func GinkgoTest(config *TestConfig) *TestContext {

// Setup must be invoked before each test. It initialize per-test
// variables in the context.
func (sc *TestContext) Setup() {
func (sc *TestContext) Setup(ctx context.Context) {
var err error

// Get StorageClass parameters from TestVolumeParametersFile
Expand Down Expand Up @@ -271,6 +274,10 @@ func (sc *TestContext) Setup() {
sc.Conn, err = utils.Connect(sc.Config.Address, sc.Config.DialOptions...)
Expect(err).NotTo(HaveOccurred())
sc.connAddress = sc.Config.Address
sc.NodeInfo, err = csi.NewNodeClient(sc.Conn).NodeGetInfo(ctx, &csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(sc.NodeInfo).NotTo(BeNil())
Expect(sc.NodeInfo.GetNodeId()).NotTo(BeEmpty())
} else {
By(fmt.Sprintf("reusing connection to CSI driver at %s", sc.connAddress))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sanity/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func registerTestsInGinkgo(sc *TestContext) {
for _, test := range tests {
test := test
Describe(test.text, func() {
BeforeEach(func() {
sc.Setup()
BeforeEach(func(ctx SpecContext) {
sc.Setup(ctx)
})

test.body(sc)
Expand Down