2015-06-12 09:25:32 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-08-04 08:59:55 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-06-12 09:25:32 -04:00
|
|
|
"os/exec"
|
2016-08-04 08:59:55 -04:00
|
|
|
"path/filepath"
|
2015-06-12 09:25:32 -04:00
|
|
|
"strings"
|
|
|
|
|
2015-09-09 09:36:44 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2016-08-04 12:57:34 -04:00
|
|
|
icmd "github.com/docker/docker/pkg/integration/cmd"
|
2015-06-12 09:25:32 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliCreate(c *check.C) {
|
|
|
|
dockerCmd(c, "volume", "create")
|
|
|
|
|
|
|
|
_, err := runCommand(exec.Command(dockerBinary, "volume", "create", "-d", "nosuchdriver"))
|
|
|
|
c.Assert(err, check.Not(check.IsNil))
|
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
// test using hidden --name option
|
2015-06-12 09:25:32 -04:00
|
|
|
out, _ := dockerCmd(c, "volume", "create", "--name=test")
|
|
|
|
name := strings.TrimSpace(out)
|
|
|
|
c.Assert(name, check.Equals, "test")
|
2016-06-14 18:42:30 -04:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "create", "test2")
|
|
|
|
name = strings.TrimSpace(out)
|
|
|
|
c.Assert(name, check.Equals, "test2")
|
2015-06-12 09:25:32 -04:00
|
|
|
}
|
|
|
|
|
2015-10-04 08:09:51 -04:00
|
|
|
func (s *DockerSuite) TestVolumeCliCreateOptionConflict(c *check.C) {
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
|
|
|
out, _, err := dockerCmdWithError("volume", "create", "test", "--driver", "nosuchdriver")
|
2015-10-04 08:09:51 -04:00
|
|
|
c.Assert(err, check.NotNil, check.Commentf("volume create exception name already in use with another driver"))
|
2015-09-23 16:29:14 -04:00
|
|
|
c.Assert(out, checker.Contains, "A volume named test already exists")
|
2015-10-04 08:09:51 -04:00
|
|
|
|
2016-05-16 17:20:29 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Driver }}", "test")
|
2016-06-14 18:42:30 -04:00
|
|
|
_, _, err = dockerCmdWithError("volume", "create", "test", "--driver", strings.TrimSpace(out))
|
2015-10-04 08:09:51 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2016-06-14 18:42:30 -04:00
|
|
|
|
|
|
|
// make sure hidden --name option conflicts with positional arg name
|
|
|
|
out, _, err = dockerCmdWithError("volume", "create", "--name", "test2", "test2")
|
|
|
|
c.Assert(err, check.NotNil, check.Commentf("Conflicting options: either specify --name or provide positional arg, not both"))
|
2015-10-04 08:09:51 -04:00
|
|
|
}
|
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
func (s *DockerSuite) TestVolumeCliInspect(c *check.C) {
|
|
|
|
c.Assert(
|
|
|
|
exec.Command(dockerBinary, "volume", "inspect", "doesntexist").Run(),
|
|
|
|
check.Not(check.IsNil),
|
2015-11-25 08:45:37 -05:00
|
|
|
check.Commentf("volume inspect should error on non-existent volume"),
|
2015-06-12 09:25:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "volume", "create")
|
|
|
|
name := strings.TrimSpace(out)
|
2016-05-16 17:20:29 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", name)
|
2015-06-12 09:25:32 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, name)
|
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
2016-05-16 17:20:29 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", "test")
|
2015-06-12 09:25:32 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "test")
|
|
|
|
}
|
|
|
|
|
2015-11-07 12:11:37 -05:00
|
|
|
func (s *DockerSuite) TestVolumeCliInspectMulti(c *check.C) {
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test1")
|
|
|
|
dockerCmd(c, "volume", "create", "test2")
|
|
|
|
dockerCmd(c, "volume", "create", "not-shown")
|
2015-11-07 12:11:37 -05:00
|
|
|
|
2016-08-04 12:57:34 -04:00
|
|
|
result := dockerCmdWithResult("volume", "inspect", "--format={{ .Name }}", "test1", "test2", "doesntexist", "not-shown")
|
2016-08-16 17:51:38 -04:00
|
|
|
c.Assert(result, icmd.Matches, icmd.Expected{
|
2016-08-04 12:57:34 -04:00
|
|
|
ExitCode: 1,
|
|
|
|
Err: "No such volume: doesntexist",
|
|
|
|
})
|
|
|
|
|
|
|
|
out := result.Stdout()
|
2015-11-07 12:11:37 -05:00
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
2016-08-04 12:57:34 -04:00
|
|
|
c.Assert(len(outArr), check.Equals, 2, check.Commentf("\n%s", out))
|
2015-11-07 12:11:37 -05:00
|
|
|
|
2015-12-07 22:04:38 -05:00
|
|
|
c.Assert(out, checker.Contains, "test1")
|
|
|
|
c.Assert(out, checker.Contains, "test2")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "not-shown")
|
2015-11-07 12:11:37 -05:00
|
|
|
}
|
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "aaa")
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
2016-02-17 03:59:53 -05:00
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "soo")
|
2016-02-17 03:59:53 -05:00
|
|
|
dockerCmd(c, "run", "-v", "soo:"+prefix+"/foo", "busybox", "ls", "/")
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2016-08-04 08:59:55 -04:00
|
|
|
out, _ := dockerCmd(c, "volume", "ls")
|
2015-06-12 09:25:32 -04:00
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
|
|
|
|
|
2016-02-17 03:59:53 -05:00
|
|
|
assertVolList(c, out, []string{"aaa", "soo", "test"})
|
|
|
|
}
|
|
|
|
|
2016-08-04 08:59:55 -04:00
|
|
|
func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "aaa")
|
|
|
|
dockerCmd(c, "volume", "create", "test")
|
|
|
|
dockerCmd(c, "volume", "create", "soo")
|
2016-08-04 08:59:55 -04:00
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
|
|
|
|
|
expected := []string{"aaa", "soo", "test"}
|
|
|
|
var names []string
|
|
|
|
for _, l := range lines {
|
|
|
|
names = append(names, l)
|
|
|
|
}
|
|
|
|
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) {
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "aaa")
|
|
|
|
dockerCmd(c, "volume", "create", "test")
|
|
|
|
dockerCmd(c, "volume", "create", "soo")
|
2016-08-04 08:59:55 -04:00
|
|
|
|
|
|
|
config := `{
|
|
|
|
"volumesFormat": "{{ .Name }} default"
|
|
|
|
}`
|
|
|
|
d, err := ioutil.TempDir("", "integration-cli-")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer os.RemoveAll(d)
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "--config", d, "volume", "ls")
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
|
|
|
|
|
expected := []string{"aaa default", "soo default", "test default"}
|
|
|
|
var names []string
|
|
|
|
for _, l := range lines {
|
|
|
|
names = append(names, l)
|
|
|
|
}
|
|
|
|
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
|
|
|
|
}
|
|
|
|
|
2016-02-17 03:59:53 -05:00
|
|
|
// assertVolList checks volume retrieved with ls command
|
|
|
|
// equals to expected volume list
|
|
|
|
// note: out should be `volume ls [option]` result
|
|
|
|
func assertVolList(c *check.C, out string, expectVols []string) {
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
var volList []string
|
|
|
|
for _, line := range lines[1 : len(lines)-1] {
|
|
|
|
volFields := strings.Fields(line)
|
|
|
|
// wrap all volume name in volList
|
|
|
|
volList = append(volList, volFields[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
// volume ls should contains all expected volumes
|
|
|
|
c.Assert(volList, checker.DeepEquals, expectVols)
|
2015-06-12 09:25:32 -04:00
|
|
|
}
|
|
|
|
|
2015-09-05 18:44:29 -04:00
|
|
|
func (s *DockerSuite) TestVolumeCliLsFilterDangling(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "testnotinuse1")
|
|
|
|
dockerCmd(c, "volume", "create", "testisinuse1")
|
|
|
|
dockerCmd(c, "volume", "create", "testisinuse2")
|
2015-09-05 18:44:29 -04:00
|
|
|
|
|
|
|
// Make sure both "created" (but not started), and started
|
|
|
|
// containers are included in reference counting
|
2015-09-23 19:04:51 -04:00
|
|
|
dockerCmd(c, "run", "--name", "volume-test1", "-v", "testisinuse1:"+prefix+"/foo", "busybox", "true")
|
|
|
|
dockerCmd(c, "create", "--name", "volume-test2", "-v", "testisinuse2:"+prefix+"/foo", "busybox", "true")
|
2015-09-05 18:44:29 -04:00
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "volume", "ls")
|
|
|
|
|
|
|
|
// No filter, all volumes should show
|
|
|
|
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false")
|
|
|
|
|
2016-01-25 14:39:41 -05:00
|
|
|
// Explicitly disabling dangling
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
2015-09-05 18:44:29 -04:00
|
|
|
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true")
|
|
|
|
|
2015-12-13 11:00:39 -05:00
|
|
|
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output
|
2015-09-05 18:44:29 -04:00
|
|
|
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
|
2016-01-04 03:37:01 -05:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=1")
|
|
|
|
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output, dangling also accept 1
|
|
|
|
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=0")
|
|
|
|
// dangling=0 is same as dangling=false case
|
2016-01-25 14:39:41 -05:00
|
|
|
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
2016-01-04 03:37:01 -05:00
|
|
|
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
2016-03-21 03:39:48 -04:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "name=testisin")
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invalidDriver")
|
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
|
|
|
|
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loc")
|
|
|
|
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
|
|
|
|
|
2016-01-04 03:37:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliLsErrorWithInvalidFilterName(c *check.C) {
|
|
|
|
out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "Invalid filter")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliLsWithIncorrectFilterValue(c *check.C) {
|
|
|
|
out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "Invalid filter")
|
2015-09-05 18:44:29 -04:00
|
|
|
}
|
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2015-06-12 09:25:32 -04:00
|
|
|
out, _ := dockerCmd(c, "volume", "create")
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
2015-06-12 09:25:32 -04:00
|
|
|
dockerCmd(c, "volume", "rm", id)
|
|
|
|
dockerCmd(c, "volume", "rm", "test")
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls")
|
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
|
|
|
|
|
|
|
|
volumeID := "testing"
|
2015-09-23 19:04:51 -04:00
|
|
|
dockerCmd(c, "run", "-v", volumeID+":"+prefix+"/foo", "--name=test", "busybox", "sh", "-c", "echo hello > /foo/bar")
|
2015-06-12 09:25:32 -04:00
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "volume", "rm", "testing"))
|
|
|
|
c.Assert(
|
|
|
|
err,
|
|
|
|
check.Not(check.IsNil),
|
|
|
|
check.Commentf("Should not be able to remove volume that is in use by a container\n%s", out))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar")
|
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
|
|
|
|
dockerCmd(c, "rm", "-fv", "test2")
|
|
|
|
dockerCmd(c, "volume", "inspect", volumeID)
|
|
|
|
dockerCmd(c, "rm", "-f", "test")
|
|
|
|
|
2015-09-23 19:04:51 -04:00
|
|
|
out, _ = dockerCmd(c, "run", "--name=test2", "-v", volumeID+":"+prefix+"/foo", "busybox", "sh", "-c", "cat /foo/bar")
|
2015-06-12 09:25:32 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "hello", check.Commentf("volume data was removed"))
|
|
|
|
dockerCmd(c, "rm", "test2")
|
|
|
|
|
|
|
|
dockerCmd(c, "volume", "rm", volumeID)
|
|
|
|
c.Assert(
|
|
|
|
exec.Command("volume", "rm", "doesntexist").Run(),
|
|
|
|
check.Not(check.IsNil),
|
2015-11-25 08:45:37 -05:00
|
|
|
check.Commentf("volume rm should fail with non-existent volume"),
|
2015-06-12 09:25:32 -04:00
|
|
|
)
|
|
|
|
}
|
2015-08-26 20:31:31 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliNoArgs(c *check.C) {
|
|
|
|
out, _ := dockerCmd(c, "volume")
|
2015-10-07 12:22:08 -04:00
|
|
|
// no args should produce the cmd usage output
|
2016-05-16 17:20:29 -04:00
|
|
|
usage := "Usage: docker volume COMMAND"
|
2015-10-07 12:22:08 -04:00
|
|
|
c.Assert(out, checker.Contains, usage)
|
2015-08-26 20:31:31 -04:00
|
|
|
|
|
|
|
// invalid arg should error and show the command usage on stderr
|
|
|
|
_, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg"))
|
2015-10-07 12:22:08 -04:00
|
|
|
c.Assert(err, check.NotNil, check.Commentf(stderr))
|
|
|
|
c.Assert(stderr, checker.Contains, usage)
|
|
|
|
|
|
|
|
// invalid flag should error and show the flag error and cmd usage
|
|
|
|
_, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag"))
|
|
|
|
c.Assert(err, check.NotNil, check.Commentf(stderr))
|
|
|
|
c.Assert(stderr, checker.Contains, usage)
|
2016-05-16 17:20:29 -04:00
|
|
|
c.Assert(stderr, checker.Contains, "unknown flag: --no-such-flag")
|
2015-08-26 20:31:31 -04:00
|
|
|
}
|
2015-12-02 15:24:30 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliInspectTmplError(c *check.C) {
|
|
|
|
out, _ := dockerCmd(c, "volume", "create")
|
|
|
|
name := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, exitCode, err := dockerCmdWithError("volume", "inspect", "--format='{{ .FooBar }}'", name)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("Output: %s", out))
|
|
|
|
c.Assert(exitCode, checker.Equals, 1, check.Commentf("Output: %s", out))
|
|
|
|
c.Assert(out, checker.Contains, "Template parsing error")
|
|
|
|
}
|
2016-02-11 21:48:16 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliCreateWithOpts(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "-d", "local", "test", "--opt=type=tmpfs", "--opt=device=tmpfs", "--opt=o=size=1m,uid=1000")
|
2016-02-11 21:48:16 -05:00
|
|
|
out, _ := dockerCmd(c, "run", "-v", "test:/foo", "busybox", "mount")
|
|
|
|
|
|
|
|
mounts := strings.Split(out, "\n")
|
|
|
|
var found bool
|
|
|
|
for _, m := range mounts {
|
|
|
|
if strings.Contains(m, "/foo") {
|
|
|
|
found = true
|
|
|
|
info := strings.Fields(m)
|
|
|
|
// tmpfs on <path> type tmpfs (rw,relatime,size=1024k,uid=1000)
|
|
|
|
c.Assert(info[0], checker.Equals, "tmpfs")
|
|
|
|
c.Assert(info[2], checker.Equals, "/foo")
|
|
|
|
c.Assert(info[4], checker.Equals, "tmpfs")
|
|
|
|
c.Assert(info[5], checker.Contains, "uid=1000")
|
|
|
|
c.Assert(info[5], checker.Contains, "size=1024k")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Assert(found, checker.Equals, true)
|
|
|
|
}
|
2016-03-16 17:52:34 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliCreateLabel(c *check.C) {
|
|
|
|
testVol := "testvolcreatelabel"
|
|
|
|
testLabel := "foo"
|
|
|
|
testValue := "bar"
|
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
out, _, err := dockerCmdWithError("volume", "create", "--label", testLabel+"="+testValue, testVol)
|
2016-03-16 17:52:34 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2016-05-16 17:20:29 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol)
|
2016-03-16 17:52:34 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, testValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliCreateLabelMultiple(c *check.C) {
|
|
|
|
testVol := "testvolcreatelabel"
|
|
|
|
|
|
|
|
testLabels := map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"baz": "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"volume",
|
|
|
|
"create",
|
|
|
|
testVol,
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range testLabels {
|
|
|
|
args = append(args, "--label", k+"="+v)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError(args...)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
for k, v := range testLabels {
|
2016-05-16 17:20:29 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol)
|
2016-03-16 17:52:34 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, v)
|
|
|
|
}
|
|
|
|
}
|
2016-03-28 04:43:41 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliLsFilterLabels(c *check.C) {
|
|
|
|
testVol1 := "testvolcreatelabel-1"
|
2016-06-14 18:42:30 -04:00
|
|
|
out, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1)
|
2016-03-28 04:43:41 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
testVol2 := "testvolcreatelabel-2"
|
2016-06-14 18:42:30 -04:00
|
|
|
out, _, err = dockerCmdWithError("volume", "create", "--label", "foo=bar2", testVol2)
|
2016-03-28 04:43:41 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo")
|
|
|
|
|
|
|
|
// filter with label=key
|
|
|
|
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
|
|
|
c.Assert(out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=bar1")
|
|
|
|
|
|
|
|
// filter with label=key=value
|
|
|
|
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
|
|
|
c.Assert(out, check.Not(checker.Contains), "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2 in output"))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=non-exist")
|
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist")
|
|
|
|
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
|
|
|
}
|
2016-06-10 10:40:09 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliRmForceUsage(c *check.C) {
|
|
|
|
out, _ := dockerCmd(c, "volume", "create")
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "volume", "rm", "-f", id)
|
|
|
|
dockerCmd(c, "volume", "rm", "--force", "nonexist")
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls")
|
|
|
|
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestVolumeCliRmForce(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
|
|
|
|
|
|
|
name := "test"
|
2016-06-14 18:42:30 -04:00
|
|
|
out, _ := dockerCmd(c, "volume", "create", name)
|
2016-06-10 10:40:09 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
c.Assert(id, checker.Equals, name)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format", "{{.Mountpoint}}", name)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
|
|
|
// Mountpoint is in the form of "/var/lib/docker/volumes/.../_data", removing `/_data`
|
|
|
|
path := strings.TrimSuffix(strings.TrimSpace(out), "/_data")
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command("rm", "-rf", path))
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
dockerCmd(c, "volume", "rm", "-f", "test")
|
|
|
|
out, _ = dockerCmd(c, "volume", "ls")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
2016-06-14 18:42:30 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
2016-06-10 10:40:09 -04:00
|
|
|
out, _ = dockerCmd(c, "volume", "ls")
|
|
|
|
c.Assert(out, checker.Contains, name)
|
|
|
|
}
|