Signed-off-by: Madhu Venugopal <madhu@docker.com>
| ... | ... |
@@ -453,20 +453,13 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
|
| 453 | 453 |
func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
| 454 | 454 |
d := s.d |
| 455 | 455 |
err := d.Start("--bridge", "nosuchbridge")
|
| 456 |
- c.Assert(err, check.Not(check.IsNil), check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail"))
|
|
| 456 |
+ c.Assert(err, check.NotNil, check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail"))
|
|
| 457 | 457 |
|
| 458 | 458 |
bridgeName := "external-bridge" |
| 459 | 459 |
bridgeIp := "192.169.1.1/24" |
| 460 | 460 |
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIp) |
| 461 | 461 |
|
| 462 |
- args := []string{"link", "add", "name", bridgeName, "type", "bridge"}
|
|
| 463 |
- ipLinkCmd := exec.Command("ip", args...)
|
|
| 464 |
- _, _, _, err = runCommandWithStdoutStderr(ipLinkCmd) |
|
| 465 |
- c.Assert(err, check.IsNil) |
|
| 466 |
- |
|
| 467 |
- ifCfgCmd := exec.Command("ifconfig", bridgeName, bridgeIp, "up")
|
|
| 468 |
- _, _, _, err = runCommandWithStdoutStderr(ifCfgCmd) |
|
| 469 |
- c.Assert(err, check.IsNil) |
|
| 462 |
+ createInterface(c, "bridge", bridgeName, bridgeIp) |
|
| 470 | 463 |
|
| 471 | 464 |
err = d.StartWithBusybox("--bridge", bridgeName)
|
| 472 | 465 |
c.Assert(err, check.IsNil) |
| ... | ... |
@@ -483,7 +476,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
| 483 | 483 |
_, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
|
| 484 | 484 |
c.Assert(err, check.IsNil) |
| 485 | 485 |
|
| 486 |
- containerIp := d.findContainerIP(c, "ExtContainer") |
|
| 486 |
+ containerIp := d.findContainerIP("ExtContainer")
|
|
| 487 | 487 |
ip := net.ParseIP(containerIp) |
| 488 | 488 |
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, |
| 489 | 489 |
check.Commentf("Container IP-Address must be in the same subnet range : %s",
|
| ... | ... |
@@ -494,14 +487,29 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
| 494 | 494 |
d.Restart() |
| 495 | 495 |
} |
| 496 | 496 |
|
| 497 |
+func createInterface(c *check.C, ifType string, ifName string, ipNet string) {
|
|
| 498 |
+ args := []string{"link", "add", "name", ifName, "type", ifType}
|
|
| 499 |
+ ipLinkCmd := exec.Command("ip", args...)
|
|
| 500 |
+ out, _, err := runCommandWithOutput(ipLinkCmd) |
|
| 501 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 502 |
+ |
|
| 503 |
+ ifCfgCmd := exec.Command("ifconfig", ifName, ipNet, "up")
|
|
| 504 |
+ out, _, err = runCommandWithOutput(ifCfgCmd) |
|
| 505 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 506 |
+} |
|
| 507 |
+ |
|
| 497 | 508 |
func deleteInterface(c *check.C, bridge string) {
|
| 498 | 509 |
ifCmd := exec.Command("ip", "link", "delete", bridge)
|
| 499 |
- _, _, _, err := runCommandWithStdoutStderr(ifCmd) |
|
| 500 |
- c.Assert(err, check.IsNil) |
|
| 510 |
+ out, _, err := runCommandWithOutput(ifCmd) |
|
| 511 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 501 | 512 |
|
| 502 | 513 |
flushCmd := exec.Command("iptables", "-t", "nat", "--flush")
|
| 503 |
- _, _, _, err = runCommandWithStdoutStderr(flushCmd) |
|
| 504 |
- c.Assert(err, check.IsNil) |
|
| 514 |
+ out, _, err = runCommandWithOutput(flushCmd) |
|
| 515 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 516 |
+ |
|
| 517 |
+ flushCmd = exec.Command("iptables", "--flush")
|
|
| 518 |
+ out, _, err = runCommandWithOutput(flushCmd) |
|
| 519 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 505 | 520 |
} |
| 506 | 521 |
|
| 507 | 522 |
func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
|
| ... | ... |
@@ -547,7 +555,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
|
| 547 | 547 |
out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
| 548 | 548 |
c.Assert(err, check.IsNil) |
| 549 | 549 |
|
| 550 |
- containerIp := d.findContainerIP(c, "test") |
|
| 550 |
+ containerIp := d.findContainerIP("test")
|
|
| 551 | 551 |
ip = net.ParseIP(containerIp) |
| 552 | 552 |
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, |
| 553 | 553 |
check.Commentf("Container IP-Address must be in the same subnet range : %s",
|
| ... | ... |
@@ -556,24 +564,19 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
|
| 556 | 556 |
// Reset to Defaults |
| 557 | 557 |
deleteInterface(c, defaultNetworkBridge) |
| 558 | 558 |
d.Restart() |
| 559 |
- pingContainers(c) |
|
| 559 |
+ pingContainers(c, nil, false) |
|
| 560 | 560 |
} |
| 561 | 561 |
|
| 562 | 562 |
func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
|
| 563 | 563 |
d := s.d |
| 564 | 564 |
|
| 565 | 565 |
bridgeName := "external-bridge" |
| 566 |
- args := []string{"link", "add", "name", bridgeName, "type", "bridge"}
|
|
| 567 |
- ipLinkCmd := exec.Command("ip", args...)
|
|
| 568 |
- _, _, _, err := runCommandWithStdoutStderr(ipLinkCmd) |
|
| 569 |
- c.Assert(err, check.IsNil) |
|
| 566 |
+ bridgeIp := "192.169.1.1/24" |
|
| 570 | 567 |
|
| 571 |
- ifCmd := exec.Command("ifconfig", bridgeName, "192.169.1.1/24", "up")
|
|
| 572 |
- _, _, _, err = runCommandWithStdoutStderr(ifCmd) |
|
| 573 |
- c.Assert(err, check.IsNil) |
|
| 568 |
+ createInterface(c, "bridge", bridgeName, bridgeIp) |
|
| 574 | 569 |
|
| 575 |
- args = []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"}
|
|
| 576 |
- err = d.StartWithBusybox(args...) |
|
| 570 |
+ args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"}
|
|
| 571 |
+ err := d.StartWithBusybox(args...) |
|
| 577 | 572 |
c.Assert(err, check.IsNil) |
| 578 | 573 |
|
| 579 | 574 |
for i := 0; i < 4; i++ {
|
| ... | ... |
@@ -600,19 +603,12 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
|
| 600 | 600 |
c.Assert(err, check.IsNil) |
| 601 | 601 |
|
| 602 | 602 |
out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
|
| 603 |
- c.Assert(err, check.Not(check.IsNil), |
|
| 603 |
+ c.Assert(err, check.NotNil, |
|
| 604 | 604 |
check.Commentf("Running a container must fail with an invalid --ip option"))
|
| 605 | 605 |
c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true) |
| 606 | 606 |
|
| 607 | 607 |
ifName := "dummy" |
| 608 |
- args = []string{"link", "add", "name", ifName, "type", "dummy"}
|
|
| 609 |
- ipLinkCmd := exec.Command("ip", args...)
|
|
| 610 |
- _, _, _, err = runCommandWithStdoutStderr(ipLinkCmd) |
|
| 611 |
- c.Assert(err, check.IsNil) |
|
| 612 |
- |
|
| 613 |
- ifCmd := exec.Command("ifconfig", ifName, ipStr, "up")
|
|
| 614 |
- _, _, _, err = runCommandWithStdoutStderr(ifCmd) |
|
| 615 |
- c.Assert(err, check.IsNil) |
|
| 608 |
+ createInterface(c, "dummy", ifName, ipStr) |
|
| 616 | 609 |
|
| 617 | 610 |
_, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
|
| 618 | 611 |
c.Assert(err, check.IsNil) |
| ... | ... |
@@ -631,6 +627,79 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
|
| 631 | 631 |
d.Restart() |
| 632 | 632 |
} |
| 633 | 633 |
|
| 634 |
+func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
|
|
| 635 |
+ d := s.d |
|
| 636 |
+ |
|
| 637 |
+ bridgeName := "external-bridge" |
|
| 638 |
+ bridgeIp := "192.169.1.1/24" |
|
| 639 |
+ |
|
| 640 |
+ createInterface(c, "bridge", bridgeName, bridgeIp) |
|
| 641 |
+ |
|
| 642 |
+ args := []string{"--bridge", bridgeName, "--icc=false"}
|
|
| 643 |
+ err := d.StartWithBusybox(args...) |
|
| 644 |
+ c.Assert(err, check.IsNil) |
|
| 645 |
+ |
|
| 646 |
+ ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
|
|
| 647 |
+ out, _, err := runCommandWithOutput(ipTablesCmd) |
|
| 648 |
+ c.Assert(err, check.IsNil) |
|
| 649 |
+ |
|
| 650 |
+ regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
|
|
| 651 |
+ matched, _ := regexp.MatchString(regex, out) |
|
| 652 |
+ c.Assert(matched, check.Equals, true, |
|
| 653 |
+ check.Commentf("iptables output should have contained %q, but was %q", regex, out))
|
|
| 654 |
+ |
|
| 655 |
+ // Pinging another container must fail with --icc=false |
|
| 656 |
+ pingContainers(c, d, true) |
|
| 657 |
+ |
|
| 658 |
+ ipStr := "192.171.1.1/24" |
|
| 659 |
+ ip, _, _ := net.ParseCIDR(ipStr) |
|
| 660 |
+ ifName := "icc-dummy" |
|
| 661 |
+ |
|
| 662 |
+ createInterface(c, "dummy", ifName, ipStr) |
|
| 663 |
+ |
|
| 664 |
+ // But, Pinging external or a Host interface must succeed |
|
| 665 |
+ pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
|
|
| 666 |
+ runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd}
|
|
| 667 |
+ _, err = d.Cmd("run", runArgs...)
|
|
| 668 |
+ c.Assert(err, check.IsNil) |
|
| 669 |
+ |
|
| 670 |
+ // Reset to Defaults |
|
| 671 |
+ deleteInterface(c, ifName) |
|
| 672 |
+ d.Restart() |
|
| 673 |
+} |
|
| 674 |
+ |
|
| 675 |
+func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
|
|
| 676 |
+ d := s.d |
|
| 677 |
+ |
|
| 678 |
+ bridgeName := "external-bridge" |
|
| 679 |
+ bridgeIp := "192.169.1.1/24" |
|
| 680 |
+ |
|
| 681 |
+ createInterface(c, "bridge", bridgeName, bridgeIp) |
|
| 682 |
+ |
|
| 683 |
+ args := []string{"--bridge", bridgeName, "--icc=false"}
|
|
| 684 |
+ err := d.StartWithBusybox(args...) |
|
| 685 |
+ c.Assert(err, check.IsNil) |
|
| 686 |
+ |
|
| 687 |
+ ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
|
|
| 688 |
+ out, _, err := runCommandWithOutput(ipTablesCmd) |
|
| 689 |
+ c.Assert(err, check.IsNil) |
|
| 690 |
+ |
|
| 691 |
+ regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
|
|
| 692 |
+ matched, _ := regexp.MatchString(regex, out) |
|
| 693 |
+ c.Assert(matched, check.Equals, true, |
|
| 694 |
+ check.Commentf("iptables output should have contained %q, but was %q", regex, out))
|
|
| 695 |
+ |
|
| 696 |
+ _, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567")
|
|
| 697 |
+ c.Assert(err, check.IsNil) |
|
| 698 |
+ |
|
| 699 |
+ out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567")
|
|
| 700 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 701 |
+ |
|
| 702 |
+ // Reset to Defaults |
|
| 703 |
+ deleteInterface(c, bridgeName) |
|
| 704 |
+ d.Restart() |
|
| 705 |
+} |
|
| 706 |
+ |
|
| 634 | 707 |
func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) {
|
| 635 | 708 |
testRequires(c, NativeExecDriver) |
| 636 | 709 |
|
| ... | ... |
@@ -1074,15 +1143,27 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
|
| 1074 | 1074 |
} |
| 1075 | 1075 |
} |
| 1076 | 1076 |
|
| 1077 |
-func pingContainers(c *check.C) {
|
|
| 1078 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "container1", |
|
| 1079 |
- "--hostname", "fred", "busybox", "top") |
|
| 1080 |
- _, err := runCommand(runCmd) |
|
| 1077 |
+func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
|
|
| 1078 |
+ var dargs []string |
|
| 1079 |
+ if d != nil {
|
|
| 1080 |
+ dargs = []string{"--host", d.sock()}
|
|
| 1081 |
+ } |
|
| 1082 |
+ |
|
| 1083 |
+ args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top") |
|
| 1084 |
+ _, err := runCommand(exec.Command(dockerBinary, args...)) |
|
| 1081 | 1085 |
c.Assert(err, check.IsNil) |
| 1082 | 1086 |
|
| 1083 |
- runArgs := []string{"run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c"}
|
|
| 1087 |
+ args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c") |
|
| 1084 | 1088 |
pingCmd := "ping -c 1 %s -W 1" |
| 1089 |
+ args = append(args, fmt.Sprintf(pingCmd, "alias1")) |
|
| 1090 |
+ _, err = runCommand(exec.Command(dockerBinary, args...)) |
|
| 1091 |
+ |
|
| 1092 |
+ if expectFailure {
|
|
| 1093 |
+ c.Assert(err, check.NotNil) |
|
| 1094 |
+ } else {
|
|
| 1095 |
+ c.Assert(err, check.IsNil) |
|
| 1096 |
+ } |
|
| 1085 | 1097 |
|
| 1086 |
- dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1"))...) |
|
| 1087 |
- dockerCmd(c, "rm", "-f", "container1") |
|
| 1098 |
+ args = append(dargs, "rm", "-f", "container1") |
|
| 1099 |
+ runCommand(exec.Command(dockerBinary, args...)) |
|
| 1088 | 1100 |
} |
| ... | ... |
@@ -581,8 +581,8 @@ func findContainerIP(c *check.C, id string, vargs ...string) string {
|
| 581 | 581 |
return strings.Trim(out, " \r\n'") |
| 582 | 582 |
} |
| 583 | 583 |
|
| 584 |
-func (d *Daemon) findContainerIP(c *check.C, id string) string {
|
|
| 585 |
- return findContainerIP(c, id, "--host", d.sock()) |
|
| 584 |
+func (d *Daemon) findContainerIP(id string) string {
|
|
| 585 |
+ return findContainerIP(d.c, id, "--host", d.sock()) |
|
| 586 | 586 |
} |
| 587 | 587 |
|
| 588 | 588 |
func getContainerCount() (int, error) {
|