diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 99d68d09..2c92e1b5 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -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") @@ -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") @@ -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), ) @@ -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) }) }) @@ -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 } @@ -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) @@ -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, diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 0071d6d3..50bb1dc4 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -68,29 +68,13 @@ 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") @@ -98,7 +82,7 @@ func runControllerTest(sc *TestContext, r *Resources, controllerPublishSupported 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, @@ -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) @@ -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) @@ -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) @@ -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(), diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index b57d76dc..b2ba9e9e 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -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" @@ -182,6 +183,8 @@ type TestContext struct { ControllerConn *grpc.ClientConn Secrets *CSISecrets + NodeInfo *csi.NodeGetInfoResponse + connAddress string controllerConnAddress string @@ -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 @@ -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)) } diff --git a/pkg/sanity/tests.go b/pkg/sanity/tests.go index 13d84439..689ec8cb 100644 --- a/pkg/sanity/tests.go +++ b/pkg/sanity/tests.go @@ -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)