1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #19291 from coolljt0725/fix_19100

Fix #19100 and fix a typo
This commit is contained in:
Tibor Vass 2016-01-14 11:40:29 -05:00
commit 349d9700bd
2 changed files with 54 additions and 1 deletions

View file

@ -31,12 +31,22 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
// creating a container, not during start. // creating a container, not during start.
if hostConfig != nil { if hostConfig != nil {
logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12") logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12")
oldNetworkMode := container.HostConfig.NetworkMode
if err := daemon.setSecurityOptions(container, hostConfig); err != nil { if err := daemon.setSecurityOptions(container, hostConfig); err != nil {
return err return err
} }
if err := daemon.setHostConfig(container, hostConfig); err != nil { if err := daemon.setHostConfig(container, hostConfig); err != nil {
return err return err
} }
newNetworkMode := container.HostConfig.NetworkMode
if string(oldNetworkMode) != string(newNetworkMode) {
// if user has change the network mode on starting, clean up the
// old networks. It is a deprecated feature and will be removed in Docker 1.12
container.NetworkSettings.Networks = nil
if err := container.ToDisk(); err != nil {
return err
}
}
container.InitDNSHostConfig() container.InitDNSHostConfig()
} }
} else { } else {

View file

@ -940,7 +940,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkInspectCreatedContainer(c *check.C
c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should return 'bridge' network")) c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should return 'bridge' network"))
} }
func (s *DockerNetworkSuite) TestDockerNetworkRestartWithMulipleNetworks(c *check.C) { func (s *DockerNetworkSuite) TestDockerNetworkRestartWithMultipleNetworks(c *check.C) {
dockerCmd(c, "network", "create", "test") dockerCmd(c, "network", "create", "test")
dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
c.Assert(waitRun("foo"), checker.IsNil) c.Assert(waitRun("foo"), checker.IsNil)
@ -1097,3 +1097,46 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectLink(c *check.C) {
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo2") _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo2")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
} }
// #19100 This is a deprecated feature test, it should be remove in Docker 1.12
func (s *DockerNetworkSuite) TestDockerNetworkStartAPIWithHostconfig(c *check.C) {
netName := "test"
conName := "foo"
dockerCmd(c, "network", "create", netName)
dockerCmd(c, "create", "--name", conName, "busybox", "top")
config := map[string]interface{}{
"HostConfig": map[string]interface{}{
"NetworkMode": netName,
},
}
_, _, err := sockRequest("POST", "/containers/"+conName+"/start", config)
c.Assert(err, checker.IsNil)
c.Assert(waitRun(conName), checker.IsNil)
networks, err := inspectField(conName, "NetworkSettings.Networks")
c.Assert(err, checker.IsNil)
c.Assert(networks, checker.Contains, netName, check.Commentf(fmt.Sprintf("Should contain '%s' network", netName)))
c.Assert(networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network"))
}
func (s *DockerNetworkSuite) TestDockerNetworkDisconnectDefault(c *check.C) {
netWorkName1 := "test1"
netWorkName2 := "test2"
containerName := "foo"
dockerCmd(c, "network", "create", netWorkName1)
dockerCmd(c, "network", "create", netWorkName2)
dockerCmd(c, "create", "--name", containerName, "busybox", "top")
dockerCmd(c, "network", "connect", netWorkName1, containerName)
dockerCmd(c, "network", "connect", netWorkName2, containerName)
dockerCmd(c, "network", "disconnect", "bridge", containerName)
dockerCmd(c, "start", containerName)
c.Assert(waitRun(containerName), checker.IsNil)
networks, err := inspectField(containerName, "NetworkSettings.Networks")
c.Assert(err, checker.IsNil)
c.Assert(networks, checker.Contains, netWorkName1, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName1)))
c.Assert(networks, checker.Contains, netWorkName2, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName2)))
c.Assert(networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network"))
}