Skip to content

Commit

Permalink
Merge pull request #212 from davidz627/feature/volIDGenerator
Browse files Browse the repository at this point in the history
Add ID Generator interface for generating valid IDs for Volume and Node
  • Loading branch information
k8s-ci-robot authored Aug 7, 2019
2 parents c094d20 + 43c8a31 commit fda8ad3
Show file tree
Hide file tree
Showing 25 changed files with 1,046 additions and 17 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hack/_embedded/embedded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var _ = Describe("MyCSIDriver", func() {
StagingPath: os.TempDir() + "/csi-staging",
Address: "/tmp/e2e-csi-sanity.sock",
TestNodeVolumeAttachLimit: true,
IDGen: &sanity.DefaultIDGenerator{},
}

BeforeEach(func() {})
Expand Down
20 changes: 10 additions & 10 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
volReq.VolumeContentSource = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Volume{
Volume: &csi.VolumeContentSource_VolumeSource{
VolumeId: "non-existing-volume-id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
},
},
}
Expand Down Expand Up @@ -864,7 +864,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
_, err := c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
VolumeId: "reallyfakevolumeid",
VolumeId: sc.Config.IDGen.GenerateInvalidVolumeID(),
Secrets: sc.Secrets.DeleteVolumeSecret,
},
)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
_, err := c.ValidateVolumeCapabilities(
context.Background(),
&csi.ValidateVolumeCapabilitiesRequest{
VolumeId: "some-vol-id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Expand Down Expand Up @@ -1110,7 +1110,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
},
)
Expand All @@ -1126,8 +1126,8 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: "id",
NodeId: "fakenode",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
NodeId: sc.Config.IDGen.GenerateUniqueValidNodeID(),
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
},
)
Expand Down Expand Up @@ -1287,8 +1287,8 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
conpubvol, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: "some-vol-id",
NodeId: "some-node-id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
NodeId: sc.Config.IDGen.GenerateUniqueValidNodeID(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand Down Expand Up @@ -1346,7 +1346,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *Sanity
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
NodeId: "some-fake-node-id",
NodeId: sc.Config.IDGen.GenerateUniqueValidNodeID(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand Down Expand Up @@ -1711,7 +1711,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte

snapshots, err := c.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{SourceVolumeId: "none-exist-volume-id"})
&csi.ListSnapshotsRequest{SourceVolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID()})
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(BeEmpty())
Expand Down
14 changes: 7 additions & 7 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
)
Expand All @@ -202,7 +202,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
TargetPath: sc.TargetPath + "/target",
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
Expand Down Expand Up @@ -233,7 +233,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodeUnpublishVolume(
context.Background(),
&csi.NodeUnpublishVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
})
Expect(err).To(HaveOccurred())

Expand Down Expand Up @@ -286,7 +286,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand Down Expand Up @@ -395,7 +395,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodeUnstageVolume(
context.Background(),
&csi.NodeUnstageVolumeRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
})
Expect(err).To(HaveOccurred())

Expand Down Expand Up @@ -430,7 +430,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
},
)
Expect(err).To(HaveOccurred())
Expand All @@ -444,7 +444,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
_, err := c.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: "id",
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumePath: "some/path",
},
)
Expand Down
9 changes: 9 additions & 0 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ type Config struct {
RemoveStagingPathCmd string
// Timeout for the executed commands for path removal.
RemovePathCmdTimeout int

// IDGen is an optional interface for callers to provide a generator for
// valid Volume and Node IDs. Defaults to DefaultIDGenerator which generates
// generic string IDs
IDGen IDGenerator
}

// SanityContext holds the variables that each test can depend on. It
Expand Down Expand Up @@ -153,6 +158,10 @@ func Test(t *testing.T, reqConfig *Config) {
}
}

if reqConfig.IDGen == nil {
reqConfig.IDGen = &DefaultIDGenerator{}
}

sc := &SanityContext{
Config: reqConfig,
}
Expand Down
66 changes: 66 additions & 0 deletions pkg/sanity/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2019 Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package sanity

import (
"fmt"

"github.com/google/uuid"
)

// IDGenerator generates valid and invalid Volume and Node IDs to be used in
// tests
type IDGenerator interface {
// GenerateUniqueValidVolumeID must generate a unique Volume ID that the CSI
// Driver considers in valid form
GenerateUniqueValidVolumeID() string

// GenerateInvalidVolumeID must output a Volume ID that the CSI Driver MAY
// consider invalid. Some drivers may not have requirements on IDs in which
// case this method should output any non-empty ID
GenerateInvalidVolumeID() string

// GenerateUniqueValidNodeID must generate a unique Node ID that the CSI
// Driver considers in valid form
GenerateUniqueValidNodeID() string

// GenerateInvalidNodeID must output a Node ID that the CSI Driver MAY
// consider invalid. Some drivers may not have requirements on IDs in which
// case this method should output any non-empty ID
GenerateInvalidNodeID() string
}

var _ IDGenerator = &DefaultIDGenerator{}

type DefaultIDGenerator struct {
}

func (d DefaultIDGenerator) GenerateUniqueValidVolumeID() string {
return fmt.Sprintf("fake-vol-id-%s", uuid.New().String()[:10])
}

func (d DefaultIDGenerator) GenerateInvalidVolumeID() string {
return "fake-vol-id"
}

func (d DefaultIDGenerator) GenerateUniqueValidNodeID() string {
return fmt.Sprintf("fake-node-id-%s", uuid.New().String()[:10])
}

func (d DefaultIDGenerator) GenerateInvalidNodeID() string {
return "fake-node-id"
}
9 changes: 9 additions & 0 deletions vendor/github.com/google/uuid/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/google/uuid/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/google/uuid/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fda8ad3

Please sign in to comment.