Skip to content

Commit

Permalink
pkg/sanity: also track volumes that shouldn't have been created
Browse files Browse the repository at this point in the history
In the tests that expect a volume not to be created the CSI driver
might misbehave and create a volume. Detect those and delete them.
  • Loading branch information
pohly committed Jul 13, 2018
1 parent b6016b3 commit d34fca7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/sanity/cleanup.go
Expand Up @@ -58,6 +58,14 @@ func (cl *Cleanup) RegisterVolume(name string, info VolumeInfo) {
cl.volumes[name] = info
}

// MaybeRegisterVolume adds or updates an entry for the volume with
// the given name if CreateVolume was successful.
func (cl *Cleanup) MaybeRegisterVolume(name string, vol *csi.CreateVolumeResponse, err error) {
if err == nil && vol.GetVolume().GetId() != "" {
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()})
}
}

// UnregisterVolume removes the entry for the volume with the
// given name, thus preventing all cleanup operations for it.
func (cl *Cleanup) UnregisterVolume(name string) {
Expand Down
9 changes: 6 additions & 3 deletions pkg/sanity/controller.go
Expand Up @@ -171,12 +171,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
})

It("should fail when no name is provided", func() {
_, err := c.CreateVolume(
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret,
},
)
cl.MaybeRegisterVolume("", vol, err)
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expand All @@ -185,13 +186,15 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
})

It("should fail when no volume capabilities are provided", func() {
_, err := c.CreateVolume(
name := uniqueString("sanity-controller-create-no-volume-capabilities")
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Name: "name",
Name: name,
ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret,
},
)
cl.MaybeRegisterVolume(name, vol, err)
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expand Down

0 comments on commit d34fca7

Please sign in to comment.