Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Addressed all review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaomin Chen committed Jun 1, 2017
1 parent ba79e63 commit b9fe2b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
12 changes: 6 additions & 6 deletions tests/e2e/swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SwarmTestSuite struct {
master string
worker1 string
worker2 string
dockerHosts []string
swarmNodes []string
volumeName string
serviceName string
}
Expand All @@ -43,7 +43,7 @@ func (s *SwarmTestSuite) SetUpSuite(c *C) {
s.master = inputparams.GetSwarmManager1()
s.worker1 = inputparams.GetSwarmWorker1()
s.worker2 = inputparams.GetSwarmWorker2()
s.dockerHosts = []string{s.master, s.worker1, s.worker2}
s.swarmNodes = inputparams.GetSwarmNodes()

s.volumeName = inputparams.GetVolumeNameWithTimeStamp("swarm_test")
s.serviceName = inputparams.GetServiceNameWithTimeStamp("swarm_test")
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) {
status := verification.IsDockerServiceRunning(s.master, s.serviceName, 1)
c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName))

status, _ = verification.IsDockerContainerRunning(s.dockerHosts, s.serviceName, 1)
status, _ = verification.IsDockerContainerRunning(s.swarmNodes, s.serviceName, 1)
c.Assert(status, Equals, true, Commentf("Container %s is not running", s.serviceName))

status = verification.VerifyAttachedStatus(s.volumeName, s.master, s.esxName)
Expand All @@ -109,18 +109,18 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) {
status = verification.IsDockerServiceRunning(s.master, s.serviceName, 2)
c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName))

status, host := verification.IsDockerContainerRunning(s.dockerHosts, s.serviceName, 2)
status, host := verification.IsDockerContainerRunning(s.swarmNodes, s.serviceName, 2)
c.Assert(status, Equals, true, Commentf("Container %s is not running on any hosts", s.serviceName))

containerName, err = verification.GetContainerName(host, s.serviceName+".1")
containerName, err = dockercli.GetContainerName(host, s.serviceName+".1")
c.Assert(err, IsNil, Commentf("Failed to retrieve container name: %s", containerName))
out, err = dockercli.StopService(host, containerName)
c.Assert(err, IsNil, Commentf(out))

status = verification.IsDockerServiceRunning(s.master, s.serviceName, 2)
c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName))

status, _ = verification.IsDockerContainerRunning(s.dockerHosts, s.serviceName, 2)
status, _ = verification.IsDockerContainerRunning(s.swarmNodes, s.serviceName, 2)
c.Assert(status, Equals, true, Commentf("Container %s is not running", s.serviceName))

status = verification.VerifyAttachedStatus(s.volumeName, s.master, s.esxName)
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/dockercli/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ func RemoveService(ip, name string) (string, error) {
log.Printf("Removing docker service [%s] on VM [%s]\n", name, ip)
return ssh.InvokeCommand(ip, dockercli.RemoveService+name)
}

// GetContainerName returns full container name based on given short name
func GetContainerName(hostName, shortName string) (string, error) {
cmd := dockercli.ListContainers + "--filter name='" + shortName + "' --format '{{.Names}}'"
return ssh.InvokeCommand(hostName, cmd)
}

// GetAllContainers returns all running containers on the give host based on the filtering criteria
func GetAllContainers(hostName, filter string) (string, error) {
cmd := dockercli.ListContainers + "--filter name='" + filter + "' --format '{{.Names}}'"
return ssh.InvokeCommand(hostName, cmd)
}
5 changes: 5 additions & 0 deletions tests/utils/inputparams/testparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func GetSwarmWorker2() string {
return os.Getenv("WORKER2")
}

// GetSwarmNodes returns all nodes in the configured swarm cluster
func GetSwarmNodes() []string {
return []string{GetSwarmManager1(), GetSwarmWorker1(), GetSwarmWorker2()}
}

// GetDockerHostIP - returns ip of the VM where vm can be first vm (VM1) or second vm (VM2)
func GetDockerHostIP(vm string) string {
return os.Getenv(vm)
Expand Down
23 changes: 4 additions & 19 deletions tests/utils/verification/dockercontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,18 @@ package verification

import (
"log"
"strings"

"strconv"
"strings"

"github.com/vmware/docker-volume-vsphere/tests/constants/dockercli"
util "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/misc"
"github.com/vmware/docker-volume-vsphere/tests/utils/ssh"
)

// GetContainerName returns full container name based on given short name
func GetContainerName(hostName, shortName string) (string, error) {
cmd := dockercli.ListContainers + "--filter name='" + shortName + "' --format '{{.Names}}'"
return ssh.InvokeCommand(hostName, cmd)
}

// GetAllContainers returns all running containers on the give host based on the filtering criteria
func GetAllContainers(hostName, filter string) (string, error) {
cmd := dockercli.ListContainers + "--filter name='" + filter + "' --format '{{.Names}}'"
return ssh.InvokeCommand(hostName, cmd)
}

// IsDockerServiceRunning returns true if the given service is running on
// the specified VM with specified replicas; false otherwise.
func IsDockerServiceRunning(hostName, serviceName string, replicas int) bool {
log.Printf("Checking docker service [%s] status on VM [%s]\n", serviceName, hostName)
out, err := util.ListService(hostName, serviceName)
out, err := dockercli.ListService(hostName, serviceName)
if err != nil {
log.Println(err)
return false
Expand Down Expand Up @@ -78,7 +63,7 @@ func IsDockerContainerRunning(dockerHosts []string, serviceName string, replicas
// isContainerRunning returns true if all replicated containers are up and running; false otherwise.
func isContainerRunning(dockerHosts []string, serviceName string, replicas int) (bool, string) {
for _, host := range dockerHosts {
out, err := GetAllContainers(host, serviceName)
out, err := dockercli.GetAllContainers(host, serviceName)
if err != nil || out == "" {
continue
}
Expand Down

0 comments on commit b9fe2b8

Please sign in to comment.