2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-06-21 09:15:17 +00:00
|
|
|
"encoding/json"
|
2015-09-10 23:12:00 +00:00
|
|
|
"fmt"
|
2015-10-26 00:12:22 +00:00
|
|
|
"net"
|
2015-10-27 20:12:33 +00:00
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2016-12-30 17:23:00 +00:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-09 09:17:53 +00:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2018-04-13 15:02:56 +00:00
|
|
|
testdaemon "github.com/docker/docker/internal/test/daemon"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2019-04-04 13:23:19 +00:00
|
|
|
"gotest.tools/assert"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure docker info succeeds
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ := dockerCmd(c, "info")
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-09 11:01:39 +00:00
|
|
|
// always shown fields
|
|
|
|
stringsToCheck := []string{
|
|
|
|
"ID:",
|
|
|
|
"Containers:",
|
2015-10-27 20:12:33 +00:00
|
|
|
" Running:",
|
|
|
|
" Paused:",
|
|
|
|
" Stopped:",
|
2015-04-09 11:01:39 +00:00
|
|
|
"Images:",
|
2015-06-13 07:39:19 +00:00
|
|
|
"OSType:",
|
|
|
|
"Architecture:",
|
2015-04-09 11:01:39 +00:00
|
|
|
"Logging Driver:",
|
|
|
|
"Operating System:",
|
|
|
|
"CPUs:",
|
|
|
|
"Total Memory:",
|
|
|
|
"Kernel Version:",
|
2015-05-21 17:48:36 +00:00
|
|
|
"Storage Driver:",
|
2015-10-23 06:08:26 +00:00
|
|
|
"Volume:",
|
|
|
|
"Network:",
|
2016-07-24 20:00:15 +00:00
|
|
|
"Live Restore Enabled:",
|
2015-05-21 17:48:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:32:06 +00:00
|
|
|
if testEnv.OSType == "linux" {
|
2016-10-24 22:18:58 +00:00
|
|
|
stringsToCheck = append(stringsToCheck, "Init Binary:", "Security Options:", "containerd version:", "runc version:", "init version:")
|
2016-09-07 18:14:49 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 14:13:23 +00:00
|
|
|
if DaemonIsLinux() {
|
2016-06-20 19:14:27 +00:00
|
|
|
stringsToCheck = append(stringsToCheck, "Runtimes:", "Default Runtime: runc")
|
2016-05-23 21:49:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:30:05 +00:00
|
|
|
if testEnv.DaemonInfo.ExperimentalBuild {
|
2015-05-21 17:48:36 +00:00
|
|
|
stringsToCheck = append(stringsToCheck, "Experimental: true")
|
2016-10-06 14:09:54 +00:00
|
|
|
} else {
|
|
|
|
stringsToCheck = append(stringsToCheck, "Experimental: false")
|
2015-05-21 17:48:36 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
for _, linePrefix := range stringsToCheck {
|
2015-10-20 05:38:55 +00:00
|
|
|
c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 23:12:00 +00:00
|
|
|
|
2016-06-21 09:15:17 +00:00
|
|
|
// TestInfoFormat tests `docker info --format`
|
|
|
|
func (s *DockerSuite) TestInfoFormat(c *check.C) {
|
|
|
|
out, status := dockerCmd(c, "info", "--format", "{{json .}}")
|
|
|
|
c.Assert(status, checker.Equals, 0)
|
|
|
|
var m map[string]interface{}
|
|
|
|
err := json.Unmarshal([]byte(out), &m)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-06-21 09:15:17 +00:00
|
|
|
_, _, err = dockerCmdWithError("info", "--format", "{{.badString}}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-06-21 09:15:17 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:12:00 +00:00
|
|
|
// TestInfoDiscoveryBackend verifies that a daemon run with `--cluster-advertise` and
|
|
|
|
// `--cluster-store` properly show the backend's endpoint in info output.
|
|
|
|
func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
2015-09-10 23:12:00 +00:00
|
|
|
|
2018-04-13 15:02:56 +00:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2015-09-10 23:12:00 +00:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
2015-10-26 00:12:22 +00:00
|
|
|
discoveryAdvertise := "1.1.1.1:2375"
|
2016-12-09 22:20:14 +00:00
|
|
|
d.Start(c, fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise))
|
|
|
|
defer d.Stop(c)
|
2015-09-10 23:12:00 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-03-28 07:46:53 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise))
|
2015-10-26 00:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
|
|
|
|
// an invalid `--cluster-advertise` configuration
|
|
|
|
func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
2015-10-26 00:12:22 +00:00
|
|
|
|
2018-04-13 15:02:56 +00:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2015-10-26 00:12:22 +00:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
|
|
|
|
// --cluster-advertise with an invalid string is an error
|
2016-12-09 22:20:14 +00:00
|
|
|
err := d.StartWithError(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2015-10-26 00:12:22 +00:00
|
|
|
|
|
|
|
// --cluster-advertise without --cluster-store is also an error
|
2016-12-09 22:20:14 +00:00
|
|
|
err = d.StartWithError("--cluster-advertise=1.1.1.1:2375")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2015-10-26 00:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestInfoDiscoveryAdvertiseInterfaceName verifies that a daemon run with `--cluster-advertise`
|
|
|
|
// configured with interface name properly show the advertise ip-address in info output.
|
|
|
|
func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, Network, DaemonIsLinux)
|
2015-10-26 00:12:22 +00:00
|
|
|
|
2018-04-13 15:02:56 +00:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2015-10-26 00:12:22 +00:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
discoveryAdvertise := "eth0"
|
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
d.Start(c, fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise))
|
|
|
|
defer d.Stop(c)
|
2015-10-26 00:12:22 +00:00
|
|
|
|
|
|
|
iface, err := net.InterfaceByName(discoveryAdvertise)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2015-10-26 00:12:22 +00:00
|
|
|
addrs, err := iface.Addrs()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, len(addrs) > 0)
|
2015-10-26 00:12:22 +00:00
|
|
|
ip, _, err := net.ParseCIDR(addrs[0].String())
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2015-10-26 00:12:22 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-03-28 07:46:53 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String()))
|
2015-09-10 23:12:00 +00:00
|
|
|
}
|
2015-10-27 20:12:33 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
2017-09-08 15:16:15 +00:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2015-10-27 20:12:33 +00:00
|
|
|
dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
out, _ := dockerCmd(c, "info")
|
2017-09-08 15:16:15 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
|
2015-10-27 20:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
2016-09-09 00:31:04 +00:00
|
|
|
testRequires(c, IsPausable)
|
2015-10-27 20:12:33 +00:00
|
|
|
|
2017-09-08 15:16:15 +00:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2017-04-16 21:39:30 +00:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-10-27 20:12:33 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "pause", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
2017-09-08 15:16:15 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
|
2015-10-27 20:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
2017-09-08 15:16:15 +00:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2015-10-27 20:12:33 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "stop", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
2017-09-08 15:16:15 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1))
|
2015-10-27 20:12:33 +00:00
|
|
|
}
|
2016-02-01 23:09:25 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
2016-02-01 23:09:25 +00:00
|
|
|
|
2018-04-13 15:02:56 +00:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2016-12-09 22:20:14 +00:00
|
|
|
d.Start(c, "--debug")
|
|
|
|
defer d.Stop(c)
|
2016-02-01 23:09:25 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("--debug", "info")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-03-28 07:46:53 +00:00
|
|
|
c.Assert(out, checker.Contains, "Debug Mode (client): true\n")
|
|
|
|
c.Assert(out, checker.Contains, "Debug Mode (server): true\n")
|
2016-02-01 23:09:25 +00:00
|
|
|
c.Assert(out, checker.Contains, "File Descriptors")
|
|
|
|
c.Assert(out, checker.Contains, "Goroutines")
|
|
|
|
c.Assert(out, checker.Contains, "System Time")
|
|
|
|
c.Assert(out, checker.Contains, "EventsListeners")
|
|
|
|
c.Assert(out, checker.Contains, "Docker Root Dir")
|
|
|
|
}
|
2016-02-16 22:45:48 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
2016-02-16 22:45:48 +00:00
|
|
|
|
|
|
|
registryCIDR := "192.168.1.0/24"
|
|
|
|
registryHost := "insecurehost.com:5000"
|
|
|
|
|
2018-04-13 15:02:56 +00:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2016-12-09 22:20:14 +00:00
|
|
|
d.Start(c, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
|
|
|
|
defer d.Stop(c)
|
2016-02-16 22:45:48 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-04-25 10:40:24 +00:00
|
|
|
c.Assert(out, checker.Contains, "Insecure Registries:\n")
|
2016-02-16 22:45:48 +00:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
|
|
|
|
}
|
2016-08-29 18:50:11 +00:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
|
2016-08-29 18:50:11 +00:00
|
|
|
|
|
|
|
registryMirror1 := "https://192.168.1.2"
|
|
|
|
registryMirror2 := "http://registry.mirror.com:5000"
|
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
s.d.Start(c, "--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2)
|
2016-08-29 18:50:11 +00:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("info")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-08-29 18:50:11 +00:00
|
|
|
c.Assert(out, checker.Contains, "Registry Mirrors:\n")
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror2))
|
|
|
|
}
|
2016-07-12 12:08:05 +00:00
|
|
|
|
2017-09-08 15:16:15 +00:00
|
|
|
func existingContainerStates(c *check.C) map[string]int {
|
|
|
|
out, _ := dockerCmd(c, "info", "--format", "{{json .}}")
|
|
|
|
var m map[string]interface{}
|
|
|
|
err := json.Unmarshal([]byte(out), &m)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-09-08 15:16:15 +00:00
|
|
|
res := map[string]int{}
|
|
|
|
res["Containers"] = int(m["Containers"].(float64))
|
|
|
|
res["ContainersRunning"] = int(m["ContainersRunning"].(float64))
|
|
|
|
res["ContainersPaused"] = int(m["ContainersPaused"].(float64))
|
|
|
|
res["ContainersStopped"] = int(m["ContainersStopped"].(float64))
|
|
|
|
return res
|
|
|
|
}
|