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
18 changes: 17 additions & 1 deletion hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ function install_lxcfs
fi
}

# local-persist is a volume plugin
function install_local_persist
{
echo "Try installing local-persist"
wget --quiet -O /tmp/local-persist \
https://github.com/CWSpear/local-persist/releases/download/v1.3.0/local-persist-linux-amd64
chmod +x /tmp/local-persist
mv /tmp/local-persist /usr/local/bin/
}

function install_nsenter
{
echo "Try installing nsenter"
Expand Down Expand Up @@ -193,7 +203,13 @@ function target
$IMAGE \
bash -c "cd test && go test -c -o integration-test"

#start pouch daemon
install_local_persist

# start local-persist
echo "start local-persist volume plugin"
local-persist > $TMP/volume.log 2 >&1 &

# start pouch daemon
echo "start pouch daemon"
if stat /usr/bin/lxcfs ; then
pouchd --debug --enable-lxcfs=true \
Expand Down
5 changes: 3 additions & 2 deletions test/api_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func (suite *APISystemSuite) TestInfo(c *check.C) {
c.Assert(got.NCPU, check.Equals, int64(runtime.NumCPU()))

// Check the volume drivers
c.Assert(len(got.VolumeDrivers), check.Equals, 3)
c.Assert(len(got.VolumeDrivers), check.Equals, 4)
c.Assert(got.VolumeDrivers[0], check.Equals, "ceph")
c.Assert(got.VolumeDrivers[1], check.Equals, "local")
c.Assert(got.VolumeDrivers[2], check.Equals, "tmpfs")
c.Assert(got.VolumeDrivers[2], check.Equals, "local-persist")
c.Assert(got.VolumeDrivers[3], check.Equals, "tmpfs")
}

// TestVersion tests /version API.
Expand Down
22 changes: 22 additions & 0 deletions test/api_volume_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ func (suite *APIVolumeCreateSuite) TestVolumeCreateOk(c *check.C) {
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}

// TestPluginVolumeCreateOk tests creating a volume which created by volume plugin
func (suite *APIVolumeCreateSuite) TestPluginVolumeCreateOk(c *check.C) {
vol := "TestPluginVolumeCreateOk"

obj := map[string]interface{}{
"Driver": "local-persist",
"Name": vol,
"DriverOpts": map[string]string{"mountpoint": "/data/images"},
}

path := "/volumes/create"
body := request.WithJSONBody(obj)
resp, err := request.Post(path, body)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 201)

path = "/volumes/" + vol
resp, err = request.Delete(path)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}
17 changes: 12 additions & 5 deletions test/api_volume_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ func (suite *APIVolumeListSuite) SetUpTest(c *check.C) {
// TestVolumeListOk tests if list volumes is OK.
func (suite *APIVolumeListSuite) TestVolumeListOk(c *check.C) {
// Create a volume with the name "TestVolume1".
err := CreateVolume(c, "TestVolume1", "local")
err := CreateVolume(c, "TestVolume1", "local", nil)
c.Assert(err, check.IsNil)
defer RemoveVolume(c, "TestVolume1")

// Create a volume with the name "TestVolume1".
err = CreateVolume(c, "TestVolume2", "local")
// Create a volume with the name "TestVolume2".
err = CreateVolume(c, "TestVolume2", "local", nil)
c.Assert(err, check.IsNil)
defer RemoveVolume(c, "TestVolume2")

// Create a volume with the name "TestVolume3".
options := map[string]string{"mountpoint": "/data/TestVolume3"}
err = CreateVolume(c, "TestVolume3", "local", options)
c.Assert(err, check.IsNil)

// Test volume list feature.
path := "/volumes"
resp, err := request.Get(path)
Expand All @@ -46,9 +51,11 @@ func (suite *APIVolumeListSuite) TestVolumeListOk(c *check.C) {
// Check response having the pre-created two volumes.
found := 0
for _, volume := range volumeListResp.Volumes {
if volume.Name == "TestVolume1" || volume.Name == "TestVolume2" {
if volume.Name == "TestVolume1" ||
volume.Name == "TestVolume2" ||
volume.Name == "TestVolume3" {
found++
}
}
c.Assert(found, check.Equals, 2)
c.Assert(found, check.Equals, 3)
}
18 changes: 18 additions & 0 deletions test/cli_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ func (suite *PouchVolumeSuite) TestVolumeUsingByContainer(c *check.C) {
command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)
}

// TestVolumePluginUsingByContainer tests creating container using the plugin volume.
func (suite *PouchVolumeSuite) TestVolumePluginUsingByContainer(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
volumeName := "volume_" + funcname
command.PouchRun("volume", "create", "--name", volumeName, "-d", "local-persist", "-o", "mountpoint=/data/volume1").Assert(c, icmd.Success)
command.PouchRun("run", "-d", "-v", volumeName+":/mnt", "--name", funcname, busyboxImage, "top").Assert(c, icmd.Success)

// delete the container.
command.PouchRun("rm", "-f", funcname).Assert(c, icmd.Success)
// delete the volume.
command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)
}

// TestVolumeBindReplaceMode tests the volume "direct replace(dr)" mode.
func (suite *PouchVolumeSuite) TestVolumeBindReplaceMode(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
Expand Down
7 changes: 4 additions & 3 deletions test/util_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ func StartContainerExec(c *check.C, execid string, tty bool, detach bool) (*http
}

// CreateVolume creates a volume in pouchd.
func CreateVolume(c *check.C, name, driver string) error {
func CreateVolume(c *check.C, name, driver string, options map[string]string) error {
obj := map[string]interface{}{
"Driver": driver,
"Name": name,
"Driver": driver,
"Name": name,
"DriverOpts": options,
}
path := "/volumes/create"
body := request.WithJSONBody(obj)
Expand Down