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-27 16:12:33 -04:00
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure docker info succeeds
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) {
|
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
|
|
|
}
|
|
|
|
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType == "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
|
|
|
}
|
|
|
|
|
2018-01-15 09:30:05 -05:00
|
|
|
if testEnv.DaemonInfo.ExperimentalBuild {
|
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 {
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, linePrefix), "couldn't find string %v in output", linePrefix)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 19:12:00 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *testing.T) {
|
2015-10-27 16:12:33 -04:00
|
|
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1)))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
|
2015-10-27 16:12:33 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *testing.T) {
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1)))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"])))
|
2015-10-27 16:12:33 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *testing.T) {
|
2015-10-27 16:12:33 -04:00
|
|
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1)))
|
2015-10-27 16:12:33 -04:00
|
|
|
}
|
2016-02-01 18:09:25 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func existingContainerStates(c *testing.T) map[string]int {
|
2017-09-08 11:16:15 -04:00
|
|
|
out, _ := dockerCmd(c, "info", "--format", "{{json .}}")
|
|
|
|
var m map[string]interface{}
|
|
|
|
err := json.Unmarshal([]byte(out), &m)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-09-08 11:16:15 -04: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
|
|
|
|
}
|