2016-06-29 14:00:11 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-10-31 15:38:00 -04:00
|
|
|
"fmt"
|
2017-04-28 19:45:37 -04:00
|
|
|
"path/filepath"
|
2016-06-29 14:00:11 -04:00
|
|
|
"strings"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-10-31 09:53:01 -04:00
|
|
|
"github.com/docker/docker/api/types/mount"
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-06-29 14:00:11 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--mount", "type=volume,source=foo,target=/foo,volume-nocopy", "busybox", "top")
|
2016-06-29 14:00:11 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks = d.GetServiceTasks(c, id)
|
2016-06-29 14:00:11 -04:00
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
2016-12-09 04:17:53 -05:00
|
|
|
task = d.GetTask(c, task.ID)
|
2016-06-29 14:00:11 -04:00
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
2016-10-31 09:53:01 -04:00
|
|
|
// check container mount config
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
var mountConfig []mount.Mount
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
|
|
|
c.Assert(mountConfig, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(mountConfig[0].Source, checker.Equals, "foo")
|
|
|
|
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
|
|
|
|
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeVolume)
|
|
|
|
c.Assert(mountConfig[0].VolumeOptions, checker.NotNil)
|
|
|
|
c.Assert(mountConfig[0].VolumeOptions.NoCopy, checker.True)
|
|
|
|
|
|
|
|
// check container mounts actual
|
2016-06-29 14:00:11 -04:00
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
var mounts []types.MountPoint
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
|
|
|
c.Assert(mounts, checker.HasLen, 1)
|
|
|
|
|
2016-10-31 09:53:01 -04:00
|
|
|
c.Assert(mounts[0].Type, checker.Equals, mount.TypeVolume)
|
2016-06-29 14:00:11 -04:00
|
|
|
c.Assert(mounts[0].Name, checker.Equals, "foo")
|
|
|
|
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
|
2016-07-05 14:43:28 -04:00
|
|
|
c.Assert(mounts[0].RW, checker.Equals, true)
|
2016-06-29 14:00:11 -04:00
|
|
|
}
|
2016-10-31 15:38:00 -04:00
|
|
|
|
2016-11-03 15:56:05 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
serviceName := "test-service-secret"
|
|
|
|
testName := "test_secret"
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
2017-03-20 04:27:51 -04:00
|
|
|
Annotations: swarm.Annotations{
|
2016-11-03 15:56:05 -04:00
|
|
|
Name: testName,
|
|
|
|
},
|
2017-03-20 04:27:51 -04:00
|
|
|
Data: []byte("TESTINGDATA"),
|
2016-11-03 15:56:05 -04:00
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", serviceName, "--secret", testName, "busybox", "top")
|
2016-11-03 15:56:05 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.SecretReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(refs[0].SecretName, checker.Equals, testName)
|
2016-11-15 10:04:36 -05:00
|
|
|
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].File.Name, checker.Equals, testName)
|
|
|
|
c.Assert(refs[0].File.UID, checker.Equals, "0")
|
|
|
|
c.Assert(refs[0].File.GID, checker.Equals, "0")
|
2016-10-31 15:38:00 -04:00
|
|
|
|
2017-04-11 13:34:19 -04:00
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
2016-10-31 15:38:00 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2017-04-11 13:34:19 -04:00
|
|
|
d.DeleteSecret(c, testName)
|
|
|
|
}
|
2016-10-31 15:38:00 -04:00
|
|
|
|
2017-04-11 13:34:19 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2016-10-31 15:38:00 -04:00
|
|
|
|
2017-04-11 13:34:19 -04:00
|
|
|
testPaths := map[string]string{
|
2017-04-28 19:45:37 -04:00
|
|
|
"app": "/etc/secret",
|
|
|
|
"test_secret": "test_secret",
|
|
|
|
"relative_secret": "relative/secret",
|
|
|
|
"escapes_in_container": "../secret",
|
2017-04-11 13:34:19 -04:00
|
|
|
}
|
2017-04-28 19:45:37 -04:00
|
|
|
|
|
|
|
var secretFlags []string
|
|
|
|
|
2017-04-11 13:34:19 -04:00
|
|
|
for testName, testTarget := range testPaths {
|
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
2017-04-28 19:45:37 -04:00
|
|
|
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
|
2017-04-11 13:34:19 -04:00
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
secretFlags = append(secretFlags, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceName := "svc"
|
2017-05-18 15:23:28 -04:00
|
|
|
serviceCmd := []string{"service", "create", "--no-resolve-image", "--name", serviceName}
|
2017-04-28 19:45:37 -04:00
|
|
|
serviceCmd = append(serviceCmd, secretFlags...)
|
|
|
|
serviceCmd = append(serviceCmd, "busybox", "top")
|
|
|
|
out, err := d.Cmd(serviceCmd...)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.SecretReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, len(testPaths))
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
2017-04-11 13:34:19 -04:00
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
|
|
task = d.GetTask(c, task.ID)
|
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
for testName, testTarget := range testPaths {
|
|
|
|
path := testTarget
|
|
|
|
if !filepath.IsAbs(path) {
|
|
|
|
path = filepath.Join("/run/secrets", path)
|
|
|
|
}
|
|
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
2017-04-11 13:34:19 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-04-28 19:45:37 -04:00
|
|
|
c.Assert(out, checker.Equals, "TESTINGDATA "+testName+" "+testTarget)
|
|
|
|
}
|
2017-04-11 13:34:19 -04:00
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
}
|
2017-04-11 13:34:19 -04:00
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2017-04-11 13:34:19 -04:00
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "mysecret",
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
|
|
|
serviceName := "svc"
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", serviceName, "--secret", "source=mysecret,target=target1", "--secret", "source=mysecret,target=target2", "busybox", "top")
|
2017-04-28 19:45:37 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.SecretReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 2)
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
|
|
task = d.GetTask(c, task.ID)
|
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
2017-04-11 13:34:19 -04:00
|
|
|
|
2017-04-28 19:45:37 -04:00
|
|
|
for _, target := range []string{"target1", "target2"} {
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
path := filepath.Join("/run/secrets", target)
|
|
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "TESTINGDATA")
|
2017-04-11 13:34:19 -04:00
|
|
|
}
|
2017-04-28 19:45:37 -04:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2016-10-31 15:38:00 -04:00
|
|
|
}
|
2016-10-31 09:53:01 -04:00
|
|
|
|
2017-04-03 20:59:09 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
serviceName := "test-service-config"
|
|
|
|
testName := "test_config"
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", serviceName, "--config", testName, "busybox", "top")
|
2017-04-03 20:59:09 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.ConfigReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(refs[0].ConfigName, checker.Equals, testName)
|
|
|
|
c.Assert(refs[0].File, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].File.Name, checker.Equals, testName)
|
|
|
|
c.Assert(refs[0].File.UID, checker.Equals, "0")
|
|
|
|
c.Assert(refs[0].File.GID, checker.Equals, "0")
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
d.DeleteConfig(c, testName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
testPaths := map[string]string{
|
|
|
|
"app": "/etc/config",
|
|
|
|
"test_config": "test_config",
|
|
|
|
"relative_config": "relative/config",
|
|
|
|
}
|
|
|
|
|
|
|
|
var configFlags []string
|
|
|
|
|
|
|
|
for testName, testTarget := range testPaths {
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
|
|
|
|
configFlags = append(configFlags, "--config", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceName := "svc"
|
2017-05-18 15:23:28 -04:00
|
|
|
serviceCmd := []string{"service", "create", "--no-resolve-image", "--name", serviceName}
|
2017-04-03 20:59:09 -04:00
|
|
|
serviceCmd = append(serviceCmd, configFlags...)
|
|
|
|
serviceCmd = append(serviceCmd, "busybox", "top")
|
|
|
|
out, err := d.Cmd(serviceCmd...)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.ConfigReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, len(testPaths))
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
|
|
task = d.GetTask(c, task.ID)
|
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
for testName, testTarget := range testPaths {
|
|
|
|
path := testTarget
|
|
|
|
if !filepath.IsAbs(path) {
|
|
|
|
path = filepath.Join("/", path)
|
|
|
|
}
|
|
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "TESTINGDATA "+testName+" "+testTarget)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "myconfig",
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
|
|
|
|
serviceName := "svc"
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", serviceName, "--config", "source=myconfig,target=target1", "--config", "source=myconfig,target=target2", "busybox", "top")
|
2017-04-03 20:59:09 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
var refs []swarm.ConfigReference
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
|
|
c.Assert(refs, checker.HasLen, 2)
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
|
|
task = d.GetTask(c, task.ID)
|
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
for _, target := range []string{"target1", "target2"} {
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
path := filepath.Join("/", target)
|
|
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "TESTINGDATA")
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
}
|
|
|
|
|
2016-10-31 09:53:01 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2017-05-18 15:23:28 -04:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--mount", "type=tmpfs,target=/foo,tmpfs-size=1MB", "busybox", "sh", "-c", "mount | grep foo; tail -f /dev/null")
|
2016-10-31 09:53:01 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks = d.GetServiceTasks(c, id)
|
2016-10-31 09:53:01 -04:00
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
2016-12-09 04:17:53 -05:00
|
|
|
task = d.GetTask(c, task.ID)
|
2016-10-31 09:53:01 -04:00
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
// check container mount config
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
var mountConfig []mount.Mount
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
|
|
|
c.Assert(mountConfig, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(mountConfig[0].Source, checker.Equals, "")
|
|
|
|
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
|
|
|
|
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
|
2016-12-02 11:43:47 -05:00
|
|
|
c.Assert(mountConfig[0].TmpfsOptions, checker.NotNil)
|
|
|
|
c.Assert(mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
|
2016-10-31 09:53:01 -04:00
|
|
|
|
|
|
|
// check container mounts actual
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
var mounts []types.MountPoint
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
|
|
|
c.Assert(mounts, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(mounts[0].Type, checker.Equals, mount.TypeTmpfs)
|
|
|
|
c.Assert(mounts[0].Name, checker.Equals, "")
|
|
|
|
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
|
|
|
|
c.Assert(mounts[0].RW, checker.Equals, true)
|
|
|
|
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.HasPrefix, "tmpfs on /foo type tmpfs")
|
2016-12-02 11:43:47 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, "size=1024k")
|
2016-10-31 09:53:01 -04:00
|
|
|
}
|
2017-06-07 14:14:14 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
out, err := d.Cmd("network", "create", "--scope=swarm", "test_swarm_br")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--network=name=test_swarm_br,alias=srv_alias", "--name=alias_tst_container", "busybox", "top")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
var tasks []swarm.Task
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
tasks = d.GetServiceTasks(c, id)
|
|
|
|
return len(tasks) > 0, nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
task := tasks[0]
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
|
|
task = d.GetTask(c, task.ID)
|
|
|
|
}
|
|
|
|
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
|
|
|
}, checker.Equals, true)
|
|
|
|
|
|
|
|
// check container alias config
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .NetworkSettings.Networks.test_swarm_br.Aliases}}", task.Status.ContainerStatus.ContainerID)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
// Make sure the only alias seen is the container-id
|
|
|
|
var aliases []string
|
|
|
|
c.Assert(json.Unmarshal([]byte(out), &aliases), checker.IsNil)
|
|
|
|
c.Assert(aliases, checker.HasLen, 1)
|
|
|
|
|
|
|
|
c.Assert(task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
|
|
|
|
}
|