2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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
|
|
|
|
2015-09-10 19:12:00 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-05-21 13:48:36 -04:00
|
|
|
"github.com/docker/docker/utils"
|
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:",
|
2015-05-21 13:48:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if utils.ExperimentalBuild() {
|
|
|
|
stringsToCheck = append(stringsToCheck, "Experimental: true")
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
d := NewDaemon(c)
|
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
2015-10-25 20:12:22 -04:00
|
|
|
discoveryAdvertise := "1.1.1.1:2375"
|
|
|
|
err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise))
|
2015-10-20 01:38:55 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-09-10 19:12:00 -04:00
|
|
|
defer d.Stop()
|
|
|
|
|
|
|
|
out, err := d.Cmd("info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
|
2015-10-25 20:12:22 -04:00
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s\n", discoveryAdvertise))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
d := NewDaemon(c)
|
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
|
|
|
|
// --cluster-advertise with an invalid string is an error
|
|
|
|
err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid")
|
|
|
|
c.Assert(err, checker.Not(checker.IsNil))
|
|
|
|
|
|
|
|
// --cluster-advertise without --cluster-store is also an error
|
|
|
|
err = d.Start("--cluster-advertise=1.1.1.1:2375")
|
|
|
|
c.Assert(err, checker.Not(checker.IsNil))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
d := NewDaemon(c)
|
|
|
|
discoveryBackend := "consul://consuladdr:consulport/some/path"
|
|
|
|
discoveryAdvertise := "eth0"
|
|
|
|
|
|
|
|
err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer d.Stop()
|
|
|
|
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
|
|
|
|
dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
out, _ := dockerCmd(c, "info")
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "pause", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
dockerCmd(c, "stop", cleanedContainerID)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "info")
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
|
|
|
|
}
|
2016-02-01 18:09:25 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
|
|
|
|
|
|
|
d := NewDaemon(c)
|
|
|
|
err := d.Start("--debug")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer d.Stop()
|
|
|
|
|
|
|
|
out, err := d.Cmd("--debug", "info")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, "Debug mode (client): true\n")
|
|
|
|
c.Assert(out, checker.Contains, "Debug mode (server): true\n")
|
|
|
|
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")
|
|
|
|
}
|