2014-11-20 00:19:16 -05:00
|
|
|
// +build daemon
|
|
|
|
|
2014-07-23 14:39:14 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-10-08 13:13:32 -04:00
|
|
|
"encoding/json"
|
2014-11-14 23:38:02 -05:00
|
|
|
"fmt"
|
2014-10-01 09:07:24 -04:00
|
|
|
"io/ioutil"
|
2015-04-27 16:16:33 -04:00
|
|
|
"net"
|
2014-10-08 13:13:32 -04:00
|
|
|
"os"
|
2014-10-05 00:21:59 -04:00
|
|
|
"os/exec"
|
2015-01-22 13:51:04 -05:00
|
|
|
"path/filepath"
|
2015-04-28 13:26:59 -04:00
|
|
|
"regexp"
|
2015-04-28 11:55:04 -04:00
|
|
|
"strconv"
|
2014-07-23 14:39:14 -04:00
|
|
|
"strings"
|
2015-02-04 16:44:52 -05:00
|
|
|
"time"
|
2015-01-21 11:14:30 -05:00
|
|
|
|
2015-05-06 18:39:29 -04:00
|
|
|
"github.com/docker/libnetwork/iptables"
|
2015-01-21 11:14:30 -05:00
|
|
|
"github.com/docker/libtrust"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-07-23 14:39:14 -04:00
|
|
|
)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithRunningContainersPorts(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run top1: err=%v\n%s", err, out)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
// --restart=no by default
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run top2: err=%v\n%s", err, out)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
testRun := func(m map[string]bool, prefix string) {
|
|
|
|
var format string
|
2015-04-18 12:46:47 -04:00
|
|
|
for cont, shouldRun := range m {
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("ps")
|
2014-07-23 14:39:14 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run ps: err=%v\n%q", err, out)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
if shouldRun {
|
|
|
|
format = "%scontainer %q is not running"
|
|
|
|
} else {
|
|
|
|
format = "%scontainer %q is running"
|
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
if shouldRun != strings.Contains(out, cont) {
|
|
|
|
c.Fatalf(format, prefix, cont)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testRun(map[string]bool{"top1": true, "top2": true}, "")
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
2014-07-23 14:39:14 -04:00
|
|
|
}
|
|
|
|
testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ")
|
|
|
|
}
|
2014-10-08 13:13:32 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithVolumesRefs(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "-d", "--name", "volrestarttest1", "-v", "/foo", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if _, err := s.d.Cmd("run", "-d", "--volumes-from", "volrestarttest1", "--name", "volrestarttest2", "busybox", "top"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("rm", "-fv", "volrestarttest2"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
v, err := s.d.Cmd("inspect", "--format", "{{ json .Volumes }}", "volrestarttest1")
|
2014-10-08 13:13:32 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
|
|
|
volumes := make(map[string]string)
|
|
|
|
json.Unmarshal([]byte(v), &volumes)
|
|
|
|
if _, err := os.Stat(volumes["/foo"]); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected volume to exist: %s - %s", volumes["/foo"], err)
|
2014-10-08 13:13:32 -04:00
|
|
|
}
|
|
|
|
}
|
2014-10-16 14:39:22 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonStartIptablesFalse(c *check.C) {
|
|
|
|
if err := s.d.Start("--iptables=false"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("we should have been able to start the daemon with passing iptables=false: %v", err)
|
2014-10-16 14:39:22 -04:00
|
|
|
}
|
|
|
|
}
|
2014-10-05 00:21:59 -04:00
|
|
|
|
|
|
|
// Issue #8444: If docker0 bridge is modified (intentionally or unintentionally) and
|
|
|
|
// no longer has an IP associated, we should gracefully handle that case and associate
|
|
|
|
// an IP with it rather than fail daemon start
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C) {
|
2014-10-05 00:21:59 -04:00
|
|
|
// rather than depending on brctl commands to verify docker0 is created and up
|
|
|
|
// let's start the daemon and stop it, and then make a modification to run the
|
|
|
|
// actual test
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
2014-10-05 00:21:59 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Stop(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not stop daemon: %v", err)
|
2014-10-05 00:21:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// now we will remove the ip from docker0 and then try starting the daemon
|
|
|
|
ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0")
|
|
|
|
stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
|
2014-10-05 00:21:59 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2014-10-05 00:21:59 -04:00
|
|
|
warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix"
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon when docker0 has no IP address: %v\n%s", err, warning)
|
2014-10-05 00:21:59 -04:00
|
|
|
}
|
|
|
|
}
|
2014-09-30 15:18:26 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonIptablesClean(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run top: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get output from iptables with container running
|
|
|
|
ipTablesSearchString := "tcp dpt:80"
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-nvL")
|
|
|
|
out, _, err := runCommandWithOutput(ipTablesCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, ipTablesSearchString) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Stop(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not stop daemon: %v", err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get output from iptables after restart
|
|
|
|
ipTablesCmd = exec.Command("iptables", "-nvL")
|
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Contains(out, ipTablesSearchString) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "-d", "--name", "top", "--restart=always", "-p", "80", "busybox:latest", "top"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run top: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get output from iptables with container running
|
|
|
|
ipTablesSearchString := "tcp dpt:80"
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-nvL")
|
|
|
|
out, _, err := runCommandWithOutput(ipTablesCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, ipTablesSearchString) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the container is not running
|
2015-04-25 22:47:42 -04:00
|
|
|
runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", "top")
|
2014-09-30 15:18:26 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not inspect on container: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
if strings.TrimSpace(runningOut) != "true" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut))
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get output from iptables after restart
|
|
|
|
ipTablesCmd = exec.Command("iptables", "-nvL")
|
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, ipTablesSearchString) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out)
|
2014-09-30 15:18:26 -04:00
|
|
|
}
|
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
|
|
|
|
c.Assert(s.d.Start("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
|
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) {
|
|
|
|
if err := s.d.Start("--log-level=debug"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-03-11 13:43:56 -04:00
|
|
|
if !strings.Contains(string(content), `level=debug`) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf(`Missing level="debug" in log file:\n%s`, string(content))
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLogLevelFatal(c *check.C) {
|
|
|
|
// we creating new daemons to create new logFile
|
|
|
|
if err := s.d.Start("--log-level=fatal"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-03-11 13:43:56 -04:00
|
|
|
if strings.Contains(string(content), `level=debug`) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf(`Should not have level="debug" in log file:\n%s`, string(content))
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonFlagD(c *check.C) {
|
|
|
|
if err := s.d.Start("-D"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-05-14 13:07:21 -04:00
|
|
|
if !strings.Contains(string(content), `level=debug`) {
|
|
|
|
c.Fatalf(`Should have level="debug" in log file using -D:\n%s`, string(content))
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonFlagDebug(c *check.C) {
|
|
|
|
if err := s.d.Start("--debug"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-05-14 13:07:21 -04:00
|
|
|
if !strings.Contains(string(content), `level=debug`) {
|
|
|
|
c.Fatalf(`Should have level="debug" in log file using --debug:\n%s`, string(content))
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
}
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonFlagDebugLogLevelFatal(c *check.C) {
|
|
|
|
if err := s.d.Start("--debug", "--log-level=fatal"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-05-14 13:07:21 -04:00
|
|
|
if !strings.Contains(string(content), `level=debug`) {
|
|
|
|
c.Fatalf(`Should have level="debug" in log file when using both --debug and --log-level=fatal:\n%s`, string(content))
|
2014-10-01 09:07:24 -04:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 23:38:02 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *check.C) {
|
2014-11-14 23:38:02 -05:00
|
|
|
listeningPorts := [][]string{
|
|
|
|
{"0.0.0.0", "0.0.0.0", "5678"},
|
|
|
|
{"127.0.0.1", "127.0.0.1", "1234"},
|
|
|
|
{"localhost", "127.0.0.1", "1235"},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdArgs := []string{}
|
|
|
|
for _, hostDirective := range listeningPorts {
|
|
|
|
cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2]))
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.StartWithBusybox(cmdArgs...); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
2014-11-14 23:38:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, hostDirective := range listeningPorts {
|
2015-04-25 22:47:42 -04:00
|
|
|
output, err := s.d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true")
|
2014-11-14 23:38:02 -05:00
|
|
|
if err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Container should not start, expected port already allocated error: %q", output)
|
2014-11-14 23:38:02 -05:00
|
|
|
} else if !strings.Contains(output, "port is already allocated") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected port is already allocated error: %q", output)
|
2014-11-14 23:38:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 14:48:25 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonKeyGeneration(c *check.C) {
|
2015-01-22 13:29:15 -05:00
|
|
|
// TODO: skip or update for Windows daemon
|
2015-01-21 11:14:30 -05:00
|
|
|
os.Remove("/etc/docker/key.json")
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
2015-01-21 11:14:30 -05:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Stop()
|
2015-01-21 11:14:30 -05:00
|
|
|
|
|
|
|
k, err := libtrust.LoadKeyFile("/etc/docker/key.json")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error opening key file")
|
2015-01-21 11:14:30 -05:00
|
|
|
}
|
|
|
|
kid := k.KeyID()
|
|
|
|
// Test Key ID is a valid fingerprint (e.g. QQXN:JY5W:TBXI:MK3X:GX6P:PD5D:F56N:NHCS:LVRZ:JA46:R24J:XEFF)
|
|
|
|
if len(kid) != 59 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Bad key ID: %s", kid)
|
2015-01-21 11:14:30 -05:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 13:51:04 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonKeyMigration(c *check.C) {
|
2015-01-22 13:51:04 -05:00
|
|
|
// TODO: skip or update for Windows daemon
|
|
|
|
os.Remove("/etc/docker/key.json")
|
|
|
|
k1, err := libtrust.GenerateECP256PrivateKey()
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error generating private key: %s", err)
|
2015-01-22 13:51:04 -05:00
|
|
|
}
|
2015-01-29 16:46:12 -05:00
|
|
|
if err := os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".docker"), 0755); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating .docker directory: %s", err)
|
2015-01-29 16:46:12 -05:00
|
|
|
}
|
2015-01-22 13:51:04 -05:00
|
|
|
if err := libtrust.SaveKey(filepath.Join(os.Getenv("HOME"), ".docker", "key.json"), k1); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error saving private key: %s", err)
|
2015-01-22 13:51:04 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
2015-01-22 13:51:04 -05:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Stop()
|
2015-01-22 13:51:04 -05:00
|
|
|
|
|
|
|
k2, err := libtrust.LoadKeyFile("/etc/docker/key.json")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error opening key file")
|
2015-01-22 13:51:04 -05:00
|
|
|
}
|
|
|
|
if k1.KeyID() != k2.KeyID() {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Key not migrated")
|
2015-01-22 13:51:04 -05:00
|
|
|
}
|
|
|
|
}
|
2015-01-21 21:40:19 -05:00
|
|
|
|
2015-03-11 10:33:06 -04:00
|
|
|
// GH#11320 - verify that the daemon exits on failure properly
|
|
|
|
// Note that this explicitly tests the conflict of {-b,--bridge} and {--bip} options as the means
|
|
|
|
// to get a daemon init failure; no other tests for -b/--bip conflict are therefore required
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
|
2015-03-11 10:33:06 -04:00
|
|
|
//attempt to start daemon with incorrect flags (we know -b and --bip conflict)
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil {
|
2015-03-11 10:33:06 -04:00
|
|
|
//verify we got the right error
|
|
|
|
if !strings.Contains(err.Error(), "Daemon exited and never started") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected daemon not to start, got %v", err)
|
2015-03-11 10:33:06 -04:00
|
|
|
}
|
|
|
|
// look in the log and make sure we got the message that daemon is shutting down
|
2015-04-25 22:47:42 -04:00
|
|
|
runCmd := exec.Command("grep", "Error starting daemon", s.d.LogfileName())
|
2015-03-11 10:33:06 -04:00
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected 'Error starting daemon' message; but doesn't exist in log: %q, err: %v", out, err)
|
2015-03-11 10:33:06 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//if we didn't get an error and the daemon is running, this is a failure
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("Conflicting options should cause the daemon to error out with a failure")
|
2015-03-11 10:33:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 16:16:33 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
|
|
|
d := s.d
|
|
|
|
err := d.Start("--bridge", "nosuchbridge")
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.NotNil, check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail"))
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-27 16:16:33 -04:00
|
|
|
|
|
|
|
bridgeName := "external-bridge"
|
|
|
|
bridgeIp := "192.169.1.1/24"
|
|
|
|
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIp)
|
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, bridgeName)
|
2015-04-27 16:16:33 -04:00
|
|
|
|
|
|
|
err = d.StartWithBusybox("--bridge", bridgeName)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
ipTablesSearchString := bridgeIPNet.String()
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
2015-04-29 14:41:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
2015-04-27 16:16:33 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
|
|
|
|
check.Commentf("iptables output should have contained %q, but was %q",
|
|
|
|
ipTablesSearchString, out))
|
|
|
|
|
|
|
|
_, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
containerIp := d.findContainerIP("ExtContainer")
|
2015-04-27 16:16:33 -04:00
|
|
|
ip := net.ParseIP(containerIp)
|
|
|
|
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
|
|
|
|
check.Commentf("Container IP-Address must be in the same subnet range : %s",
|
|
|
|
containerIp))
|
|
|
|
}
|
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) {
|
2015-04-28 19:17:00 -04:00
|
|
|
args := []string{"link", "add", "name", ifName, "type", ifType}
|
|
|
|
ipLinkCmd := exec.Command("ip", args...)
|
|
|
|
out, _, err := runCommandWithOutput(ipLinkCmd)
|
2015-04-29 14:41:13 -04:00
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
ifCfgCmd := exec.Command("ifconfig", ifName, ipNet, "up")
|
|
|
|
out, _, err = runCommandWithOutput(ifCfgCmd)
|
2015-04-29 14:41:13 -04:00
|
|
|
return out, err
|
2015-04-28 19:17:00 -04:00
|
|
|
}
|
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
func deleteInterface(c *check.C, ifName string) {
|
|
|
|
ifCmd := exec.Command("ip", "link", "delete", ifName)
|
2015-04-28 19:17:00 -04:00
|
|
|
out, _, err := runCommandWithOutput(ifCmd)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
2015-04-27 23:36:40 -04:00
|
|
|
|
|
|
|
flushCmd := exec.Command("iptables", "-t", "nat", "--flush")
|
2015-04-28 19:17:00 -04:00
|
|
|
out, _, err = runCommandWithOutput(flushCmd)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
flushCmd = exec.Command("iptables", "--flush")
|
|
|
|
out, _, err = runCommandWithOutput(flushCmd)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
2015-04-27 23:36:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
|
|
|
|
// TestDaemonBridgeIP Steps
|
|
|
|
// 1. Delete the existing docker0 Bridge
|
|
|
|
// 2. Set --bip daemon configuration and start the new Docker Daemon
|
|
|
|
// 3. Check if the bip config has taken effect using ifconfig and iptables commands
|
|
|
|
// 4. Launch a Container and make sure the IP-Address is in the expected subnet
|
|
|
|
// 5. Delete the docker0 Bridge
|
2015-04-29 14:41:13 -04:00
|
|
|
// 6. Restart the Docker Daemon (via defered action)
|
2015-04-27 23:36:40 -04:00
|
|
|
// This Restart takes care of bringing docker0 interface back to auto-assigned IP
|
|
|
|
|
|
|
|
defaultNetworkBridge := "docker0"
|
2015-04-28 13:26:59 -04:00
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
2015-04-27 23:36:40 -04:00
|
|
|
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeIp := "192.169.1.1/24"
|
|
|
|
ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIp)
|
|
|
|
|
|
|
|
err := d.StartWithBusybox("--bip", bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-27 23:36:40 -04:00
|
|
|
|
|
|
|
ifconfigSearchString := ip.String()
|
|
|
|
ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge)
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true,
|
|
|
|
check.Commentf("ifconfig output should have contained %q, but was %q",
|
|
|
|
ifconfigSearchString, out))
|
|
|
|
|
|
|
|
ipTablesSearchString := bridgeIPNet.String()
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
|
|
|
|
check.Commentf("iptables output should have contained %q, but was %q",
|
|
|
|
ipTablesSearchString, out))
|
|
|
|
|
|
|
|
out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
containerIp := d.findContainerIP("test")
|
2015-04-27 23:36:40 -04:00
|
|
|
ip = net.ParseIP(containerIp)
|
|
|
|
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
|
|
|
|
check.Commentf("Container IP-Address must be in the same subnet range : %s",
|
|
|
|
containerIp))
|
2015-04-28 13:26:59 -04:00
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
2015-04-27 23:36:40 -04:00
|
|
|
}
|
|
|
|
|
2015-04-16 03:09:36 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) {
|
|
|
|
if err := s.d.Start(); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
|
|
|
defer s.d.Restart()
|
|
|
|
if err := s.d.Stop(); err != nil {
|
|
|
|
c.Fatalf("Could not stop daemon: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we will change the docker0's IP and then try starting the daemon
|
|
|
|
bridgeIP := "192.169.100.1/24"
|
|
|
|
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
|
|
|
|
|
|
|
|
ipCmd := exec.Command("ifconfig", "docker0", bridgeIP)
|
|
|
|
stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.d.Start("--bip", bridgeIP); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if the iptables contains new bridgeIP MASQUERADE rule
|
|
|
|
ipTablesSearchString := bridgeIPNet.String()
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
|
|
|
out, _, err := runCommandWithOutput(ipTablesCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
if !strings.Contains(out, ipTablesSearchString) {
|
|
|
|
c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 11:55:04 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeName := "external-bridge"
|
2015-04-28 19:17:00 -04:00
|
|
|
bridgeIp := "192.169.1.1/24"
|
2015-04-28 11:55:04 -04:00
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, bridgeName)
|
2015-04-28 11:55:04 -04:00
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"}
|
2015-04-29 14:41:13 -04:00
|
|
|
err = d.StartWithBusybox(args...)
|
2015-04-28 11:55:04 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-28 11:55:04 -04:00
|
|
|
|
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
cName := "Container" + strconv.Itoa(i)
|
|
|
|
out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top")
|
|
|
|
if err != nil {
|
|
|
|
c.Assert(strings.Contains(out, "no available ip addresses"), check.Equals, true,
|
|
|
|
check.Commentf("Could not run a Container : %s %s", err.Error(), out))
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 13:26:59 -04:00
|
|
|
}
|
|
|
|
|
2015-06-05 01:57:59 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) {
|
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
|
|
|
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeIp := "192.169.1.1"
|
|
|
|
bridgeIpNet := fmt.Sprintf("%s/24", bridgeIp)
|
|
|
|
|
|
|
|
err := d.StartWithBusybox("--bip", bridgeIpNet)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer d.Restart()
|
|
|
|
|
|
|
|
expectedMessage := fmt.Sprintf("default via %s dev", bridgeIp)
|
|
|
|
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
|
|
|
|
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
|
|
|
|
check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'",
|
|
|
|
bridgeIp, strings.TrimSpace(out)))
|
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) {
|
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
|
|
|
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeIp := "192.169.1.1"
|
|
|
|
bridgeIpNet := fmt.Sprintf("%s/24", bridgeIp)
|
|
|
|
gatewayIp := "192.169.1.254"
|
|
|
|
|
|
|
|
err := d.StartWithBusybox("--bip", bridgeIpNet, "--default-gateway", gatewayIp)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer d.Restart()
|
|
|
|
|
|
|
|
expectedMessage := fmt.Sprintf("default via %s dev", gatewayIp)
|
|
|
|
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
|
|
|
|
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
|
|
|
|
check.Commentf("Explicit default gateway should be %s, but default route was '%s'",
|
|
|
|
gatewayIp, strings.TrimSpace(out)))
|
|
|
|
deleteInterface(c, defaultNetworkBridge)
|
|
|
|
}
|
|
|
|
|
2015-04-28 13:26:59 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
ipStr := "192.170.1.1/24"
|
|
|
|
ip, _, _ := net.ParseCIDR(ipStr)
|
|
|
|
args := []string{"--ip", ip.String()}
|
|
|
|
err := d.StartWithBusybox(args...)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-28 13:26:59 -04:00
|
|
|
|
|
|
|
out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.NotNil,
|
2015-04-28 13:26:59 -04:00
|
|
|
check.Commentf("Running a container must fail with an invalid --ip option"))
|
|
|
|
c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true)
|
|
|
|
|
|
|
|
ifName := "dummy"
|
2015-04-29 14:41:13 -04:00
|
|
|
out, err = createInterface(c, "dummy", ifName, ipStr)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, ifName)
|
2015-04-28 13:26:59 -04:00
|
|
|
|
|
|
|
_, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String())
|
|
|
|
matched, _ := regexp.MatchString(regex, out)
|
|
|
|
c.Assert(matched, check.Equals, true,
|
|
|
|
check.Commentf("iptables output should have contained %q, but was %q", regex, out))
|
2015-04-28 11:55:04 -04:00
|
|
|
}
|
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeName := "external-bridge"
|
|
|
|
bridgeIp := "192.169.1.1/24"
|
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, bridgeName)
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
args := []string{"--bridge", bridgeName, "--icc=false"}
|
2015-04-29 14:41:13 -04:00
|
|
|
err = d.StartWithBusybox(args...)
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
|
2015-04-29 14:41:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
|
|
|
|
matched, _ := regexp.MatchString(regex, out)
|
|
|
|
c.Assert(matched, check.Equals, true,
|
|
|
|
check.Commentf("iptables output should have contained %q, but was %q", regex, out))
|
|
|
|
|
|
|
|
// Pinging another container must fail with --icc=false
|
|
|
|
pingContainers(c, d, true)
|
|
|
|
|
|
|
|
ipStr := "192.171.1.1/24"
|
|
|
|
ip, _, _ := net.ParseCIDR(ipStr)
|
|
|
|
ifName := "icc-dummy"
|
|
|
|
|
|
|
|
createInterface(c, "dummy", ifName, ipStr)
|
|
|
|
|
|
|
|
// But, Pinging external or a Host interface must succeed
|
|
|
|
pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
|
|
|
|
runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd}
|
|
|
|
_, err = d.Cmd("run", runArgs...)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
|
|
|
|
d := s.d
|
|
|
|
|
|
|
|
bridgeName := "external-bridge"
|
|
|
|
bridgeIp := "192.169.1.1/24"
|
|
|
|
|
2015-04-29 14:41:13 -04:00
|
|
|
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, bridgeName)
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
args := []string{"--bridge", bridgeName, "--icc=false"}
|
2015-04-29 14:41:13 -04:00
|
|
|
err = d.StartWithBusybox(args...)
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-04-29 14:41:13 -04:00
|
|
|
defer d.Restart()
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
|
2015-04-29 14:41:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(ipTablesCmd)
|
2015-04-28 19:17:00 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
|
|
|
|
matched, _ := regexp.MatchString(regex, out)
|
|
|
|
c.Assert(matched, check.Equals, true,
|
|
|
|
check.Commentf("iptables output should have contained %q, but was %q", regex, out))
|
|
|
|
|
2015-05-06 18:39:29 -04:00
|
|
|
out, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567")
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
2015-04-28 19:17:00 -04:00
|
|
|
|
|
|
|
out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567")
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
}
|
|
|
|
|
2015-05-06 18:39:29 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *check.C) {
|
|
|
|
bridgeName := "external-bridge"
|
|
|
|
bridgeIp := "192.169.1.1/24"
|
|
|
|
|
|
|
|
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
defer deleteInterface(c, bridgeName)
|
|
|
|
|
|
|
|
args := []string{"--bridge", bridgeName, "--icc=false"}
|
|
|
|
err = s.d.StartWithBusybox(args...)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer s.d.Restart()
|
|
|
|
|
|
|
|
_, err = s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
_, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
childIP := s.d.findContainerIP("child")
|
|
|
|
parentIP := s.d.findContainerIP("parent")
|
|
|
|
|
|
|
|
sourceRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", childIP, "--sport", "80", "-d", parentIP, "-j", "ACCEPT"}
|
|
|
|
destinationRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", parentIP, "--dport", "80", "-d", childIP, "-j", "ACCEPT"}
|
|
|
|
if !iptables.Exists("filter", "DOCKER", sourceRule...) || !iptables.Exists("filter", "DOCKER", destinationRule...) {
|
|
|
|
c.Fatal("Iptables rules not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
s.d.Cmd("rm", "--link", "parent/http")
|
|
|
|
if iptables.Exists("filter", "DOCKER", sourceRule...) || iptables.Exists("filter", "DOCKER", destinationRule...) {
|
|
|
|
c.Fatal("Iptables rules should be removed when unlink")
|
|
|
|
}
|
|
|
|
|
|
|
|
s.d.Cmd("kill", "child")
|
|
|
|
s.d.Cmd("kill", "parent")
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) {
|
2015-04-18 12:46:47 -04:00
|
|
|
testRequires(c, NativeExecDriver)
|
2015-02-11 14:21:38 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "--ulimit", "nproc=2048", "--name=test", "busybox", "/bin/sh", "-c", "echo $(ulimit -n); echo $(ulimit -p)")
|
2015-02-11 14:21:38 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
outArr := strings.Split(out, "\n")
|
|
|
|
if len(outArr) < 2 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("got unexpected output: %s", out)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
nofile := strings.TrimSpace(outArr[0])
|
|
|
|
nproc := strings.TrimSpace(outArr[1])
|
|
|
|
|
|
|
|
if nofile != "42" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("expected `ulimit -n` to be `42`, got: %s", nofile)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
if nproc != "2048" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now restart daemon with a new default
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart("--default-ulimit", "nofile=43"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err = s.d.Cmd("start", "-a", "test")
|
2015-02-11 14:21:38 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
outArr = strings.Split(out, "\n")
|
|
|
|
if len(outArr) < 2 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("got unexpected output: %s", out)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
nofile = strings.TrimSpace(outArr[0])
|
|
|
|
nproc = strings.TrimSpace(outArr[1])
|
|
|
|
|
|
|
|
if nofile != "43" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("expected `ulimit -n` to be `43`, got: %s", nofile)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
if nproc != "2048" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-11 12:17:23 -04:00
|
|
|
|
|
|
|
// #11315
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartRenameContainer(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-11 12:17:23 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("run", "--name=test", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2015-03-11 12:17:23 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("rename", "test", "test2"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2015-03-11 12:17:23 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-11 12:17:23 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("start", "test2"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2015-03-11 12:17:23 -04:00
|
|
|
}
|
|
|
|
}
|
2015-02-04 16:44:52 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefault(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
|
2015-02-04 16:44:52 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("wait", id); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log")
|
2015-02-04 16:44:52 -05:00
|
|
|
|
|
|
|
if _, err := os.Stat(logPath); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
f, err := os.Open(logPath)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
var res struct {
|
2015-03-25 23:18:42 -04:00
|
|
|
Log string `json:"log"`
|
|
|
|
Stream string `json:"stream"`
|
|
|
|
Time time.Time `json:"time"`
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if err := json.NewDecoder(f).Decode(&res); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if res.Log != "testline\n" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n")
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if res.Stream != "stdout" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout")
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if !time.Now().After(res.Time) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Log time %v in future", res.Time)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefaultOverride(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "--log-driver=none", "busybox", "echo", "testline")
|
2015-02-04 16:44:52 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("wait", id); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log")
|
2015-02-04 16:44:52 -05:00
|
|
|
|
|
|
|
if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLoggingDriverNone(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
|
2015-02-04 16:44:52 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("wait", id); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log")
|
2015-02-04 16:44:52 -05:00
|
|
|
|
|
|
|
if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneOverride(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "--log-driver=json-file", "busybox", "echo", "testline")
|
2015-02-04 16:44:52 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("wait", id); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log")
|
2015-02-04 16:44:52 -05:00
|
|
|
|
|
|
|
if _, err := os.Stat(logPath); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
f, err := os.Open(logPath)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
var res struct {
|
2015-03-25 23:18:42 -04:00
|
|
|
Log string `json:"log"`
|
|
|
|
Stream string `json:"stream"`
|
|
|
|
Time time.Time `json:"time"`
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if err := json.NewDecoder(f).Decode(&res); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if res.Log != "testline\n" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n")
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if res.Stream != "stdout" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout")
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
if !time.Now().After(res.Time) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Log time %v in future", res.Time)
|
2015-02-04 16:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
2015-02-05 19:24:47 -05:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-05 19:24:47 -05:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
|
2015-02-05 19:24:47 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-02-05 19:24:47 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err = s.d.Cmd("logs", id)
|
2015-02-05 19:24:47 -05:00
|
|
|
if err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Logs should fail with \"none\" driver")
|
2015-02-05 19:24:47 -05:00
|
|
|
}
|
2015-05-09 14:33:06 -04:00
|
|
|
if !strings.Contains(out, `"logs" command is supported only for "json-file" logging driver`) {
|
|
|
|
c.Fatalf("There should be error about non-json-file driver, got: %s", out)
|
2015-02-05 19:24:47 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-17 20:27:53 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonDots(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now create 4 containers
|
2015-04-25 22:47:42 -04:00
|
|
|
if _, err := s.d.Cmd("create", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating container: %q", err)
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if _, err := s.d.Cmd("create", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating container: %q", err)
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if _, err := s.d.Cmd("create", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating container: %q", err)
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
if _, err := s.d.Cmd("create", "busybox"); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating container: %q", err)
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Stop()
|
2015-03-17 20:27:53 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Start("--log-level=debug")
|
|
|
|
s.d.Stop()
|
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-03-17 20:27:53 -04:00
|
|
|
if strings.Contains(string(content), "....") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Debug level should not have ....\n%s", string(content))
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Start("--log-level=error")
|
|
|
|
s.d.Stop()
|
|
|
|
content, _ = ioutil.ReadFile(s.d.logFile.Name())
|
2015-03-17 20:27:53 -04:00
|
|
|
if strings.Contains(string(content), "....") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error level should not have ....\n%s", string(content))
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d.Start("--log-level=info")
|
|
|
|
s.d.Stop()
|
|
|
|
content, _ = ioutil.ReadFile(s.d.logFile.Name())
|
2015-03-17 20:27:53 -04:00
|
|
|
if !strings.Contains(string(content), "....") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Info level should have ....\n%s", string(content))
|
2015-03-17 20:27:53 -04:00
|
|
|
}
|
|
|
|
}
|
2015-03-18 17:26:14 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) {
|
2015-03-18 17:26:14 -04:00
|
|
|
dir, err := ioutil.TempDir("", "socket-cleanup-test")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-18 17:26:14 -04:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
sockPath := filepath.Join(dir, "docker.sock")
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start("--host", "unix://"+sockPath); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-18 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := os.Stat(sockPath); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("socket does not exist")
|
2015-03-18 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Stop(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-03-18 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := os.Stat(sockPath); err == nil || !os.IsNotExist(err) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("unix socket is not cleaned up")
|
2015-03-18 17:26:14 -04:00
|
|
|
}
|
|
|
|
}
|
2015-04-05 20:57:19 -04:00
|
|
|
|
2015-04-29 07:56:45 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) {
|
2015-04-05 20:57:19 -04:00
|
|
|
type Config struct {
|
|
|
|
Crv string `json:"crv"`
|
|
|
|
D string `json:"d"`
|
|
|
|
Kid string `json:"kid"`
|
|
|
|
Kty string `json:"kty"`
|
|
|
|
X string `json:"x"`
|
|
|
|
Y string `json:"y"`
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Remove("/etc/docker/key.json")
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Failed to start daemon: %v", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Stop(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not stop daemon: %v", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
config := &Config{}
|
|
|
|
bytes, err := ioutil.ReadFile("/etc/docker/key.json")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error reading key.json file: %s", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// byte[] to Data-Struct
|
|
|
|
if err := json.Unmarshal(bytes, &config); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error Unmarshal: %s", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//replace config.Kid with the fake value
|
|
|
|
config.Kid = "VSAJ:FUYR:X3H2:B2VZ:KZ6U:CJD5:K7BX:ZXHY:UZXT:P4FT:MJWG:HRJ4"
|
|
|
|
|
|
|
|
// NEW Data-Struct to byte[]
|
|
|
|
newBytes, err := json.Marshal(&config)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error Marshal: %s", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// write back
|
|
|
|
if err := ioutil.WriteFile("/etc/docker/key.json", newBytes, 0400); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error ioutil.WriteFile: %s", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
2015-04-13 19:31:20 -04:00
|
|
|
defer os.Remove("/etc/docker/key.json")
|
2015-04-05 20:57:19 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start(); err == nil {
|
2015-04-27 16:33:30 -04:00
|
|
|
c.Fatalf("It should not be successful to start daemon with wrong key: %v", err)
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
content, _ := ioutil.ReadFile(s.d.logFile.Name())
|
2015-04-05 20:57:19 -04:00
|
|
|
|
|
|
|
if !strings.Contains(string(content), "Public Key ID does not match") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("Missing KeyID message from daemon logs")
|
2015-04-05 20:57:19 -04:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 17:11:11 -04:00
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
2015-04-09 17:11:11 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.Cmd("run", "-id", "busybox", "/bin/cat")
|
2015-04-09 17:11:11 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not run /bin/cat: err=%v\n%s", err, out)
|
2015-04-09 17:11:11 -04:00
|
|
|
}
|
|
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("kill", containerID); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not kill %s: err=%v\n%s", containerID, err, out)
|
2015-04-09 17:11:11 -04:00
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
2015-04-09 17:11:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
errchan := make(chan error)
|
|
|
|
go func() {
|
2015-04-25 22:47:42 -04:00
|
|
|
if out, err := s.d.Cmd("wait", containerID); err != nil {
|
2015-04-09 17:11:11 -04:00
|
|
|
errchan <- fmt.Errorf("%v:\n%s", err, out)
|
|
|
|
}
|
|
|
|
close(errchan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-time.After(5 * time.Second):
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("Waiting on a stopped (killed) container timed out")
|
2015-04-09 17:11:11 -04:00
|
|
|
case err := <-errchan:
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-09 17:11:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 19:21:46 -04:00
|
|
|
|
|
|
|
// TestHttpsInfo connects via two-way authenticated HTTPS to the info endpoint
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
|
2015-04-20 19:21:46 -04:00
|
|
|
const (
|
|
|
|
testDaemonHttpsAddr = "localhost:4271"
|
|
|
|
)
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
|
2015-04-20 19:21:46 -04:00
|
|
|
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHttpsAddr); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//force tcp protocol
|
|
|
|
host := fmt.Sprintf("tcp://%s", testDaemonHttpsAddr)
|
|
|
|
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
2015-04-20 19:21:46 -04:00
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Error Occurred: %s and output: %s", err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestHttpsInfoRogueCert connects via two-way authenticated HTTPS to the info endpoint
|
|
|
|
// by using a rogue client certificate and checks that it fails with the expected error.
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
|
2015-04-20 19:21:46 -04:00
|
|
|
const (
|
|
|
|
errBadCertificate = "remote error: bad certificate"
|
|
|
|
testDaemonHttpsAddr = "localhost:4271"
|
|
|
|
)
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
|
2015-04-20 19:21:46 -04:00
|
|
|
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHttpsAddr); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//force tcp protocol
|
|
|
|
host := fmt.Sprintf("tcp://%s", testDaemonHttpsAddr)
|
|
|
|
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
2015-04-20 19:21:46 -04:00
|
|
|
if err == nil || !strings.Contains(out, errBadCertificate) {
|
|
|
|
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestHttpsInfoRogueServerCert connects via two-way authenticated HTTPS to the info endpoint
|
|
|
|
// which provides a rogue server certificate and checks that it fails with the expected error
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
|
2015-04-20 19:21:46 -04:00
|
|
|
const (
|
|
|
|
errCaUnknown = "x509: certificate signed by unknown authority"
|
|
|
|
testDaemonRogueHttpsAddr = "localhost:4272"
|
|
|
|
)
|
2015-04-25 22:47:42 -04:00
|
|
|
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem",
|
2015-04-20 19:21:46 -04:00
|
|
|
"--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHttpsAddr); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon with busybox: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//force tcp protocol
|
|
|
|
host := fmt.Sprintf("tcp://%s", testDaemonRogueHttpsAddr)
|
|
|
|
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
|
2015-04-25 22:47:42 -04:00
|
|
|
out, err := s.d.CmdWithArgs(daemonArgs, "info")
|
2015-04-20 19:21:46 -04:00
|
|
|
if err == nil || !strings.Contains(out, errCaUnknown) {
|
|
|
|
c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out)
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 23:36:40 -04:00
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
|
|
|
|
var dargs []string
|
|
|
|
if d != nil {
|
|
|
|
dargs = []string{"--host", d.sock()}
|
|
|
|
}
|
|
|
|
|
|
|
|
args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top")
|
|
|
|
_, err := runCommand(exec.Command(dockerBinary, args...))
|
2015-04-27 23:36:40 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c")
|
2015-04-27 23:36:40 -04:00
|
|
|
pingCmd := "ping -c 1 %s -W 1"
|
2015-04-28 19:17:00 -04:00
|
|
|
args = append(args, fmt.Sprintf(pingCmd, "alias1"))
|
|
|
|
_, err = runCommand(exec.Command(dockerBinary, args...))
|
|
|
|
|
|
|
|
if expectFailure {
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
} else {
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|
2015-04-27 23:36:40 -04:00
|
|
|
|
2015-04-28 19:17:00 -04:00
|
|
|
args = append(dargs, "rm", "-f", "container1")
|
|
|
|
runCommand(exec.Command(dockerBinary, args...))
|
2015-04-27 23:36:40 -04:00
|
|
|
}
|
2015-05-07 18:35:12 -04:00
|
|
|
|
2015-05-19 12:32:19 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) {
|
2015-05-07 18:35:12 -04:00
|
|
|
c.Assert(s.d.StartWithBusybox(), check.IsNil)
|
|
|
|
|
|
|
|
socket := filepath.Join(s.d.folder, "docker.sock")
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "-d", "-v", socket+":/sock", "busybox")
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
|
|
c.Assert(s.d.Restart(), check.IsNil)
|
|
|
|
}
|
2015-05-19 12:32:19 -04:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) {
|
|
|
|
c.Assert(s.d.StartWithBusybox(), check.IsNil)
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "-d", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil)
|
|
|
|
c.Assert(s.d.Start(), check.IsNil)
|
|
|
|
mountOut, err := exec.Command("mount").CombinedOutput()
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
|
|
|
c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, check.Commentf("Something mounted from older daemon start: %s", mountOut))
|
|
|
|
}
|
2015-05-24 11:26:56 -04:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
|
2015-05-28 17:54:12 -04:00
|
|
|
testRequires(c, NativeExecDriver)
|
2015-05-24 11:26:56 -04:00
|
|
|
c.Assert(s.d.StartWithBusybox("-b", "none"), check.IsNil)
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l")
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
|
|
c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
|
|
|
|
check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out))
|
|
|
|
}
|
2015-05-25 21:25:34 -04:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox"); err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
2015-06-05 18:02:56 -04:00
|
|
|
|
2015-05-25 21:25:34 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Container 'test' should be removed without error
|
|
|
|
if out, err := s.d.Cmd("rm", "test"); err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 18:02:56 -04:00
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) {
|
|
|
|
if err := s.d.StartWithBusybox(); err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
out, err := s.d.Cmd("run", "--name", "netns", "-d", "busybox", "top")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(out, err)
|
|
|
|
}
|
|
|
|
if out, err := s.d.Cmd("stop", "netns"); err != nil {
|
|
|
|
c.Fatal(out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct netns file name from container id
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
nsFile := out[:12]
|
|
|
|
|
|
|
|
// Test if the file still exists
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", "/var/run/docker/netns/"+nsFile))
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
|
|
c.Assert(out, check.Equals, "/var/run/docker/netns/"+nsFile, check.Commentf("Output: %s", out))
|
|
|
|
|
|
|
|
// Remove the container and restart the daemon
|
|
|
|
if out, err := s.d.Cmd("rm", "netns"); err != nil {
|
|
|
|
c.Fatal(out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.d.Restart(); err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test again and see now the netns file does not exist
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", "/var/run/docker/netns/"+nsFile))
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
c.Assert(err, check.Not(check.IsNil), check.Commentf("Output: %s", out))
|
|
|
|
// c.Assert(out, check.Equals, "", check.Commentf("Output: %s", out))
|
|
|
|
}
|