|
@@ -3,18 +3,29 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "fmt"
|
|
"os/exec"
|
|
"os/exec"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
"github.com/go-check/check"
|
|
"github.com/go-check/check"
|
|
)
|
|
)
|
|
|
|
|
|
-func isSrvAvailable(c *check.C, sname string, name string) bool {
|
|
|
|
|
|
+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 {
|
|
runCmd := exec.Command(dockerBinary, "service", "ls")
|
|
runCmd := exec.Command(dockerBinary, "service", "ls")
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
lines := strings.Split(out, "\n")
|
|
lines := strings.Split(out, "\n")
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
|
|
if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
|
|
@@ -23,15 +34,15 @@ func isSrvAvailable(c *check.C, sname string, name string) bool {
|
|
}
|
|
}
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
-func isNwAvailable(c *check.C, name string) bool {
|
|
|
|
- runCmd := exec.Command(dockerBinary, "network", "ls")
|
|
|
|
|
|
+
|
|
|
|
+func isCntPresent(c *check.C, cname, sname, name string) bool {
|
|
|
|
+ runCmd := exec.Command(dockerBinary, "service", "ls", "--no-trunc")
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
lines := strings.Split(out, "\n")
|
|
lines := strings.Split(out, "\n")
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
- if strings.Contains(lines[i], name) {
|
|
|
|
|
|
+ fmt.Println(lines)
|
|
|
|
+ if strings.Contains(lines[i], name) && strings.Contains(lines[i], sname) && strings.Contains(lines[i], cname) {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -40,38 +51,36 @@ func isNwAvailable(c *check.C, name string) bool {
|
|
|
|
|
|
func (s *DockerSuite) TestDockerServiceCreateDelete(c *check.C) {
|
|
func (s *DockerSuite) TestDockerServiceCreateDelete(c *check.C) {
|
|
runCmd := exec.Command(dockerBinary, "network", "create", "test")
|
|
runCmd := exec.Command(dockerBinary, "network", "create", "test")
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
- if !isNwAvailable(c, "test") {
|
|
|
|
- c.Fatalf("Network test not found")
|
|
|
|
- }
|
|
|
|
|
|
+ _, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ assertNwIsAvailable(c, "test")
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "service", "publish", "s1.test")
|
|
runCmd = exec.Command(dockerBinary, "service", "publish", "s1.test")
|
|
- out, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
- if !isSrvAvailable(c, "s1", "test") {
|
|
|
|
- c.Fatalf("service s1.test not found")
|
|
|
|
- }
|
|
|
|
|
|
+ _, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ assertSrvIsAvailable(c, "s1", "test")
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "service", "unpublish", "s1.test")
|
|
runCmd = exec.Command(dockerBinary, "service", "unpublish", "s1.test")
|
|
- out, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
- if isSrvAvailable(c, "s1", "test") {
|
|
|
|
- c.Fatalf("service s1.test not removed")
|
|
|
|
- }
|
|
|
|
|
|
+ _, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ assertSrvNotAvailable(c, "s1", "test")
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "network", "rm", "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")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *DockerSuite) TestDockerPublishServiceFlag(c *check.C) {
|
|
|
|
+ // Run saying the container is the backend for the specified service on the specified network
|
|
|
|
+ runCmd := exec.Command(dockerBinary, "run", "-d", "--expose=23", "--publish-service", "telnet.production", "busybox", "top")
|
|
|
|
+ out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ cid := strings.TrimSpace(out)
|
|
|
|
+
|
|
|
|
+ // Verify container is attached in service ps o/p
|
|
|
|
+ assertSrvIsAvailable(c, "telnet", "production")
|
|
|
|
+ runCmd = exec.Command(dockerBinary, "rm", "-f", cid)
|
|
|
|
+ out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
}
|
|
}
|