Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -1539,3 +1539,67 @@ func (s *DockerNetworkSuite) TestDockerNetworkCreateDeleteSpecialCharacters(c *c |
| 1539 | 1539 |
dockerCmd(c, "network", "rm", "kiwl$%^") |
| 1540 | 1540 |
assertNwNotAvailable(c, "kiwl$%^") |
| 1541 | 1541 |
} |
| 1542 |
+ |
|
| 1543 |
+func (s *DockerDaemonSuite) TestDaemonRestartRestoreBridgeNetwork(t *check.C) {
|
|
| 1544 |
+ testRequires(t, DaemonIsLinux) |
|
| 1545 |
+ if err := s.d.StartWithBusybox("--live-restore"); err != nil {
|
|
| 1546 |
+ t.Fatal(err) |
|
| 1547 |
+ } |
|
| 1548 |
+ defer s.d.Stop() |
|
| 1549 |
+ oldCon := "old" |
|
| 1550 |
+ |
|
| 1551 |
+ _, err := s.d.Cmd("run", "-d", "--name", oldCon, "-p", "80:80", "busybox", "top")
|
|
| 1552 |
+ if err != nil {
|
|
| 1553 |
+ t.Fatal(err) |
|
| 1554 |
+ } |
|
| 1555 |
+ oldContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", oldCon)
|
|
| 1556 |
+ if err != nil {
|
|
| 1557 |
+ t.Fatal(err) |
|
| 1558 |
+ } |
|
| 1559 |
+ // Kill the daemon |
|
| 1560 |
+ if err := s.d.Kill(); err != nil {
|
|
| 1561 |
+ t.Fatal(err) |
|
| 1562 |
+ } |
|
| 1563 |
+ |
|
| 1564 |
+ // restart the daemon |
|
| 1565 |
+ if err := s.d.Start("--live-restore"); err != nil {
|
|
| 1566 |
+ t.Fatal(err) |
|
| 1567 |
+ } |
|
| 1568 |
+ |
|
| 1569 |
+ // start a new container, the new container's ip should not be the same with |
|
| 1570 |
+ // old running container. |
|
| 1571 |
+ newCon := "new" |
|
| 1572 |
+ _, err = s.d.Cmd("run", "-d", "--name", newCon, "busybox", "top")
|
|
| 1573 |
+ if err != nil {
|
|
| 1574 |
+ t.Fatal(err) |
|
| 1575 |
+ } |
|
| 1576 |
+ newContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", newCon)
|
|
| 1577 |
+ if err != nil {
|
|
| 1578 |
+ t.Fatal(err) |
|
| 1579 |
+ } |
|
| 1580 |
+ if strings.Compare(strings.TrimSpace(oldContainerIP), strings.TrimSpace(newContainerIP)) == 0 {
|
|
| 1581 |
+ t.Fatalf("new container ip should not equal to old running container ip")
|
|
| 1582 |
+ } |
|
| 1583 |
+ |
|
| 1584 |
+ // start a new container, the new container should ping old running container |
|
| 1585 |
+ _, err = s.d.Cmd("run", "-t", "busybox", "ping", "-c", "1", oldContainerIP)
|
|
| 1586 |
+ if err != nil {
|
|
| 1587 |
+ t.Fatal(err) |
|
| 1588 |
+ } |
|
| 1589 |
+ |
|
| 1590 |
+ // start a new container try to publist port 80:80 will failed |
|
| 1591 |
+ out, err := s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top")
|
|
| 1592 |
+ if err == nil || !strings.Contains(out, "Bind for 0.0.0.0:80 failed: port is already allocated") {
|
|
| 1593 |
+ t.Fatalf("80 port is allocated to old running container, it should failed on allocating to new container")
|
|
| 1594 |
+ } |
|
| 1595 |
+ |
|
| 1596 |
+ // kill old running container and try to allocate again |
|
| 1597 |
+ _, err = s.d.Cmd("kill", oldCon)
|
|
| 1598 |
+ if err != nil {
|
|
| 1599 |
+ t.Fatal(err) |
|
| 1600 |
+ } |
|
| 1601 |
+ _, err = s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top")
|
|
| 1602 |
+ if err != nil {
|
|
| 1603 |
+ t.Fatal(err) |
|
| 1604 |
+ } |
|
| 1605 |
+} |