2015-06-18 11:41:17 -04:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-15 01:31:09 -04:00
|
|
|
"fmt"
|
2015-06-18 11:41:17 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2015-06-15 01:31:09 -04:00
|
|
|
func assertSrvIsAvailable(c *check.C, sname, name string) {
|
|
|
|
if !isSrvPresent(c, sname, name) {
|
|
|
|
c.Fatalf("Service %s on network %s not found in service ls o/p", sname, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertSrvNotAvailable(c *check.C, sname, name string) {
|
|
|
|
if isSrvPresent(c, sname, name) {
|
|
|
|
c.Fatalf("Found service %s on network %s in service ls o/p", sname, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func isSrvPresent(c *check.C, sname, name string) bool {
|
2015-07-21 14:01:24 -04:00
|
|
|
out, _, _ := dockerCmdWithStdoutStderr(c, "service", "ls")
|
2015-06-18 11:41:17 -04:00
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
|
|
if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-06-15 01:31:09 -04:00
|
|
|
|
|
|
|
func isCntPresent(c *check.C, cname, sname, name string) bool {
|
2015-07-21 14:01:24 -04:00
|
|
|
out, _, _ := dockerCmdWithStdoutStderr(c, "service", "ls", "--no-trunc")
|
2015-06-18 11:41:17 -04:00
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
for i := 1; i < len(lines)-1; i++ {
|
2015-06-15 01:31:09 -04:00
|
|
|
fmt.Println(lines)
|
|
|
|
if strings.Contains(lines[i], name) && strings.Contains(lines[i], sname) && strings.Contains(lines[i], cname) {
|
2015-06-18 11:41:17 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestDockerServiceCreateDelete(c *check.C) {
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmdWithStdoutStderr(c, "network", "create", "test")
|
2015-06-15 01:31:09 -04:00
|
|
|
assertNwIsAvailable(c, "test")
|
2015-06-18 11:41:17 -04:00
|
|
|
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmdWithStdoutStderr(c, "service", "publish", "s1.test")
|
2015-06-15 01:31:09 -04:00
|
|
|
assertSrvIsAvailable(c, "s1", "test")
|
2015-06-18 11:41:17 -04:00
|
|
|
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmdWithStdoutStderr(c, "service", "unpublish", "s1.test")
|
2015-06-15 01:31:09 -04:00
|
|
|
assertSrvNotAvailable(c, "s1", "test")
|
2015-06-18 11:41:17 -04:00
|
|
|
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmdWithStdoutStderr(c, "network", "rm", "test")
|
2015-06-15 01:31:09 -04:00
|
|
|
assertNwNotAvailable(c, "test")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestDockerPublishServiceFlag(c *check.C) {
|
|
|
|
// Run saying the container is the backend for the specified service on the specified network
|
2015-07-21 14:01:24 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "--expose=23", "--publish-service", "telnet.production", "busybox", "top")
|
2015-06-15 01:31:09 -04:00
|
|
|
cid := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// Verify container is attached in service ps o/p
|
|
|
|
assertSrvIsAvailable(c, "telnet", "production")
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmd(c, "rm", "-f", cid)
|
2015-06-18 11:41:17 -04:00
|
|
|
}
|