2016-06-29 14:00:11 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-10-31 15:38:00 -04:00
|
|
|
"fmt"
|
2016-06-29 14:00:11 -04:00
|
|
|
"strings"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-06-29 14:00:11 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
out, err := d.Cmd("service", "create", "--mount", "type=volume,source=foo,target=/foo", "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)
|
|
|
|
|
|
|
|
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].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
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecret(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
serviceName := "test-service-secret"
|
|
|
|
testName := "test_secret"
|
|
|
|
id := d.createSecret(c, swarm.SecretSpec{
|
|
|
|
swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
[]byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
testTarget := "testing"
|
|
|
|
|
|
|
|
out, err := d.Cmd("service", "create", "--name", serviceName, "--secret", fmt.Sprintf("%s:%s", testName, testTarget), "busybox", "top")
|
|
|
|
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-01 18:59:16 -04:00
|
|
|
c.Assert(refs[0].Target, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(refs[0].Target.Name, checker.Equals, testTarget)
|
2016-10-31 15:38:00 -04:00
|
|
|
}
|