Signed-off-by: Madhu Venugopal <madhu@docker.com>
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"encoding/json" |
| 7 | 7 |
"fmt" |
| 8 | 8 |
"io/ioutil" |
| 9 |
+ "net" |
|
| 9 | 10 |
"os" |
| 10 | 11 |
"os/exec" |
| 11 | 12 |
"path/filepath" |
| ... | ... |
@@ -447,6 +448,46 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
|
| 447 | 447 |
} |
| 448 | 448 |
} |
| 449 | 449 |
|
| 450 |
+func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
|
| 451 |
+ d := s.d |
|
| 452 |
+ err := d.Start("--bridge", "nosuchbridge")
|
|
| 453 |
+ c.Assert(err, check.Not(check.IsNil), check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail"))
|
|
| 454 |
+ |
|
| 455 |
+ bridgeName := "external-bridge" |
|
| 456 |
+ bridgeIp := "192.169.1.1/24" |
|
| 457 |
+ _, bridgeIPNet, _ := net.ParseCIDR(bridgeIp) |
|
| 458 |
+ |
|
| 459 |
+ args := []string{"link", "add", "name", bridgeName, "type", "bridge"}
|
|
| 460 |
+ ipLinkCmd := exec.Command("ip", args...)
|
|
| 461 |
+ _, _, _, err = runCommandWithStdoutStderr(ipLinkCmd) |
|
| 462 |
+ c.Assert(err, check.IsNil) |
|
| 463 |
+ |
|
| 464 |
+ ifCfgCmd := exec.Command("ifconfig", bridgeName, bridgeIp, "up")
|
|
| 465 |
+ _, _, _, err = runCommandWithStdoutStderr(ifCfgCmd) |
|
| 466 |
+ c.Assert(err, check.IsNil) |
|
| 467 |
+ |
|
| 468 |
+ err = d.StartWithBusybox("--bridge", bridgeName)
|
|
| 469 |
+ c.Assert(err, check.IsNil) |
|
| 470 |
+ |
|
| 471 |
+ ipTablesSearchString := bridgeIPNet.String() |
|
| 472 |
+ ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
|
| 473 |
+ out, _, err := runCommandWithOutput(ipTablesCmd) |
|
| 474 |
+ c.Assert(err, check.IsNil) |
|
| 475 |
+ |
|
| 476 |
+ c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true, |
|
| 477 |
+ check.Commentf("iptables output should have contained %q, but was %q",
|
|
| 478 |
+ ipTablesSearchString, out)) |
|
| 479 |
+ |
|
| 480 |
+ _, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
|
|
| 481 |
+ c.Assert(err, check.IsNil) |
|
| 482 |
+ |
|
| 483 |
+ containerIp := d.findContainerIP(c, "ExtContainer") |
|
| 484 |
+ ip := net.ParseIP(containerIp) |
|
| 485 |
+ c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, |
|
| 486 |
+ check.Commentf("Container IP-Address must be in the same subnet range : %s",
|
|
| 487 |
+ containerIp)) |
|
| 488 |
+} |
|
| 489 |
+ |
|
| 450 | 490 |
func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) {
|
| 451 | 491 |
testRequires(c, NativeExecDriver) |
| 452 | 492 |
|
| ... | ... |
@@ -570,8 +570,9 @@ func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...strin |
| 570 | 570 |
return out, status, err |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 |
-func findContainerIP(c *check.C, id string) string {
|
|
| 574 |
- cmd := exec.Command(dockerBinary, "inspect", "--format='{{ .NetworkSettings.IPAddress }}'", id)
|
|
| 573 |
+func findContainerIP(c *check.C, id string, vargs ...string) string {
|
|
| 574 |
+ args := append(vargs, "inspect", "--format='{{ .NetworkSettings.IPAddress }}'", id)
|
|
| 575 |
+ cmd := exec.Command(dockerBinary, args...) |
|
| 575 | 576 |
out, _, err := runCommandWithOutput(cmd) |
| 576 | 577 |
if err != nil {
|
| 577 | 578 |
c.Fatal(err, out) |
| ... | ... |
@@ -580,6 +581,10 @@ func findContainerIP(c *check.C, id string) string {
|
| 580 | 580 |
return strings.Trim(out, " \r\n'") |
| 581 | 581 |
} |
| 582 | 582 |
|
| 583 |
+func (d *Daemon) findContainerIP(c *check.C, id string) string {
|
|
| 584 |
+ return findContainerIP(c, id, "--host", d.sock()) |
|
| 585 |
+} |
|
| 586 |
+ |
|
| 583 | 587 |
func getContainerCount() (int, error) {
|
| 584 | 588 |
const containers = "Containers:" |
| 585 | 589 |
|