Skip to content

Commit 02d2f5a

Browse files
authored
Test addition (#3379)
1 parent a70632f commit 02d2f5a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/e2e/csi_cns_telemetry.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,61 @@ var _ = ginkgo.Describe("[csi-block-vanilla] [csi-file-vanilla] [csi-block-vanil
276276
gomega.Equal(vanillaClusterDistributionWithSpecialChar),
277277
"Wrong/empty cluster-distribution name present on CNS")
278278
})
279+
280+
// Test to verify PVC goes to Pending when cluster-distribution name has more than 128 characters
281+
// Steps
282+
// 1. Update cluster-distribution value to more than 128 characters
283+
// 2. Create a PVC.
284+
// 3. Expect PVC to go to Pending state.
285+
286+
ginkgo.It("Verify PVC goes to Pending when cluster distribution name has more than 128 characters", ginkgo.Label(p0,
287+
block, file, vanilla, vc70), func() {
288+
ctx, cancel := context.WithCancel(context.Background())
289+
defer cancel()
290+
291+
var pvclaim *v1.PersistentVolumeClaim
292+
var storageclasspvc *storagev1.StorageClass
293+
var err error
294+
295+
ginkgo.By("Setting the cluster-distribution name having more than 128 characters")
296+
clsDistributionName, err := genrateRandomString(130)
297+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
298+
setClusterDistribution(ctx, client, clsDistributionName)
299+
ginkgo.By("Restart CSI driver")
300+
collectPodLogs(ctx, client, csiSystemNamespace)
301+
restartSuccess, err := restartCSIDriver(ctx, client, csiNamespace, csiReplicas)
302+
gomega.Expect(restartSuccess).To(gomega.BeTrue(), "csi driver restart not successful")
303+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
304+
305+
defer func() {
306+
// Reset the cluster distribution value to default value "CSI-Vanilla".
307+
setClusterDistribution(ctx, client, vanillaClusterDistribution)
308+
}()
309+
310+
ginkgo.By("Creating a PVC")
311+
scParameters[scParamDatastoreURL] = datastoreURL
312+
storageclasspvc, pvclaim, err = createPVCAndStorageClass(ctx, client,
313+
namespace, nil, scParameters, diskSize, nil, "", false, "")
314+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
315+
316+
defer func() {
317+
err = fpv.DeletePersistentVolumeClaim(ctx, client, pvclaim.Name, pvclaim.Namespace)
318+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
319+
320+
err := client.StorageV1().StorageClasses().Delete(ctx,
321+
storageclasspvc.Name, *metav1.NewDeleteOptions(0))
322+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
323+
}()
324+
325+
ginkgo.By("Expect claim to fail")
326+
err = fpv.WaitForPersistentVolumeClaimPhase(ctx,
327+
v1.ClaimPending, client, pvclaim.Namespace, pvclaim.Name, framework.Poll, time.Second*130)
328+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
329+
330+
expectedErrMsg := "A specified parameter was not correct: createSpecs.metadata.containerCluster.clusterDistribution"
331+
framework.Logf("Expected failure message: %+q", expectedErrMsg)
332+
errorOccurred := checkEventsforError(client, pvclaim.Namespace,
333+
metav1.ListOptions{FieldSelector: fmt.Sprintf("involvedObject.name=%s", pvclaim.Name)}, expectedErrMsg)
334+
gomega.Expect(errorOccurred).To(gomega.BeTrue())
335+
})
279336
})

tests/e2e/util.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"bytes"
2121
"context"
22+
cryptoRand "crypto/rand"
2223
"crypto/tls"
2324
"encoding/json"
2425
"errors"
@@ -8129,3 +8130,16 @@ func createtWcpNsWithZonesAndPolicies(
81298130

81308131
return namespace, statusCode, nil
81318132
}
8133+
8134+
// Generates random string of requested length
8135+
func genrateRandomString(length int) (string, error) {
8136+
var generatedString string
8137+
rand.New(rand.NewSource(time.Now().UnixNano()))
8138+
b := make([]byte, length+2)
8139+
_, err := cryptoRand.Read(b)
8140+
if err != nil {
8141+
return generatedString, fmt.Errorf("error marshalling request body: %w", err)
8142+
}
8143+
generatedString = fmt.Sprintf("%x", b)[2 : length+2]
8144+
return generatedString, err
8145+
}

0 commit comments

Comments
 (0)