mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
1d92789b4f
sed -E -i 's#\bcheck\.C\b#testing.T#g' \ -- "integration-cli/check_test.go" "integration-cli/daemon/daemon.go" "integration-cli/daemon/daemon_swarm.go" "integration-cli/daemon_swarm_hack_test.go" "integration-cli/docker_api_attach_test.go" "integration-cli/docker_api_build_test.go" "integration-cli/docker_api_build_windows_test.go" "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_containers_windows_test.go" "integration-cli/docker_api_exec_resize_test.go" "integration-cli/docker_api_exec_test.go" "integration-cli/docker_api_images_test.go" "integration-cli/docker_api_inspect_test.go" "integration-cli/docker_api_logs_test.go" "integration-cli/docker_api_network_test.go" "integration-cli/docker_api_stats_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_api_swarm_service_test.go" "integration-cli/docker_api_swarm_test.go" "integration-cli/docker_api_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_cp_from_container_test.go" "integration-cli/docker_cli_cp_test.go" "integration-cli/docker_cli_cp_to_container_test.go" "integration-cli/docker_cli_cp_to_container_unix_test.go" "integration-cli/docker_cli_cp_utils_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_plugins_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_events_test.go" "integration-cli/docker_cli_events_unix_test.go" "integration-cli/docker_cli_exec_test.go" "integration-cli/docker_cli_exec_unix_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_health_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_info_unix_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_login_test.go" "integration-cli/docker_cli_logout_test.go" "integration-cli/docker_cli_logs_test.go" "integration-cli/docker_cli_netmode_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_logdriver_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_proxy_test.go" "integration-cli/docker_cli_prune_unix_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_pull_test.go" "integration-cli/docker_cli_push_test.go" "integration-cli/docker_cli_registry_user_agent_test.go" "integration-cli/docker_cli_restart_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_save_load_test.go" "integration-cli/docker_cli_save_load_unix_test.go" "integration-cli/docker_cli_search_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_health_test.go" "integration-cli/docker_cli_service_logs_test.go" "integration-cli/docker_cli_service_scale_test.go" "integration-cli/docker_cli_sni_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_stats_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_swarm_unix_test.go" "integration-cli/docker_cli_top_test.go" "integration-cli/docker_cli_update_unix_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_v2_only_test.go" "integration-cli/docker_cli_volume_test.go" "integration-cli/docker_deprecated_api_v124_test.go" "integration-cli/docker_deprecated_api_v124_unix_test.go" "integration-cli/docker_hub_pull_suite_test.go" "integration-cli/docker_utils_test.go" "integration-cli/events_utils_test.go" "integration-cli/fixtures_linux_daemon_test.go" "integration-cli/utils_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/memory/memory_test.go" "pkg/discovery/nodes/nodes_test.go" Signed-off-by: Tibor Vass <tibor@docker.com>
448 lines
17 KiB
Go
448 lines
17 KiB
Go
// +build !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/mount"
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/go-check/check"
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--mount", "type=volume,source=foo,target=/foo,volume-nocopy", "busybox", "top")
|
|
assert.NilError(c, err, out)
|
|
id := strings.TrimSpace(out)
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, id)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
|
}, checker.Equals, true)
|
|
|
|
// check container mount config
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
assert.NilError(c, err, out)
|
|
|
|
var mountConfig []mount.Mount
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
|
assert.Assert(c, mountConfig, checker.HasLen, 1)
|
|
|
|
assert.Assert(c, mountConfig[0].Source, checker.Equals, "foo")
|
|
assert.Assert(c, mountConfig[0].Target, checker.Equals, "/foo")
|
|
assert.Assert(c, mountConfig[0].Type, checker.Equals, mount.TypeVolume)
|
|
assert.Assert(c, mountConfig[0].VolumeOptions, checker.NotNil)
|
|
assert.Assert(c, mountConfig[0].VolumeOptions.NoCopy, checker.True)
|
|
|
|
// check container mounts actual
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
assert.NilError(c, err, out)
|
|
|
|
var mounts []types.MountPoint
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
|
assert.Assert(c, mounts, checker.HasLen, 1)
|
|
|
|
assert.Assert(c, mounts[0].Type, checker.Equals, mount.TypeVolume)
|
|
assert.Assert(c, mounts[0].Name, checker.Equals, "foo")
|
|
assert.Assert(c, mounts[0].Destination, checker.Equals, "/foo")
|
|
assert.Assert(c, mounts[0].RW, checker.Equals, true)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
serviceName := "test-service-secret"
|
|
testName := "test_secret"
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
Annotations: swarm.Annotations{
|
|
Name: testName,
|
|
},
|
|
Data: []byte("TESTINGDATA"),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", testName, "busybox", "top")
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.SecretReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), 1)
|
|
|
|
assert.Assert(c, refs[0].SecretName, checker.Equals, testName)
|
|
assert.Assert(c, refs[0].File, checker.Not(checker.IsNil))
|
|
assert.Assert(c, refs[0].File.Name, checker.Equals, testName)
|
|
assert.Assert(c, refs[0].File.UID, checker.Equals, "0")
|
|
assert.Assert(c, refs[0].File.GID, checker.Equals, "0")
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
d.DeleteSecret(c, testName)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
testPaths := map[string]string{
|
|
"app": "/etc/secret",
|
|
"test_secret": "test_secret",
|
|
"relative_secret": "relative/secret",
|
|
"escapes_in_container": "../secret",
|
|
}
|
|
|
|
var secretFlags []string
|
|
|
|
for testName, testTarget := range testPaths {
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
Annotations: swarm.Annotations{
|
|
Name: testName,
|
|
},
|
|
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
secretFlags = append(secretFlags, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
|
}
|
|
|
|
serviceName := "svc"
|
|
serviceCmd := []string{"service", "create", "--detach", "--no-resolve-image", "--name", serviceName}
|
|
serviceCmd = append(serviceCmd, secretFlags...)
|
|
serviceCmd = append(serviceCmd, "busybox", "top")
|
|
out, err := d.Cmd(serviceCmd...)
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.SecretReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), len(testPaths))
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, 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)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, out, "TESTINGDATA "+testName+" "+testTarget)
|
|
}
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
Annotations: swarm.Annotations{
|
|
Name: "mysecret",
|
|
},
|
|
Data: []byte("TESTINGDATA"),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
serviceName := "svc"
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", "source=mysecret,target=target1", "--secret", "source=mysecret,target=target2", "busybox", "top")
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.SecretReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), 2)
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
|
}, checker.Equals, true)
|
|
|
|
for _, target := range []string{"target1", "target2"} {
|
|
assert.NilError(c, err, out)
|
|
path := filepath.Join("/run/secrets", target)
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, out, "TESTINGDATA")
|
|
}
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *testing.T) {
|
|
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"),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", testName, "busybox", "top")
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.ConfigReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), 1)
|
|
|
|
assert.Assert(c, refs[0].ConfigName, checker.Equals, testName)
|
|
assert.Assert(c, refs[0].File, checker.Not(checker.IsNil))
|
|
assert.Assert(c, refs[0].File.Name, checker.Equals, testName)
|
|
assert.Assert(c, refs[0].File.UID, checker.Equals, "0")
|
|
assert.Assert(c, refs[0].File.GID, checker.Equals, "0")
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
d.DeleteConfig(c, testName)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testing.T) {
|
|
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),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
configFlags = append(configFlags, "--config", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
|
|
}
|
|
|
|
serviceName := "svc"
|
|
serviceCmd := []string{"service", "create", "--detach", "--no-resolve-image", "--name", serviceName}
|
|
serviceCmd = append(serviceCmd, configFlags...)
|
|
serviceCmd = append(serviceCmd, "busybox", "top")
|
|
out, err := d.Cmd(serviceCmd...)
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.ConfigReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), len(testPaths))
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, 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)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, out, "TESTINGDATA "+testName+" "+testTarget)
|
|
}
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
Annotations: swarm.Annotations{
|
|
Name: "myconfig",
|
|
},
|
|
Data: []byte("TESTINGDATA"),
|
|
})
|
|
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
|
|
serviceName := "svc"
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", "source=myconfig,target=target1", "--config", "source=myconfig,target=target2", "busybox", "top")
|
|
assert.NilError(c, err, out)
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Configs }}", serviceName)
|
|
assert.NilError(c, err)
|
|
|
|
var refs []swarm.ConfigReference
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
|
|
assert.Equal(c, len(refs), 2)
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, serviceName)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
|
}, checker.Equals, true)
|
|
|
|
for _, target := range []string{"target1", "target2"} {
|
|
assert.NilError(c, err, out)
|
|
path := filepath.Join("/", target)
|
|
out, err := d.Cmd("exec", task.Status.ContainerStatus.ContainerID, "cat", path)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, out, "TESTINGDATA")
|
|
}
|
|
|
|
out, err = d.Cmd("service", "rm", serviceName)
|
|
assert.NilError(c, err, out)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
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")
|
|
assert.NilError(c, err, out)
|
|
id := strings.TrimSpace(out)
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, id)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
|
}, checker.Equals, true)
|
|
|
|
// check container mount config
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
assert.NilError(c, err, out)
|
|
|
|
var mountConfig []mount.Mount
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
|
|
assert.Assert(c, mountConfig, checker.HasLen, 1)
|
|
|
|
assert.Assert(c, mountConfig[0].Source, checker.Equals, "")
|
|
assert.Assert(c, mountConfig[0].Target, checker.Equals, "/foo")
|
|
assert.Assert(c, mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
|
|
assert.Assert(c, mountConfig[0].TmpfsOptions, checker.NotNil)
|
|
assert.Assert(c, mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
|
|
|
|
// check container mounts actual
|
|
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
|
|
assert.NilError(c, err, out)
|
|
|
|
var mounts []types.MountPoint
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
|
|
assert.Assert(c, mounts, checker.HasLen, 1)
|
|
|
|
assert.Assert(c, mounts[0].Type, checker.Equals, mount.TypeTmpfs)
|
|
assert.Assert(c, mounts[0].Name, checker.Equals, "")
|
|
assert.Assert(c, mounts[0].Destination, checker.Equals, "/foo")
|
|
assert.Assert(c, mounts[0].RW, checker.Equals, true)
|
|
|
|
out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID)
|
|
assert.NilError(c, err, out)
|
|
assert.Assert(c, strings.HasPrefix(strings.TrimSpace(out), "tmpfs on /foo type tmpfs"))
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "size=1024k"))
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) {
|
|
d := s.AddDaemon(c, true, true)
|
|
out, err := d.Cmd("network", "create", "--scope=swarm", "test_swarm_br")
|
|
assert.NilError(c, err, 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")
|
|
assert.NilError(c, err, out)
|
|
id := strings.TrimSpace(out)
|
|
|
|
var tasks []swarm.Task
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
tasks = d.GetServiceTasks(c, id)
|
|
return len(tasks) > 0, nil
|
|
}, checker.Equals, true)
|
|
|
|
task := tasks[0]
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
|
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
task = d.GetTask(c, task.ID)
|
|
}
|
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, 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)
|
|
assert.NilError(c, err, out)
|
|
|
|
// Make sure the only alias seen is the container-id
|
|
var aliases []string
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &aliases), checker.IsNil)
|
|
assert.Assert(c, aliases, checker.HasLen, 1)
|
|
|
|
assert.Assert(c, task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
|
|
}
|