2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-06-21 05:15:17 -04:00
|
|
|
"encoding/json"
|
2015-09-10 19:12:00 -04:00
|
|
|
"fmt"
|
2015-10-25 20:12:22 -04:00
|
|
|
"net"
|
2015-10-27 16:12:33 -04:00
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure docker info succeeds
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
|
2015-07-20 02:55:40 -04:00
|
|
|
out, _ := dockerCmd(c, "info")
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-04-09 07:01:39 -04:00
|
|
|
// always shown fields
|
|
|
|
stringsToCheck := []string{
|
|
|
|
"ID:",
|
|
|
|
"Containers:",
|
2015-10-27 16:12:33 -04:00
|
|
|
" Running:",
|
|
|
|
" Paused:",
|
|
|
|
" Stopped:",
|
2015-04-09 07:01:39 -04:00
|
|
|
"Images:",
|
2015-06-13 03:39:19 -04:00
|
|
|
"OSType:",
|
|
|
|
"Architecture:",
|
2015-04-09 07:01:39 -04:00
|
|
|
"Logging Driver:",
|
|
|
|
"Operating System:",
|
|
|
|
"CPUs:",
|
|
|
|
"Total Memory:",
|
|
|
|
"Kernel Version:",
|
2015-05-21 13:48:36 -04:00
|
|
|
"Storage Driver:",
|
2015-10-23 02:08:26 -04:00
|
|
|
"Volume:",
|
|
|
|
"Network:",
|
2016-07-24 16:00:15 -04:00
|
|
|
"Live Restore Enabled:",
|
2015-05-21 13:48:36 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() == "linux" {
|
2016-10-24 18:18:58 -04:00
|
|
|
stringsToCheck = append(stringsToCheck, "Init Binary:", "Security Options:", "containerd version:", "runc version:", "init version:")
|
2016-09-07 14:14:49 -04:00
|
|
|
}
|
|
|
|
|
2016-12-16 09:13:23 -05:00
|
|
|
if DaemonIsLinux() {
|
2016-06-20 15:14:27 -04:00
|
|
|
stringsToCheck = append(stringsToCheck, "Runtimes:", "Default Runtime: runc")
|
2016-05-23 17:49:50 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.ExperimentalDaemon() {
|
2015-05-21 13:48:36 -04:00
|
|
|
stringsToCheck = append(stringsToCheck, "Experimental: true")
|
2016-10-06 10:09:54 -04:00
|
|
|
} else {
|
|
|
|
stringsToCheck = append(stringsToCheck, "Experimental: false")
|
2015-05-21 13:48:36 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
for _, linePrefix := range stringsToCheck {
|
2015-10-20 01:38:55 -04:00
|
|
|
c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 19:12:00 -04:00
|
|
|
|
2016-06-21 05:15:17 -04: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)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
_, _, err = dockerCmdWithError("info", "--format", "{{.badString}}")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
}
|
|
|
|
|
2015-09-10 19:12:00 -04: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) {
|
2016-01-08 16:49:43 -05:00
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
2015-09-10 19:12:00 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2015-09-10 19:12:00 -04:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
2015-10-25 20:12:22 -04:00
|
|
|
discoveryAdvertise := "1.1.1.1:2375"
|
2016-12-09 17:20:14 -05:00
|
|
|
d.Start(c, fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise))
|
|
|
|
defer d.Stop(c)
|
2015-09-10 19:12:00 -04:00
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-03-28 03:46:53 -04: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-25 20:12:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
|
|
|
|
// an invalid `--cluster-advertise` configuration
|
|
|
|
func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
|
2016-01-08 16:49:43 -05:00
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
2015-10-25 20:12:22 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2015-10-25 20:12:22 -04:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
|
|
|
|
// --cluster-advertise with an invalid string is an error
|
2016-12-09 17:20:14 -05:00
|
|
|
err := d.StartWithError(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid")
|
|
|
|
c.Assert(err, checker.NotNil)
|
2015-10-25 20:12:22 -04:00
|
|
|
|
|
|
|
// --cluster-advertise without --cluster-store is also an error
|
2016-12-09 17:20:14 -05:00
|
|
|
err = d.StartWithError("--cluster-advertise=1.1.1.1:2375")
|
|
|
|
c.Assert(err, checker.NotNil)
|
2015-10-25 20:12:22 -04: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) {
|
2016-01-08 16:49:43 -05:00
|
|
|
testRequires(c, SameHostDaemon, Network, DaemonIsLinux)
|
2015-10-25 20:12:22 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2015-10-25 20:12:22 -04:00
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
discoveryAdvertise := "eth0"
|
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
d.Start(c, fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise))
|
|
|
|
defer d.Stop(c)
|
2015-10-25 20:12:22 -04:00
|
|
|
|
|
|
|
iface, err := net.InterfaceByName(discoveryAdvertise)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
addrs, err := iface.Addrs()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(addrs), checker.GreaterThan, 0)
|
|
|
|
ip, _, err := net.ParseCIDR(addrs[0].String())
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-03-28 03:46:53 -04: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 19:12:00 -04:00
|
|
|
}
|
2015-10-27 16:12:33 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
2017-09-08 11:16:15 -04:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2015-10-27 16:12:33 -04:00
|
|
|
dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
out, _ := dockerCmd(c, "info")
|
2017-09-08 11:16:15 -04: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 16:12:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
2016-09-08 20:31:04 -04:00
|
|
|
testRequires(c, IsPausable)
|
2015-10-27 16:12:33 -04:00
|
|
|
|
2017-09-08 11:16:15 -04:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-10-27 16:12:33 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "pause", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
2017-09-08 11:16:15 -04: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 16:12:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
2017-09-08 11:16:15 -04:00
|
|
|
existing := existingContainerStates(c)
|
|
|
|
|
2015-10-27 16:12:33 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "stop", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
2017-09-08 11:16:15 -04: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 16:12:33 -04:00
|
|
|
}
|
2016-02-01 18:09:25 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2016-12-09 17:20:14 -05:00
|
|
|
d.Start(c, "--debug")
|
|
|
|
defer d.Stop(c)
|
2016-02-01 18:09:25 -05:00
|
|
|
|
|
|
|
out, err := d.Cmd("--debug", "info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-03-28 03:46:53 -04:00
|
|
|
c.Assert(out, checker.Contains, "Debug Mode (client): true\n")
|
|
|
|
c.Assert(out, checker.Contains, "Debug Mode (server): true\n")
|
2016-02-01 18:09:25 -05: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 17:45:48 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
|
|
|
|
|
|
|
registryCIDR := "192.168.1.0/24"
|
|
|
|
registryHost := "insecurehost.com:5000"
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2016-12-09 17:20:14 -05:00
|
|
|
d.Start(c, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
|
|
|
|
defer d.Stop(c)
|
2016-02-16 17:45:48 -05:00
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-04-25 06:40:24 -04:00
|
|
|
c.Assert(out, checker.Contains, "Insecure Registries:\n")
|
2016-02-16 17:45:48 -05:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
|
|
|
|
}
|
2016-08-29 14:50:11 -04:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
|
|
|
|
|
|
|
registryMirror1 := "https://192.168.1.2"
|
|
|
|
registryMirror2 := "http://registry.mirror.com:5000"
|
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c, "--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2)
|
2016-08-29 14:50:11 -04:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
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 08:08:05 -04:00
|
|
|
|
2017-09-08 11:16:15 -04: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)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
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
|
|
|
|
}
|