Skip to content
Merged
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
1 change: 1 addition & 0 deletions cmd/csi-sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func init() {
flag.Int64Var(&config.TestVolumeSize, prefix+"testvolumesize", sanity.DefTestVolumeSize, "Base volume size used for provisioned volumes")
flag.Int64Var(&config.TestVolumeExpandSize, prefix+"testvolumeexpandsize", 0, "Target size for expanded volumes")
flag.StringVar(&config.TestVolumeParametersFile, prefix+"testvolumeparameters", "", "YAML file of volume parameters for provisioned volumes")
flag.StringVar(&config.TestSnapshotParametersFile, prefix+"testsnapshotparameters", "", "YAML file of snapshot parameters for provisioned snapshots")
flag.BoolVar(&config.TestNodeVolumeAttachLimit, prefix+"testnodevolumeattachlimit", false, "Test node volume attach limit")
flag.StringVar(&config.JUnitFile, prefix+"junitfile", "", "JUnit XML output file where test results will be written")
flag.Parse()
Expand Down
24 changes: 12 additions & 12 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity

By("creating a snapshot")
snapName := UniqueString("sanity-controller-snap-from-vol")
snapReq := MakeCreateSnapshotReq(sc, snapName, volume1.GetVolume().GetVolumeId(), nil)
snapReq := MakeCreateSnapshotReq(sc, snapName, volume1.GetVolume().GetVolumeId())
snap, err := c.CreateSnapshot(context.Background(), snapReq)
Expect(err).NotTo(HaveOccurred())
Expect(snap).NotTo(BeNil())
Expand Down Expand Up @@ -1650,7 +1650,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte
Expect(err).NotTo(HaveOccurred())

By("creating a snapshot")
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-1", volume.GetVolume().GetVolumeId(), nil)
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-1", volume.GetVolume().GetVolumeId())
snapshot, err := c.CreateSnapshot(context.Background(), snapshotReq)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -1692,7 +1692,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte
Expect(err).NotTo(HaveOccurred())

By("creating a snapshot")
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-2", volume.GetVolume().GetVolumeId(), nil)
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-2", volume.GetVolume().GetVolumeId())
snapshot, err := c.CreateSnapshot(context.Background(), snapshotReq)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -1743,7 +1743,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte
Expect(err).NotTo(HaveOccurred())

By("creating a snapshot")
snapReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-3", volume.GetVolume().GetVolumeId(), nil)
snapReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-3", volume.GetVolume().GetVolumeId())
snapshot, err := c.CreateSnapshot(context.Background(), snapReq)
Expect(err).NotTo(HaveOccurred())
Expect(snapshot).NotTo(BeNil())
Expand Down Expand Up @@ -1811,7 +1811,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte
Expect(volume).NotTo(BeNil())
createVols = append(createVols, volume.GetVolume())

snapReq := MakeCreateSnapshotReq(sc, "snapshot"+strconv.Itoa(i), volume.GetVolume().GetVolumeId(), nil)
snapReq := MakeCreateSnapshotReq(sc, "snapshot"+strconv.Itoa(i), volume.GetVolume().GetVolumeId())
snapshot, err := c.CreateSnapshot(context.Background(), snapReq)
Expect(err).NotTo(HaveOccurred())
Expect(snapshot).NotTo(BeNil())
Expand Down Expand Up @@ -1915,7 +1915,7 @@ var _ = DescribeSanity("DeleteSnapshot [Controller Server]", func(sc *SanityCont

// Create Snapshot First
By("creating a snapshot")
snapshotReq := MakeCreateSnapshotReq(sc, "DeleteSnapshot-snapshot-1", volume.GetVolume().GetVolumeId(), nil)
snapshotReq := MakeCreateSnapshotReq(sc, "DeleteSnapshot-snapshot-1", volume.GetVolume().GetVolumeId())
snapshot, err := c.CreateSnapshot(context.Background(), snapshotReq)
Expect(err).NotTo(HaveOccurred())
Expect(snapshot).NotTo(BeNil())
Expand Down Expand Up @@ -1988,7 +1988,7 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
Expect(err).NotTo(HaveOccurred())

By("creating a snapshot")
snapReq1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-1", volume.GetVolume().GetVolumeId(), nil)
snapReq1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-1", volume.GetVolume().GetVolumeId())
snap1, err := c.CreateSnapshot(context.Background(), snapReq1)
Expect(err).NotTo(HaveOccurred())
Expect(snap1).NotTo(BeNil())
Expand Down Expand Up @@ -2017,7 +2017,7 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
Expect(err).ToNot(HaveOccurred())

By("creating a snapshot with the created volume source id")
req1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-2", volume.GetVolume().GetVolumeId(), nil)
req1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-2", volume.GetVolume().GetVolumeId())
snap1, err := c.CreateSnapshot(context.Background(), req1)
Expect(err).NotTo(HaveOccurred())
Expect(snap1).NotTo(BeNil())
Expand All @@ -2027,7 +2027,7 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
Expect(err).ToNot(HaveOccurred())

By("creating a snapshot with the same name but different volume source id")
req2 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-2", volume2.GetVolume().GetVolumeId(), nil)
req2 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-2", volume2.GetVolume().GetVolumeId())
_, err = c.CreateSnapshot(context.Background(), req2)
Expect(err).To(HaveOccurred())
serverError, ok := status.FromError(err)
Expand Down Expand Up @@ -2059,7 +2059,7 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
name := string(nameBytes)

By("creating a snapshot")
snapReq1 := MakeCreateSnapshotReq(sc, name, volume.GetVolume().GetVolumeId(), nil)
snapReq1 := MakeCreateSnapshotReq(sc, name, volume.GetVolume().GetVolumeId())
snap1, err := c.CreateSnapshot(context.Background(), snapReq1)
Expect(err).NotTo(HaveOccurred())
Expect(snap1).NotTo(BeNil())
Expand Down Expand Up @@ -2217,11 +2217,11 @@ func MakeCreateVolumeReq(sc *SanityContext, name string) *csi.CreateVolumeReques
return req
}

func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string, parameters map[string]string) *csi.CreateSnapshotRequest {
func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string) *csi.CreateSnapshotRequest {
req := &csi.CreateSnapshotRequest{
Name: name,
SourceVolumeId: sourceVolumeId,
Parameters: parameters,
Parameters: sc.Config.TestSnapshotParameters,
}

if sc.Secrets != nil {
Expand Down
33 changes: 22 additions & 11 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ type Config struct {

JUnitFile string

// TestSnapshotParametersFile for setting CreateVolumeRequest.Parameters.
TestSnapshotParametersFile string
TestSnapshotParameters map[string]string

// Callback functions to customize the creation of target and staging
// directories. Returns the new paths for mount and staging.
// If not defined, directories are created in the default way at TargetPath
Expand Down Expand Up @@ -163,17 +167,10 @@ func newContext(reqConfig *Config) *SanityContext {
// Test will test the CSI driver at the specified address by
// setting up a Ginkgo suite and running it.
func Test(t *testing.T, reqConfig *Config) {
path := reqConfig.TestVolumeParametersFile
if len(path) != 0 {
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("failed to read file %q: %v", path, err))
}
err = yaml.Unmarshal(yamlFile, &reqConfig.TestVolumeParameters)
if err != nil {
panic(fmt.Sprintf("error unmarshaling yaml: %v", err))
}
}
// Get StorageClass parameters from TestVolumeParametersFile
loadFromFile(reqConfig.TestVolumeParametersFile, &reqConfig.TestVolumeParameters)
// Get VolumeSnapshotClass parameters from TestSnapshotParametersFile
loadFromFile(reqConfig.TestSnapshotParametersFile, &reqConfig.TestSnapshotParameters)

sc := newContext(reqConfig)
registerTestsInGinkgo(sc)
Expand Down Expand Up @@ -357,6 +354,20 @@ func loadSecrets(path string) (*CSISecrets, error) {
return &creds, nil
}

// loadFromFile reads struct from given file path.
func loadFromFile(from string, to interface{}) {
if len(from) != 0 {
yamlFile, err := ioutil.ReadFile(from)
if err != nil {
panic(fmt.Sprintf("failed to read file %q: %v", from, err))
}
err = yaml.Unmarshal(yamlFile, to)
if err != nil {
panic(fmt.Sprintf("error unmarshaling yaml: %v", err))
}
}
}

var uniqueSuffix = "-" + PseudoUUID()

// PseudoUUID returns a unique string generated from random
Expand Down