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-27 20:12:33 +00:00
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure docker info succeeds
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) {
|
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 {
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, linePrefix), "couldn't find string %v in output", linePrefix)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 23:12:00 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *testing.T) {
|
2015-10-27 20:12:33 +00:00
|
|
|
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")
|
2019-09-09 21:08:22 +00: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 20:12:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *testing.T) {
|
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")
|
2019-09-09 21:08:22 +00: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 20:12:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *testing.T) {
|
2015-10-27 20:12:33 +00:00
|
|
|
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")
|
2019-09-09 21:08:22 +00: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 20:12:33 +00:00
|
|
|
}
|
2016-02-01 23:09:25 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func existingContainerStates(c *testing.T) map[string]int {
|
2017-09-08 15:16:15 +00:00
|
|
|
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
|
|
|
|
}
|