diff --git a/hack/make.sh b/hack/make.sh index f6843ec94..280d3f6d4 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -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" @@ -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 \ diff --git a/test/api_system_test.go b/test/api_system_test.go index 28a60fa1a..3e3de65f9 100644 --- a/test/api_system_test.go +++ b/test/api_system_test.go @@ -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. diff --git a/test/api_volume_create_test.go b/test/api_volume_create_test.go index e25177247..0a6db4259 100644 --- a/test/api_volume_create_test.go +++ b/test/api_volume_create_test.go @@ -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) +} diff --git a/test/api_volume_list_test.go b/test/api_volume_list_test.go index b8f24dfaa..79fad6ae7 100644 --- a/test/api_volume_list_test.go +++ b/test/api_volume_list_test.go @@ -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) @@ -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) } diff --git a/test/cli_volume_test.go b/test/cli_volume_test.go index 5ccc015d1..a2115cc58 100644 --- a/test/cli_volume_test.go +++ b/test/cli_volume_test.go @@ -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) diff --git a/test/util_api.go b/test/util_api.go index 99a2237d6..580d1fd94 100644 --- a/test/util_api.go +++ b/test/util_api.go @@ -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)