github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/integration-cli/docker_cli_info_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"strings"
     7  
     8  	"github.com/docker/docker/pkg/integration/checker"
     9  	"github.com/docker/docker/utils"
    10  	"github.com/go-check/check"
    11  )
    12  
    13  // ensure docker info succeeds
    14  func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
    15  	out, _ := dockerCmd(c, "info")
    16  
    17  	// always shown fields
    18  	stringsToCheck := []string{
    19  		"ID:",
    20  		"Containers:",
    21  		" Running:",
    22  		" Paused:",
    23  		" Stopped:",
    24  		"Images:",
    25  		"OSType:",
    26  		"Architecture:",
    27  		"Logging Driver:",
    28  		"Operating System:",
    29  		"CPUs:",
    30  		"Total Memory:",
    31  		"Kernel Version:",
    32  		"Storage Driver:",
    33  		"Volume:",
    34  		"Network:",
    35  		"Security Options:",
    36  	}
    37  
    38  	if DaemonIsLinux.Condition() {
    39  		stringsToCheck = append(stringsToCheck, "Runtimes:", "Default Runtime: runc")
    40  	}
    41  
    42  	if utils.ExperimentalBuild() {
    43  		stringsToCheck = append(stringsToCheck, "Experimental: true")
    44  	}
    45  
    46  	for _, linePrefix := range stringsToCheck {
    47  		c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
    48  	}
    49  }
    50  
    51  // TestInfoDiscoveryBackend verifies that a daemon run with `--cluster-advertise` and
    52  // `--cluster-store` properly show the backend's endpoint in info output.
    53  func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
    54  	testRequires(c, SameHostDaemon, DaemonIsLinux)
    55  
    56  	d := NewDaemon(c)
    57  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    58  	discoveryAdvertise := "1.1.1.1:2375"
    59  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise))
    60  	c.Assert(err, checker.IsNil)
    61  	defer d.Stop()
    62  
    63  	out, err := d.Cmd("info")
    64  	c.Assert(err, checker.IsNil)
    65  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
    66  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise))
    67  }
    68  
    69  // TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
    70  // an invalid `--cluster-advertise` configuration
    71  func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
    72  	testRequires(c, SameHostDaemon, DaemonIsLinux)
    73  
    74  	d := NewDaemon(c)
    75  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    76  
    77  	// --cluster-advertise with an invalid string is an error
    78  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid")
    79  	c.Assert(err, checker.Not(checker.IsNil))
    80  
    81  	// --cluster-advertise without --cluster-store is also an error
    82  	err = d.Start("--cluster-advertise=1.1.1.1:2375")
    83  	c.Assert(err, checker.Not(checker.IsNil))
    84  }
    85  
    86  // TestInfoDiscoveryAdvertiseInterfaceName verifies that a daemon run with `--cluster-advertise`
    87  // configured with interface name properly show the advertise ip-address in info output.
    88  func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
    89  	testRequires(c, SameHostDaemon, Network, DaemonIsLinux)
    90  
    91  	d := NewDaemon(c)
    92  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    93  	discoveryAdvertise := "eth0"
    94  
    95  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise))
    96  	c.Assert(err, checker.IsNil)
    97  	defer d.Stop()
    98  
    99  	iface, err := net.InterfaceByName(discoveryAdvertise)
   100  	c.Assert(err, checker.IsNil)
   101  	addrs, err := iface.Addrs()
   102  	c.Assert(err, checker.IsNil)
   103  	c.Assert(len(addrs), checker.GreaterThan, 0)
   104  	ip, _, err := net.ParseCIDR(addrs[0].String())
   105  	c.Assert(err, checker.IsNil)
   106  
   107  	out, err := d.Cmd("info")
   108  	c.Assert(err, checker.IsNil)
   109  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
   110  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String()))
   111  }
   112  
   113  func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
   114  	testRequires(c, DaemonIsLinux)
   115  
   116  	dockerCmd(c, "run", "-d", "busybox", "top")
   117  	out, _ := dockerCmd(c, "info")
   118  	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
   119  	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1))
   120  	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
   121  	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
   122  }
   123  
   124  func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
   125  	testRequires(c, DaemonIsLinux)
   126  
   127  	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
   128  	cleanedContainerID := strings.TrimSpace(out)
   129  
   130  	dockerCmd(c, "pause", cleanedContainerID)
   131  
   132  	out, _ = dockerCmd(c, "info")
   133  	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
   134  	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
   135  	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1))
   136  	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
   137  }
   138  
   139  func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
   140  	testRequires(c, DaemonIsLinux)
   141  
   142  	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
   143  	cleanedContainerID := strings.TrimSpace(out)
   144  
   145  	dockerCmd(c, "stop", cleanedContainerID)
   146  
   147  	out, _ = dockerCmd(c, "info")
   148  	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
   149  	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
   150  	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
   151  	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
   152  }
   153  
   154  func (s *DockerSuite) TestInfoDebug(c *check.C) {
   155  	testRequires(c, SameHostDaemon, DaemonIsLinux)
   156  
   157  	d := NewDaemon(c)
   158  	err := d.Start("--debug")
   159  	c.Assert(err, checker.IsNil)
   160  	defer d.Stop()
   161  
   162  	out, err := d.Cmd("--debug", "info")
   163  	c.Assert(err, checker.IsNil)
   164  	c.Assert(out, checker.Contains, "Debug Mode (client): true\n")
   165  	c.Assert(out, checker.Contains, "Debug Mode (server): true\n")
   166  	c.Assert(out, checker.Contains, "File Descriptors")
   167  	c.Assert(out, checker.Contains, "Goroutines")
   168  	c.Assert(out, checker.Contains, "System Time")
   169  	c.Assert(out, checker.Contains, "EventsListeners")
   170  	c.Assert(out, checker.Contains, "Docker Root Dir")
   171  }
   172  
   173  func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
   174  	testRequires(c, SameHostDaemon, DaemonIsLinux)
   175  
   176  	registryCIDR := "192.168.1.0/24"
   177  	registryHost := "insecurehost.com:5000"
   178  
   179  	d := NewDaemon(c)
   180  	err := d.Start("--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
   181  	c.Assert(err, checker.IsNil)
   182  	defer d.Stop()
   183  
   184  	out, err := d.Cmd("info")
   185  	c.Assert(err, checker.IsNil)
   186  	c.Assert(out, checker.Contains, "Insecure Registries:\n")
   187  	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
   188  	c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
   189  }