| ... | ... |
@@ -560,3 +560,46 @@ func TestEnvironment(t *testing.T) {
|
| 560 | 560 |
|
| 561 | 561 |
logDone("run - verify environment")
|
| 562 | 562 |
} |
| 563 |
+ |
|
| 564 |
+func TestContainerNetwork(t *testing.T) {
|
|
| 565 |
+ cmd := exec.Command(dockerBinary, "run", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 566 |
+ if _, err := runCommand(cmd); err != nil {
|
|
| 567 |
+ t.Fatal(err) |
|
| 568 |
+ } |
|
| 569 |
+ |
|
| 570 |
+ deleteAllContainers() |
|
| 571 |
+ |
|
| 572 |
+ logDone("run - test container network via ping")
|
|
| 573 |
+} |
|
| 574 |
+ |
|
| 575 |
+// Issue #4681 |
|
| 576 |
+func TestLoopbackWhenNetworkDisabled(t *testing.T) {
|
|
| 577 |
+ cmd := exec.Command(dockerBinary, "run", "--networking=false", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 578 |
+ if _, err := runCommand(cmd); err != nil {
|
|
| 579 |
+ t.Fatal(err) |
|
| 580 |
+ } |
|
| 581 |
+ |
|
| 582 |
+ deleteAllContainers() |
|
| 583 |
+ |
|
| 584 |
+ logDone("run - test container loopback when networking disabled")
|
|
| 585 |
+} |
|
| 586 |
+ |
|
| 587 |
+func TestLoopbackOnlyExistsWhenNetworkingDisabled(t *testing.T) {
|
|
| 588 |
+ cmd := exec.Command(dockerBinary, "run", "--networking=false", "busybox", "ip", "a", "show", "up") |
|
| 589 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 590 |
+ if err != nil {
|
|
| 591 |
+ t.Fatal(err, out) |
|
| 592 |
+ } |
|
| 593 |
+ |
|
| 594 |
+ interfaces := regexp.MustCompile(`(?m)^[0-9]+: [a-zA-Z0-9]+`).FindAllString(out, -1) |
|
| 595 |
+ if len(interfaces) != 1 {
|
|
| 596 |
+ t.Fatalf("Wrong interface count in test container: expected [*: lo], got %s", interfaces)
|
|
| 597 |
+ } |
|
| 598 |
+ if !strings.HasSuffix(interfaces[0], ": lo") {
|
|
| 599 |
+ t.Fatalf("Wrong interface in test container: expected [*: lo], got %s", interfaces)
|
|
| 600 |
+ } |
|
| 601 |
+ |
|
| 602 |
+ deleteAllContainers() |
|
| 603 |
+ |
|
| 604 |
+ logDone("run - test loopback only exists when networking disabled")
|
|
| 605 |
+} |
| ... | ... |
@@ -583,106 +583,6 @@ func TestRestartWithVolumes(t *testing.T) {
|
| 583 | 583 |
} |
| 584 | 584 |
} |
| 585 | 585 |
|
| 586 |
-func TestContainerNetwork(t *testing.T) {
|
|
| 587 |
- daemon := mkDaemon(t) |
|
| 588 |
- defer nuke(daemon) |
|
| 589 |
- container, _, err := daemon.Create( |
|
| 590 |
- &runconfig.Config{
|
|
| 591 |
- Image: GetTestImage(daemon).ID, |
|
| 592 |
- // If I change this to ping 8.8.8.8 it fails. Any idea why? - timthelion |
|
| 593 |
- Cmd: []string{"ping", "-c", "1", "127.0.0.1"},
|
|
| 594 |
- }, |
|
| 595 |
- "", |
|
| 596 |
- ) |
|
| 597 |
- if err != nil {
|
|
| 598 |
- t.Fatal(err) |
|
| 599 |
- } |
|
| 600 |
- defer daemon.Destroy(container) |
|
| 601 |
- if err := container.Run(); err != nil {
|
|
| 602 |
- t.Fatal(err) |
|
| 603 |
- } |
|
| 604 |
- if code := container.State.GetExitCode(); code != 0 {
|
|
| 605 |
- t.Fatalf("Unexpected ping 127.0.0.1 exit code %d (expected 0)", code)
|
|
| 606 |
- } |
|
| 607 |
-} |
|
| 608 |
- |
|
| 609 |
-// Issue #4681 |
|
| 610 |
-func TestLoopbackFunctionsWhenNetworkingIsDissabled(t *testing.T) {
|
|
| 611 |
- daemon := mkDaemon(t) |
|
| 612 |
- defer nuke(daemon) |
|
| 613 |
- container, _, err := daemon.Create( |
|
| 614 |
- &runconfig.Config{
|
|
| 615 |
- Image: GetTestImage(daemon).ID, |
|
| 616 |
- Cmd: []string{"ping", "-c", "1", "127.0.0.1"},
|
|
| 617 |
- NetworkDisabled: true, |
|
| 618 |
- }, |
|
| 619 |
- "", |
|
| 620 |
- ) |
|
| 621 |
- if err != nil {
|
|
| 622 |
- t.Fatal(err) |
|
| 623 |
- } |
|
| 624 |
- defer daemon.Destroy(container) |
|
| 625 |
- if err := container.Run(); err != nil {
|
|
| 626 |
- t.Fatal(err) |
|
| 627 |
- } |
|
| 628 |
- if code := container.State.GetExitCode(); code != 0 {
|
|
| 629 |
- t.Fatalf("Unexpected ping 127.0.0.1 exit code %d (expected 0)", code)
|
|
| 630 |
- } |
|
| 631 |
-} |
|
| 632 |
- |
|
| 633 |
-func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) {
|
|
| 634 |
- eng := NewTestEngine(t) |
|
| 635 |
- daemon := mkDaemonFromEngine(eng, t) |
|
| 636 |
- defer nuke(daemon) |
|
| 637 |
- |
|
| 638 |
- config, hc, _, err := runconfig.Parse([]string{"-n=false", GetTestImage(daemon).ID, "ip", "addr", "show", "up"}, nil)
|
|
| 639 |
- if err != nil {
|
|
| 640 |
- t.Fatal(err) |
|
| 641 |
- } |
|
| 642 |
- |
|
| 643 |
- jobCreate := eng.Job("create")
|
|
| 644 |
- if err := jobCreate.ImportEnv(config); err != nil {
|
|
| 645 |
- t.Fatal(err) |
|
| 646 |
- } |
|
| 647 |
- var id string |
|
| 648 |
- jobCreate.Stdout.AddString(&id) |
|
| 649 |
- if err := jobCreate.Run(); err != nil {
|
|
| 650 |
- t.Fatal(err) |
|
| 651 |
- } |
|
| 652 |
- // FIXME: this hack can be removed once Wait is a job |
|
| 653 |
- c := daemon.Get(id) |
|
| 654 |
- if c == nil {
|
|
| 655 |
- t.Fatalf("Couldn't retrieve container %s from daemon", id)
|
|
| 656 |
- } |
|
| 657 |
- stdout, err := c.StdoutPipe() |
|
| 658 |
- if err != nil {
|
|
| 659 |
- t.Fatal(err) |
|
| 660 |
- } |
|
| 661 |
- |
|
| 662 |
- jobStart := eng.Job("start", id)
|
|
| 663 |
- if err := jobStart.ImportEnv(hc); err != nil {
|
|
| 664 |
- t.Fatal(err) |
|
| 665 |
- } |
|
| 666 |
- if err := jobStart.Run(); err != nil {
|
|
| 667 |
- t.Fatal(err) |
|
| 668 |
- } |
|
| 669 |
- |
|
| 670 |
- c.WaitTimeout(500 * time.Millisecond) |
|
| 671 |
- c.Wait() |
|
| 672 |
- output, err := ioutil.ReadAll(stdout) |
|
| 673 |
- if err != nil {
|
|
| 674 |
- t.Fatal(err) |
|
| 675 |
- } |
|
| 676 |
- |
|
| 677 |
- interfaces := regexp.MustCompile(`(?m)^[0-9]+: [a-zA-Z0-9]+`).FindAllString(string(output), -1) |
|
| 678 |
- if len(interfaces) != 1 {
|
|
| 679 |
- t.Fatalf("Wrong interface count in test container: expected [*: lo], got %s", interfaces)
|
|
| 680 |
- } |
|
| 681 |
- if !strings.HasSuffix(interfaces[0], ": lo") {
|
|
| 682 |
- t.Fatalf("Wrong interface in test container: expected [*: lo], got %s", interfaces)
|
|
| 683 |
- } |
|
| 684 |
-} |
|
| 685 |
- |
|
| 686 | 586 |
func TestPrivilegedCanMknod(t *testing.T) {
|
| 687 | 587 |
eng := NewTestEngine(t) |
| 688 | 588 |
daemon := mkDaemonFromEngine(eng, t) |