mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Support for --publish-service flag in docker run
This commit makes use of the CNM model supported by LibNetwork and provides an ability to let a container to publish a specified service. Behind the scenes, if a service with the given name doesnt exist, it is automatically created on appropriate network and attach the container. Signed-off-by: Alessandro Boch <aboch@docker.com> Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
@@ -9,12 +9,22 @@ import (
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func isNetworkPresent(c *check.C, name string) bool {
|
||||
func assertNwIsAvailable(c *check.C, name string) {
|
||||
if !isNwPresent(c, name) {
|
||||
c.Fatalf("Network %s not found in network ls o/p", name)
|
||||
}
|
||||
}
|
||||
|
||||
func assertNwNotAvailable(c *check.C, name string) {
|
||||
if isNwPresent(c, name) {
|
||||
c.Fatalf("Found network %s in network ls o/p", name)
|
||||
}
|
||||
}
|
||||
|
||||
func isNwPresent(c *check.C, name string) bool {
|
||||
runCmd := exec.Command(dockerBinary, "network", "ls")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
lines := strings.Split(out, "\n")
|
||||
for i := 1; i < len(lines)-1; i++ {
|
||||
if strings.Contains(lines[i], name) {
|
||||
@@ -27,28 +37,18 @@ func isNetworkPresent(c *check.C, name string) bool {
|
||||
func (s *DockerSuite) TestDockerNetworkLsDefault(c *check.C) {
|
||||
defaults := []string{"bridge", "host", "none"}
|
||||
for _, nn := range defaults {
|
||||
if !isNetworkPresent(c, nn) {
|
||||
c.Fatalf("Missing Default network : %s", nn)
|
||||
}
|
||||
assertNwIsAvailable(c, nn)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestDockerNetworkCreateDelete(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "network", "create", "test")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
if !isNetworkPresent(c, "test") {
|
||||
c.Fatalf("Network test not found")
|
||||
}
|
||||
_, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
assertNwIsAvailable(c, "test")
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "network", "rm", "test")
|
||||
out, _, _, err = runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
if isNetworkPresent(c, "test") {
|
||||
c.Fatalf("Network test is not removed")
|
||||
}
|
||||
_, _, _, err = runCommandWithStdoutStderr(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
assertNwNotAvailable(c, "test")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user