1
0
mirror of https://github.com/moby/moby.git synced 2025-10-24 09:13:09 +03:00

Update port info on network connect/disconnect

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch
2016-05-25 13:47:38 -07:00
parent ff3dc48966
commit f198dfd856
3 changed files with 54 additions and 2 deletions

View File

@@ -1110,6 +1110,52 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C)
dockerCmd(c, "network", "connect", "test1", "c1")
}
func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) {
chk := checker.Equals
if !mustBeEqual {
chk = checker.Not(checker.Equals)
}
currentMapping, _ := dockerCmd(c, "port", container, port)
c.Assert(currentMapping, chk, originalMapping)
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c *check.C) {
// Connect and disconnect a container with explicit and non-explicit
// host port mapping to/from networks which do cause and do not cause
// the container default gateway to change, and verify docker port cmd
// returns congruent information
testRequires(c, NotArm)
cnt := "c1"
dockerCmd(c, "network", "create", "aaa")
dockerCmd(c, "network", "create", "ccc")
dockerCmd(c, "run", "-d", "--name", cnt, "-p", "9000:90", "-p", "70", "busybox", "top")
c.Assert(waitRun(cnt), check.IsNil)
curPortMap, _ := dockerCmd(c, "port", cnt, "70")
curExplPortMap, _ := dockerCmd(c, "port", cnt, "90")
// Connect to a network which causes the container's default gw switch
dockerCmd(c, "network", "connect", "aaa", cnt)
verifyPortMap(c, cnt, "70", curPortMap, false)
verifyPortMap(c, cnt, "90", curExplPortMap, true)
// Read current mapping
curPortMap, _ = dockerCmd(c, "port", cnt, "70")
// Disconnect from a network which causes the container's default gw switch
dockerCmd(c, "network", "disconnect", "aaa", cnt)
verifyPortMap(c, cnt, "70", curPortMap, false)
verifyPortMap(c, cnt, "90", curExplPortMap, true)
// Read current mapping
curPortMap, _ = dockerCmd(c, "port", cnt, "70")
// Connect to a network which does not cause the container's default gw switch
dockerCmd(c, "network", "connect", "ccc", cnt)
verifyPortMap(c, cnt, "70", curPortMap, true)
verifyPortMap(c, cnt, "90", curExplPortMap, true)
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectWithMac(c *check.C) {
macAddress := "02:42:ac:11:00:02"
dockerCmd(c, "network", "create", "mynetwork")