Skip to content

Commit

Permalink
Add test case for network restore
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Jitang <[email protected]>
  • Loading branch information
coolljt0725 authored and aboch committed Jun 14, 2016
1 parent ecffb6d commit 7d0689a
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions integration-cli/docker_cli_network_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,3 +1539,67 @@ func (s *DockerNetworkSuite) TestDockerNetworkCreateDeleteSpecialCharacters(c *c
dockerCmd(c, "network", "rm", "kiwl$%^")
assertNwNotAvailable(c, "kiwl$%^")
}

func (s *DockerDaemonSuite) TestDaemonRestartRestoreBridgeNetwork(t *check.C) {
testRequires(t, DaemonIsLinux)
if err := s.d.StartWithBusybox("--live-restore"); err != nil {
t.Fatal(err)
}
defer s.d.Stop()
oldCon := "old"

_, err := s.d.Cmd("run", "-d", "--name", oldCon, "-p", "80:80", "busybox", "top")
if err != nil {
t.Fatal(err)
}
oldContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", oldCon)
if err != nil {
t.Fatal(err)
}
// Kill the daemon
if err := s.d.Kill(); err != nil {
t.Fatal(err)
}

// restart the daemon
if err := s.d.Start("--live-restore"); err != nil {
t.Fatal(err)
}

// start a new container, the new container's ip should not be the same with
// old running container.
newCon := "new"
_, err = s.d.Cmd("run", "-d", "--name", newCon, "busybox", "top")
if err != nil {
t.Fatal(err)
}
newContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", newCon)
if err != nil {
t.Fatal(err)
}
if strings.Compare(strings.TrimSpace(oldContainerIP), strings.TrimSpace(newContainerIP)) == 0 {
t.Fatalf("new container ip should not equal to old running container ip")
}

// start a new container, the new container should ping old running container
_, err = s.d.Cmd("run", "-t", "busybox", "ping", "-c", "1", oldContainerIP)
if err != nil {
t.Fatal(err)
}

// start a new container try to publist port 80:80 will failed
out, err := s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top")
if err == nil || !strings.Contains(out, "Bind for 0.0.0.0:80 failed: port is already allocated") {
t.Fatalf("80 port is allocated to old running container, it should failed on allocating to new container")
}

// kill old running container and try to allocate again
_, err = s.d.Cmd("kill", oldCon)
if err != nil {
t.Fatal(err)
}
_, err = s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top")
if err != nil {
t.Fatal(err)
}
}

0 comments on commit 7d0689a

Please sign in to comment.