Skip to content

Commit b1cb447

Browse files
author
Xin Wang
committed
Add snapshot parameter flag
Signed-off-by: Xin Wang <wileywang@yunify.com>
1 parent ec1441c commit b1cb447

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

cmd/csi-sanity/sanity_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func init() {
5050
flag.Int64Var(&config.TestVolumeSize, prefix+"testvolumesize", sanity.DefTestVolumeSize, "Base volume size used for provisioned volumes")
5151
flag.Int64Var(&config.TestVolumeExpandSize, prefix+"testvolumeexpandsize", 0, "Target size for expanded volumes")
5252
flag.StringVar(&config.TestVolumeParametersFile, prefix+"testvolumeparameters", "", "YAML file of volume parameters for provisioned volumes")
53+
flag.StringVar(&config.TestSnapshotParametersFile, prefix+"testsnapshotparameters", "", "YAML file of snapshot parameters for provisioned snapshots")
5354
flag.BoolVar(&config.TestNodeVolumeAttachLimit, prefix+"testnodevolumeattachlimit", false, "Test node volume attach limit")
5455
flag.StringVar(&config.JUnitFile, prefix+"junitfile", "", "JUnit XML output file where test results will be written")
5556
flag.Parse()

pkg/sanity/controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
732732

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

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

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

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

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

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

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

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

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

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

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

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

2220-
func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string, parameters map[string]string) *csi.CreateSnapshotRequest {
2220+
func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string) *csi.CreateSnapshotRequest {
22212221
req := &csi.CreateSnapshotRequest{
22222222
Name: name,
22232223
SourceVolumeId: sourceVolumeId,
2224-
Parameters: parameters,
2224+
Parameters: sc.Config.TestSnapshotParameters,
22252225
}
22262226

22272227
if sc.Secrets != nil {

pkg/sanity/sanity.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ type Config struct {
7676

7777
JUnitFile string
7878

79+
// TestSnapshotParametersFile for setting CreateVolumeRequest.Parameters.
80+
TestSnapshotParametersFile string
81+
TestSnapshotParameters map[string]string
82+
7983
// Callback functions to customize the creation of target and staging
8084
// directories. Returns the new paths for mount and staging.
8185
// If not defined, directories are created in the default way at TargetPath
@@ -163,17 +167,10 @@ func newContext(reqConfig *Config) *SanityContext {
163167
// Test will test the CSI driver at the specified address by
164168
// setting up a Ginkgo suite and running it.
165169
func Test(t *testing.T, reqConfig *Config) {
166-
path := reqConfig.TestVolumeParametersFile
167-
if len(path) != 0 {
168-
yamlFile, err := ioutil.ReadFile(path)
169-
if err != nil {
170-
panic(fmt.Sprintf("failed to read file %q: %v", path, err))
171-
}
172-
err = yaml.Unmarshal(yamlFile, &reqConfig.TestVolumeParameters)
173-
if err != nil {
174-
panic(fmt.Sprintf("error unmarshaling yaml: %v", err))
175-
}
176-
}
170+
// Get StorageClass parameters from TestVolumeParametersFile
171+
reqConfig.TestVolumeParameters = loadMap(reqConfig.TestVolumeParametersFile)
172+
// Get VolumeSnapshotClass parameters from TestSnapshotParametersFile
173+
reqConfig.TestSnapshotParameters = loadMap(reqConfig.TestSnapshotParametersFile)
177174

178175
sc := newContext(reqConfig)
179176
registerTestsInGinkgo(sc)
@@ -357,6 +354,22 @@ func loadSecrets(path string) (*CSISecrets, error) {
357354
return &creds, nil
358355
}
359356

357+
// loadMap reads a map from given file path.
358+
func loadMap(path string) map[string]string {
359+
var mp map[string]string
360+
if len(path) != 0 {
361+
yamlFile, err := ioutil.ReadFile(path)
362+
if err != nil {
363+
panic(fmt.Sprintf("failed to read file %q: %v", path, err))
364+
}
365+
err = yaml.Unmarshal(yamlFile, &mp)
366+
if err != nil {
367+
panic(fmt.Sprintf("error unmarshaling yaml: %v", err))
368+
}
369+
}
370+
return mp
371+
}
372+
360373
var uniqueSuffix = "-" + PseudoUUID()
361374

362375
// PseudoUUID returns a unique string generated from random

0 commit comments

Comments
 (0)