2018-03-01 17:51:11 -05:00
|
|
|
package system // import "github.com/docker/docker/integration/system"
|
2018-02-07 13:23:31 -05:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2018-02-07 13:23:31 -05:00
|
|
|
"fmt"
|
2019-10-18 11:57:01 -04:00
|
|
|
"sort"
|
2018-02-07 13:23:31 -05:00
|
|
|
"testing"
|
|
|
|
|
2019-10-18 11:57:01 -04:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/daemon"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-02-07 13:23:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInfoAPI(t *testing.T) {
|
2019-01-02 08:16:25 -05:00
|
|
|
defer setupTest(t)()
|
|
|
|
client := testEnv.APIClient()
|
2018-02-07 13:23:31 -05:00
|
|
|
|
|
|
|
info, err := client.Info(context.Background())
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-07 13:23:31 -05:00
|
|
|
|
|
|
|
// always shown fields
|
|
|
|
stringsToCheck := []string{
|
|
|
|
"ID",
|
|
|
|
"Containers",
|
|
|
|
"ContainersRunning",
|
|
|
|
"ContainersPaused",
|
|
|
|
"ContainersStopped",
|
|
|
|
"Images",
|
|
|
|
"LoggingDriver",
|
|
|
|
"OperatingSystem",
|
|
|
|
"NCPU",
|
|
|
|
"OSType",
|
|
|
|
"Architecture",
|
|
|
|
"MemTotal",
|
|
|
|
"KernelVersion",
|
|
|
|
"Driver",
|
|
|
|
"ServerVersion",
|
2019-03-13 19:18:46 -04:00
|
|
|
"SecurityOptions"}
|
2018-02-07 13:23:31 -05:00
|
|
|
|
|
|
|
out := fmt.Sprintf("%+v", info)
|
|
|
|
for _, linePrefix := range stringsToCheck {
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Contains(out, linePrefix))
|
2018-02-07 13:23:31 -05:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 08:06:06 -04:00
|
|
|
|
|
|
|
func TestInfoAPIWarnings(t *testing.T) {
|
2018-12-29 14:46:33 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
|
2018-08-21 08:06:06 -04:00
|
|
|
d := daemon.New(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
2018-08-21 08:06:06 -04:00
|
|
|
|
2019-10-18 11:57:01 -04:00
|
|
|
d.Start(t, "-H=0.0.0.0:23756", "-H="+d.Sock())
|
2018-08-21 08:06:06 -04:00
|
|
|
defer d.Stop(t)
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
info, err := c.Info(context.Background())
|
2018-08-21 08:06:06 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
stringsToCheck := []string{
|
|
|
|
"Access to the remote API is equivalent to root access",
|
|
|
|
"http://0.0.0.0:23756",
|
|
|
|
}
|
|
|
|
|
|
|
|
out := fmt.Sprintf("%+v", info)
|
|
|
|
for _, linePrefix := range stringsToCheck {
|
|
|
|
assert.Check(t, is.Contains(out, linePrefix))
|
|
|
|
}
|
|
|
|
}
|
2019-10-18 11:57:01 -04:00
|
|
|
|
|
|
|
func TestInfoDebug(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
2019-10-30 12:42:52 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
|
2019-10-18 11:57:01 -04:00
|
|
|
|
|
|
|
d := daemon.New(t)
|
|
|
|
d.Start(t, "--debug")
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
|
|
|
info := d.Info(t)
|
|
|
|
assert.Equal(t, info.Debug, true)
|
|
|
|
|
|
|
|
// Note that the information below is not tied to debug-mode being enabled.
|
|
|
|
assert.Check(t, info.NFd != 0)
|
|
|
|
|
|
|
|
// TODO need a stable way to generate event listeners
|
|
|
|
// assert.Check(t, info.NEventsListener != 0)
|
|
|
|
assert.Check(t, info.NGoroutines != 0)
|
|
|
|
assert.Check(t, info.SystemTime != "")
|
|
|
|
assert.Equal(t, info.DockerRootDir, d.Root)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfoInsecureRegistries(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
2019-11-11 13:54:21 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
|
2019-10-18 11:57:01 -04:00
|
|
|
|
|
|
|
const (
|
|
|
|
registryCIDR = "192.168.1.0/24"
|
|
|
|
registryHost = "insecurehost.com:5000"
|
|
|
|
)
|
|
|
|
|
|
|
|
d := daemon.New(t)
|
|
|
|
d.Start(t, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
|
|
|
info := d.Info(t)
|
|
|
|
assert.Assert(t, is.Len(info.RegistryConfig.InsecureRegistryCIDRs, 2))
|
|
|
|
cidrs := []string{
|
|
|
|
info.RegistryConfig.InsecureRegistryCIDRs[0].String(),
|
|
|
|
info.RegistryConfig.InsecureRegistryCIDRs[1].String(),
|
|
|
|
}
|
|
|
|
assert.Assert(t, is.Contains(cidrs, registryCIDR))
|
|
|
|
assert.Assert(t, is.Contains(cidrs, "127.0.0.0/8"))
|
|
|
|
assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs["docker.io"], registry.IndexInfo{Name: "docker.io", Mirrors: []string{}, Secure: true, Official: true})
|
|
|
|
assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs[registryHost], registry.IndexInfo{Name: registryHost, Mirrors: []string{}, Secure: false, Official: false})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfoRegistryMirrors(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
2019-11-11 13:54:21 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
|
2019-10-18 11:57:01 -04:00
|
|
|
|
|
|
|
const (
|
|
|
|
registryMirror1 = "https://192.168.1.2"
|
2021-04-02 08:06:27 -04:00
|
|
|
registryMirror2 = "http://registry-mirror.example.com:5000"
|
2019-10-18 11:57:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
d := daemon.New(t)
|
|
|
|
d.Start(t, "--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2)
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
|
|
|
info := d.Info(t)
|
|
|
|
sort.Strings(info.RegistryConfig.Mirrors)
|
|
|
|
assert.DeepEqual(t, info.RegistryConfig.Mirrors, []string{registryMirror2 + "/", registryMirror1 + "/"})
|
|
|
|
}
|