Skip to content

Commit

Permalink
Various fixes for test suites to run properly
Browse files Browse the repository at this point in the history
Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>
  • Loading branch information
winkingturtle-vmw and ameowlia committed Aug 15, 2024
1 parent 50c796a commit f67e261
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 104 deletions.
2 changes: 1 addition & 1 deletion driverhttp/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (r *remoteClient) Path(env dockerdriver.Env, pathRequest dockerdriver.PathR
}

func (r *remoteClient) Unmount(env dockerdriver.Env, unmountRequest dockerdriver.UnmountRequest) dockerdriver.ErrorResponse {
logger := env.Logger().Session("mount")
logger := env.Logger().Session("unmount")
logger.Info("start")
defer logger.Info("end")

Expand Down
42 changes: 6 additions & 36 deletions integration/compatibility/compatibility_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package compatibility_test

import (
"encoding/json"
"errors"
"os"
"os/exec"
"testing"

Expand All @@ -14,18 +11,8 @@ import (
"github.com/onsi/gomega/gexec"
)

type VolumeServiceBrokerBinding struct {
VolumeMounts []struct {
Device struct {
VolumeID string `json:"volume_id"`
MountConfig map[string]interface{} `json:"mount_config"`
} `json:"device"`
} `json:"volume_mounts"`
}

var (
bindingsFixture = LoadVolumeServiceBrokerBindingsFixture()
session *gexec.Session
session *gexec.Session
)

func TestCompatibility(t *testing.T) {
Expand All @@ -35,34 +22,17 @@ func TestCompatibility(t *testing.T) {
}

var _ = BeforeSuite(func() {

config, err := integration.LoadConfig()
Expect(err).NotTo(HaveOccurred())

cmd := exec.Command(config.Driver, config.DriverArgs...)

session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(session.Out).Should(gbytes.Say("driver-server.started"))
})

func LoadVolumeServiceBrokerBindingsFixture() []VolumeServiceBrokerBinding {
var ok bool
var bindingsFile string
if bindingsFile, ok = os.LookupEnv("BINDINGS_FILE"); !ok {
panic(errors.New("BINDINGS_FILE environment variable not set"))
}

bytes, err := os.ReadFile(bindingsFile)
if err != nil {
panic(err.Error())
}

bindings := []VolumeServiceBrokerBinding{}
err = json.Unmarshal(bytes, &bindings)
if err != nil {
panic(err.Error())
}

return bindings
}
var _ = AfterSuite(func() {
session.Interrupt()
Eventually(session).Should(gexec.Exit())
})
161 changes: 99 additions & 62 deletions integration/compatibility/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path"
"path/filepath"
"strconv"
"strings"
"time"

"code.cloudfoundry.org/dockerdriver"
Expand Down Expand Up @@ -46,82 +45,120 @@ var _ = Describe("Compatibility", func() {
Expect(err).NotTo(HaveOccurred())
})

for _, binding := range bindingsFixture {

options := []string{}

cf := config
cf.CreateConfig = dockerdriver.CreateRequest{}
cf.CreateConfig.Name = binding.VolumeMounts[0].Device.VolumeID
cf.CreateConfig.Opts = map[string]interface{}{}
cf.CreateConfig.Opts["source"] = config.CreateConfig.Opts["source"]
It("verifies driver name", func() {
Expect([]string{"smbdriver", "nfsv3driver"}).To(ContainElement(config.DriverName))
})

if userAuthenticated(config.CreateConfig.Opts) {
DescribeTable("nfs",
func(key string, value interface{}) {
if config.DriverName != "nfsv3driver" {
Skip("This is for nfsdriver only")
}
panic("need to add the fixture")
cf := config
cf.CreateConfig = dockerdriver.CreateRequest{}
cf.CreateConfig.Name = randomString(10)
cf.CreateConfig.Opts = map[string]interface{}{}
cf.CreateConfig.Opts["source"] = config.CreateConfig.Opts["source"]
cf.CreateConfig.Opts["username"] = config.CreateConfig.Opts["username"]
cf.CreateConfig.Opts["password"] = config.CreateConfig.Opts["password"]
} else {
cf.CreateConfig.Opts["uid"] = config.CreateConfig.Opts["uid"]
cf.CreateConfig.Opts["gid"] = config.CreateConfig.Opts["gid"]
}
cf.CreateConfig.Opts[key] = value

for k, v := range binding.VolumeMounts[0].Device.MountConfig {
options = append(options, k)
testLogger.Info("using fixture", lager.Data{"fixture": cf})
errResponse = driverClient.Create(testEnv, cf.CreateConfig)
Expect(errResponse.Err).To(Equal(""))

if k == "source" || k == "username" || k == "password" || k == "uid" || k == "gid" {
continue
mountResponse = driverClient.Mount(testEnv, dockerdriver.MountRequest{
Name: cf.CreateConfig.Name,
})
Expect(mountResponse.Err).To(Equal(""))
Expect(mountResponse.Mountpoint).NotTo(Equal(""))

cmd := exec.Command("bash", "-c", "cat /proc/mounts | grep -E '"+mountResponse.Mountpoint+"'")
Expect(cmdRunner(cmd)).To(Equal(0))
if isReadWrite(cf.CreateConfig.Opts) {
testFileWrite(testLogger, mountResponse)
} else {
testReadOnly(testLogger, mountResponse)
}

cf.CreateConfig.Opts[k] = v
}
// Cleanup
errResponse = driverClient.Unmount(testEnv, dockerdriver.UnmountRequest{
Name: cf.CreateConfig.Name,
})
Expect(errResponse.Err).To(Equal(""))

Context("given a created volume", func() {
errResponse = driverClient.Remove(testEnv, dockerdriver.RemoveRequest{
Name: cf.CreateConfig.Name,
})
Expect(errResponse.Err).To(Equal(""))
},
Entry("with a default volume mount", "domain", ""),
Entry("with a readonly=true volume mount", "readonly", true),
Entry("with a ro=true volume mount", "ro", "true"),
Entry("with a mount=/foo/bar volume mount", "mount", "/foo/bar"),
Entry("with a version=1.0 volume mount", "version", "1.0"),
Entry("with a version=2.0 volume mount", "version", "2.0"),
Entry("with a version=2.1 volume mount", "version", "2.1"),
Entry("with a version=3.0 volume mount", "version", "3.0"),
Entry("with a version=3.1.1 volume mount", "version", "3.1.1"),
Entry("with a mfsymlinks=true volume mount", "mfsymlinks", "true"),
)

DescribeTable("smb",
func(key string, value interface{}) {
if config.DriverName != "smbdriver" {
Skip("This is for smbdriver only")
}
cf := config
cf.CreateConfig = dockerdriver.CreateRequest{}
cf.CreateConfig.Name = randomString(10)
cf.CreateConfig.Opts = map[string]interface{}{}
cf.CreateConfig.Opts["source"] = config.CreateConfig.Opts["source"]
cf.CreateConfig.Opts["username"] = config.CreateConfig.Opts["username"]
cf.CreateConfig.Opts["password"] = config.CreateConfig.Opts["password"]
cf.CreateConfig.Opts[key] = value

var certificationFixture = cf
testLogger.Info("using fixture", lager.Data{"fixture": cf})
errResponse = driverClient.Create(testEnv, cf.CreateConfig)
Expect(errResponse.Err).To(Equal(""))

BeforeEach(func() {
testLogger.Info("using fixture", lager.Data{"fixture": certificationFixture})
errResponse = driverClient.Create(testEnv, certificationFixture.CreateConfig)
Expect(errResponse.Err).To(Equal(""))
mountResponse = driverClient.Mount(testEnv, dockerdriver.MountRequest{
Name: cf.CreateConfig.Name,
})
Expect(mountResponse.Err).To(Equal(""))
Expect(mountResponse.Mountpoint).NotTo(Equal(""))

cmd := exec.Command("bash", "-c", "cat /proc/mounts | grep -E '"+mountResponse.Mountpoint+"'")
Expect(cmdRunner(cmd)).To(Equal(0))
if isReadWrite(cf.CreateConfig.Opts) {
testFileWrite(testLogger, mountResponse)
} else {
testReadOnly(testLogger, mountResponse)
}

AfterEach(func() {
errResponse = driverClient.Remove(testEnv, dockerdriver.RemoveRequest{
Name: certificationFixture.CreateConfig.Name,
})
Expect(errResponse.Err).To(Equal(""))
// Cleanup
errResponse = driverClient.Unmount(testEnv, dockerdriver.UnmountRequest{
Name: cf.CreateConfig.Name,
})
Expect(errResponse.Err).To(Equal(""))

Context("given a mounted volume with options: "+strings.Join(options, ","), func() {
BeforeEach(func() {
mountResponse = driverClient.Mount(testEnv, dockerdriver.MountRequest{
Name: certificationFixture.CreateConfig.Name,
})
Expect(mountResponse.Err).To(Equal(""))
Expect(mountResponse.Mountpoint).NotTo(Equal(""))

cmd := exec.Command("bash", "-c", "cat /proc/mounts | grep -E '"+mountResponse.Mountpoint+"'")
Expect(cmdRunner(cmd)).To(Equal(0))
})

AfterEach(func() {
errResponse = driverClient.Unmount(testEnv, dockerdriver.UnmountRequest{
Name: certificationFixture.CreateConfig.Name,
})
Expect(errResponse.Err).To(Equal(""))
})

if isReadWrite(certificationFixture.CreateConfig.Opts) {
It("should be able to write a file", func() {
testFileWrite(testLogger, mountResponse)
})
} else {
It("should be a read-only filesystem", func() {
testReadOnly(testLogger, mountResponse)
})
}
errResponse = driverClient.Remove(testEnv, dockerdriver.RemoveRequest{
Name: cf.CreateConfig.Name,
})
})
}
Expect(errResponse.Err).To(Equal(""))
},
Entry("with a default volume mount", "domain", ""),
Entry("with a readonly=true volume mount", "readonly", true),
Entry("with a ro=true volume mount", "ro", "true"),
Entry("with a mount=/foo/bar volume mount", "mount", "/foo/bar"),
Entry("with a version=1.0 volume mount", "version", "1.0"),
Entry("with a version=2.0 volume mount", "version", "2.0"),
Entry("with a version=2.1 volume mount", "version", "2.1"),
Entry("with a version=3.0 volume mount", "version", "3.0"),
Entry("with a version=3.1.1 volume mount", "version", "3.1.1"),
Entry("with a mfsymlinks=true volume mount", "mfsymlinks", "true"),
)
})

func userAuthenticated(opts map[string]interface{}) bool {
Expand Down
1 change: 0 additions & 1 deletion integration/fixture.go → integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Config struct {
DriverAddress string `json:"driver_address"`
DriverArgs []string `json:"driver_args"`
TLSConfig *dockerdriver.TLSConfig `json:"tls_config,omitempty"`
VolmanSpecDir string `json:"volman_spec_dir"`
}

func LoadConfig() (Config, error) {
Expand Down
4 changes: 4 additions & 0 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ var _ = BeforeSuite(func() {

Eventually(session.Out).Should(gbytes.Say("driver-server.started"))
})
var _ = AfterSuite(func() {
session.Interrupt()
Eventually(session).Should(gexec.Exit())
})
13 changes: 9 additions & 4 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"context"
"fmt"
"math/rand"
"os"
"path"
Expand Down Expand Up @@ -33,12 +34,13 @@ var _ = Describe("Certify with: ", func() {
testLogger = lagertest.NewTestLogger("MainTest")
testContext = context.TODO()
testEnv = driverhttp.NewHttpDriverEnv(testLogger, testContext)

var err error
config, err = integration.LoadConfig()
Expect(err).NotTo(HaveOccurred())
testLogger.Info("fixture", lager.Data{"context": config})

config.CreateConfig.Name = randomString(10)

driverClient, err = driverhttp.NewRemoteClient(config.DriverAddress, config.TLSConfig)
Expect(err).NotTo(HaveOccurred())
})
Expand All @@ -53,7 +55,6 @@ var _ = Describe("Certify with: ", func() {

Context("given a created volume missing required options", func() {
BeforeEach(func() {
config.CreateConfig.Name = "invalid-configuration"
if _, found := config.CreateConfig.Opts["password"]; !found {
Skip("No password found in create config")
}
Expand All @@ -70,12 +71,12 @@ var _ = Describe("Certify with: ", func() {
errResponse = driverClient.Unmount(testEnv, dockerdriver.UnmountRequest{
Name: config.CreateConfig.Name,
})
Expect(errResponse.Err).To(ContainSubstring("Volume invalid-configuration does not exist"))
Expect(errResponse.Err).To(ContainSubstring(fmt.Sprintf("Volume %s does not exist", config.CreateConfig.Name)))

errResponse = driverClient.Remove(testEnv, dockerdriver.RemoveRequest{
Name: config.CreateConfig.Name,
})
Expect(errResponse.Err).To(ContainSubstring("Volume invalid-configuration does not exist"))
Expect(errResponse.Err).To(ContainSubstring(fmt.Sprintf("Volume %s does not exist", config.CreateConfig.Name)))
})

It("should log an error message", func() {
Expand All @@ -84,6 +85,10 @@ var _ = Describe("Certify with: ", func() {
})

Expect(mountResponse.Err).To(ContainSubstring("Missing mandatory options: username, password"))

dir := fmt.Sprintf("/var/vcap/data/dockerdriver-integration/mount/%s", config.CreateConfig.Name)
dirEntries, err := os.ReadDir(dir)
Expect(err).To(HaveOccurred(), fmt.Sprintf("Found entries %+v\n", dirEntries))
})
})

Expand Down
4 changes: 4 additions & 0 deletions integration/lazy_unmount/lazy_unmount_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("driver-server.started"))
})
var _ = AfterSuite(func() {
session.Interrupt()
Eventually(session).Should(gexec.Exit())
})

0 comments on commit f67e261

Please sign in to comment.