From 08dbe29dd5afba0bcc2d06ef2d4694b73db4ed21 Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Tue, 30 May 2017 11:58:50 -0700 Subject: [PATCH 1/7] Add swarm_test to e2e test suite --- tests/constants/dockercli/cmd.go | 24 +++- tests/e2e/swarm_test.go | 140 +++++++++++++++++++ tests/utils/dockercli/swarm.go | 68 +++++++++ tests/utils/inputparams/testparams.go | 5 + tests/utils/ssh/ssh.go | 3 + tests/utils/verification/volumeproperties.go | 71 ++++++++++ 6 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/swarm_test.go create mode 100644 tests/utils/dockercli/swarm.go diff --git a/tests/constants/dockercli/cmd.go b/tests/constants/dockercli/cmd.go index d1e6cb0d2..30c13290b 100644 --- a/tests/constants/dockercli/cmd.go +++ b/tests/constants/dockercli/cmd.go @@ -17,8 +17,10 @@ package dockercli const ( - docker = "docker " - dockerVol = docker + "volume " + docker = "docker " + dockerVol = docker + "volume " + dockerNode = docker + "node " + dockerService = docker + "service " // ListVolumes to list down docker volumes ListVolumes = dockerVol + "ls " @@ -76,4 +78,22 @@ const ( // QueryContainer checks whether container exists or not QueryContainer = docker + "ps -aq --filter name=" + + // ListContainers list all running docker containers + ListContainers = docker + "ps " + + // ListNodes list all docker swarm nodes + ListNodes = dockerNode + "ls " + + // CreateService create a docker service + CreateService = dockerService + "create " + + // ScaleService scale a docker service + ScaleService = dockerService + "scale " + + // ListService list running docker services + ListService = dockerService + "ps " + + // RemoveService remove docker services + RemoveService = dockerService + "rm " ) diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go new file mode 100644 index 000000000..7254145d3 --- /dev/null +++ b/tests/e2e/swarm_test.go @@ -0,0 +1,140 @@ +// Copyright 2017 VMware, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This test suite includes test cases to verify basic vDVS functionality +// in docker swarm mode. + +package e2e + +import ( + "log" + + . "gopkg.in/check.v1" + + "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli" + "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams" + "github.com/vmware/docker-volume-vsphere/tests/utils/verification" +) + +type SwarmTestSuite struct { + esxName string + master string + worker1 string + worker2 string + dockerHosts []string + volumeName string + serviceName string +} + +func (s *SwarmTestSuite) SetUpTest(c *C) { + s.esxName = inputparams.GetEsxIP() + s.master = inputparams.GetSwarmManager1() + s.worker1 = inputparams.GetSwarmWorker1() + s.worker2 = inputparams.GetSwarmWorker2() + s.dockerHosts = []string{s.master, s.worker1, s.worker2} + + s.volumeName = inputparams.GetVolumeNameWithTimeStamp("swarm_test") + s.serviceName = inputparams.GetServiceNameWithTimeStamp("swarm_test") + + // Verify if swarm cluster is already initialized + out, err := dockercli.ListNodes(s.master) + c.Assert(err, IsNil, Commentf(out)) + + // Create the volume + out, err = dockercli.CreateVolume(s.master, s.volumeName) + c.Assert(err, IsNil, Commentf(out)) + + status := verification.VerifyDetachedStatus(s.volumeName, s.master, s.esxName) + c.Assert(status, Equals, true, Commentf("Volume %s is not detached", s.volumeName)) +} + +func (s *SwarmTestSuite) TearDownTest(c *C) { + // Clean up the volume + out, err := dockercli.DeleteVolume(s.master, s.volumeName) + c.Assert(err, IsNil, Commentf(out)) +} + +var _ = Suite(&SwarmTestSuite{}) + +// Test vDVS usage in swarm mode +// +// Test steps: +// 1. Create a docker service with replicas setting to 1 +// 2. Verify the service is up and running with one node +// 3. Verify one container is spawned +// 5. Verify the volume is in attached status +// 6. Scale the service to set replica numbers to 2 +// 7. Verify the service is up and running with two nodes +// 8. Verify 2 containers are spawned +// 9. Stop one node of the service +// 10. Verify the service is still running with two nodes +// 11. Verify there are still 2 containers up and running +// 12. Verify the volume is in attached status +// 13. Delete the volume - expect fail +// 14. Remove the service +// 15. Verify the service is gone +// 16. Verify the volume is in detached status +func (s *SwarmTestSuite) TestDockerSwarm(c *C) { + log.Printf("START: swarm_test.TestDockerSwarm") + + opts := "--replicas 1 --mount type=volume,source=" + s.volumeName + ",target=/vol,volume-driver=vsphere busybox tail -f /dev/null" + out, err := dockercli.CreateService(s.master, s.serviceName, opts) + c.Assert(err, IsNil, Commentf(out)) + + status := verification.VerifyDockerService(s.master, s.serviceName, 1) + c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) + + status = verification.VerifyDockerContainer(s.dockerHosts, 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) + c.Assert(status, Equals, true, Commentf("Volume %s is not attached", s.volumeName)) + + out, err = dockercli.ScaleService(s.master, s.serviceName, 2) + c.Assert(err, IsNil, Commentf(out)) + + status = verification.VerifyDockerService(s.master, s.serviceName, 2) + c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) + + status = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) + c.Assert(status, Equals, true, Commentf("Container %s is not running", s.serviceName)) + + containerName, err = verification.GetContainerName(s.master, s.serviceName+".1") + c.Assert(err, IsNil, Commentf(out)) + out, err = dockercli.StopService(s.master, containerName) + c.Assert(err, IsNil, Commentf(out)) + + status = verification.VerifyDockerService(s.master, s.serviceName, 2) + c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) + + status = verification.VerifyDockerContainer(s.dockerHosts, 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) + c.Assert(status, Equals, true, Commentf("Volume %s is not attached", s.volumeName)) + + out, err = dockercli.DeleteVolume(s.master, s.volumeName) + c.Assert(err, NotNil, Commentf("Expected error does not happen")) + + out, err = dockercli.RemoveService(s.master, s.serviceName) + c.Assert(err, IsNil, Commentf(out)) + + out, err = dockercli.ListService(s.master, s.serviceName) + c.Assert(err, NotNil, Commentf("Expected error does not happen")) + + status = verification.VerifyDetachedStatus(s.volumeName, s.master, s.esxName) + c.Assert(status, Equals, true, Commentf("Volume %s is still attached", s.volumeName)) + + log.Printf("END: swarm_test.TestDockerSwarm") +} diff --git a/tests/utils/dockercli/swarm.go b/tests/utils/dockercli/swarm.go new file mode 100644 index 000000000..fd187d572 --- /dev/null +++ b/tests/utils/dockercli/swarm.go @@ -0,0 +1,68 @@ +// Copyright 2017 VMware, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This util provides various helper functions for managing docker swarm cluster. + +package dockercli + +import ( + "log" + + "strconv" + + "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli" + "github.com/vmware/docker-volume-vsphere/tests/utils/ssh" +) + +// ListContainers returns all running docker containers +func ListContainers(ip string) (string, error) { + log.Printf("Listing all docker containers on VM [%s]\n", ip) + return ssh.InvokeCommand(ip, dockercli.ListContainers) +} + +// ListNodes returns all swarm cluster nodes from the swarm master +func ListNodes(ip string) (string, error) { + log.Printf("Listing swarm cluster nodes on VM [%s]\n", ip) + return ssh.InvokeCommand(ip, dockercli.ListNodes) +} + +// CreateService creates a docker service +func CreateService(ip, name, opts string) (string, error) { + log.Printf("Creating a docker service %s on VM [%s]\n", name, ip) + return ssh.InvokeCommand(ip, dockercli.CreateService+"--name "+name+" "+opts) +} + +// ListService lists the tasks of a docker service +func ListService(ip, name string) (string, error) { + log.Printf("Listing docker services running on VM [%s]\n", ip) + return ssh.InvokeCommand(ip, dockercli.ListService+name) +} + +// ScaleService scales one or multiple replicated services +func ScaleService(ip, name string, replicas int) (string, error) { + log.Printf("Scaling %d replicated services for %s on VM [%s]\n", replicas, name, ip) + return ssh.InvokeCommand(ip, dockercli.ScaleService+name+"="+strconv.Itoa(replicas)) +} + +// StopService stops a docker service +func StopService(ip, name string) (string, error) { + log.Printf("Stopping docker service %s on VM [%s]\n", name, ip) + return ssh.InvokeCommand(ip, dockercli.StopContainer+name) +} + +// RemoveService remove a docker service +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) +} diff --git a/tests/utils/inputparams/testparams.go b/tests/utils/inputparams/testparams.go index 8867eea82..6a1fdbc69 100644 --- a/tests/utils/inputparams/testparams.go +++ b/tests/utils/inputparams/testparams.go @@ -53,6 +53,11 @@ func GetContainerNameWithTimeStamp(containerName string) string { return containerName + "_container_" + strconv.FormatInt(time.Now().Unix(), 10) } +// GetServiceNameWithTimeStamp prepares unique service name by appending current time-stamp value +func GetServiceNameWithTimeStamp(serviceName string) string { + return serviceName + "_service_" + strconv.FormatInt(time.Now().Unix(), 10) +} + // GetEndPoint1 returns first VM endpoint supplied through CLI func GetEndPoint1() string { return endPoint1 diff --git a/tests/utils/ssh/ssh.go b/tests/utils/ssh/ssh.go index df5db7096..dea7dae48 100644 --- a/tests/utils/ssh/ssh.go +++ b/tests/utils/ssh/ssh.go @@ -32,6 +32,9 @@ var sshIdentity = []string{strings.Split(os.Getenv("SSH_KEY_OPT"), " ")[0], stri // cmd: A command string to be executed on the remote host as per func InvokeCommand(ip, cmd string) (string, error) { out, err := exec.Command("/usr/bin/ssh", append(sshIdentity, "root@"+ip, cmd)...).CombinedOutput() + if err != nil { + log.Printf("Failed to invoke command [%s]: %v", cmd, err) + } return strings.TrimSpace(string(out[:])), err } diff --git a/tests/utils/verification/volumeproperties.go b/tests/utils/verification/volumeproperties.go index 7160a5f57..b185f6749 100644 --- a/tests/utils/verification/volumeproperties.go +++ b/tests/utils/verification/volumeproperties.go @@ -22,9 +22,12 @@ import ( "log" "strings" + "strconv" + "github.com/vmware/docker-volume-vsphere/tests/constants/admincli" "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli" "github.com/vmware/docker-volume-vsphere/tests/constants/properties" + util "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" ) @@ -97,6 +100,74 @@ func GetVolumePropertiesDockerCli(volName string, hostname string) string { return op } +// 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) +} + +// VerifyDockerService returns true if the given service is running on +// the specified VM with specified replicas; false otherwise. +func VerifyDockerService(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) + if err != nil { + log.Println(err) + return false + } + + for i := 1; i <= replicas; i++ { + if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { + return false + } + } + return true +} + +// VerifyDockerContainer returns true if the containers are running on one of +// the given docker hosts with specified replicas; false otherwise. +func VerifyDockerContainer(dockerHosts []string, serviceName string, replicas int) bool { + log.Printf("Checking running containers for docker service [%s] on docker hosts: %v\n", serviceName, dockerHosts) + + //TODO: Need to implement generic polling logic for better reuse + for attempt := 0; attempt < maxAttempt; attempt++ { + if allContainersRunning(dockerHosts, serviceName, replicas) { + return true + } + misc.SleepForSec(5) + } + return false +} + +// allContainersRunning returns true if all replicated containers are up and running; false otherwise. +func allContainersRunning(dockerHosts []string, serviceName string, replicas int) bool { + //TODO: It looks like all containers will always be spawned on one node. If this assumption + //turns out to be false, then the logic below needs to be changed + for _, host := range dockerHosts { + out, err := GetAllContainers(host, serviceName) + if err != nil { + log.Println(err) + continue + } + if out != "" { + log.Printf("Containers running on docker host [%s]: %s\n", host, out) + for i := 1; i <= replicas; i++ { + if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { + return false + } + } + return true + } + } + return false +} + // CheckVolumeAvailability returns true if the given volume is available // from the specified VM; false otherwise. func CheckVolumeAvailability(hostName string, volumeName string) bool { From 4812c590ca483f5d147de75b04bd85075f6e0c0a Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Tue, 30 May 2017 17:21:59 -0700 Subject: [PATCH 2/7] Fixed 2 issues: 1. Using full volume name to create docker service 2. Add $WORKER2 to the build script --- tests/e2e/swarm_test.go | 3 ++- tests/utils/verification/volumeproperties.go | 17 +++++++++++++++++ vmdk_plugin/Makefile | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go index 7254145d3..0c61d574e 100644 --- a/tests/e2e/swarm_test.go +++ b/tests/e2e/swarm_test.go @@ -88,7 +88,8 @@ var _ = Suite(&SwarmTestSuite{}) func (s *SwarmTestSuite) TestDockerSwarm(c *C) { log.Printf("START: swarm_test.TestDockerSwarm") - opts := "--replicas 1 --mount type=volume,source=" + s.volumeName + ",target=/vol,volume-driver=vsphere busybox tail -f /dev/null" + fullVolumeName := verification.GetFullVolumeName(s.master, s.volumeName) + opts := "--replicas 1 --mount type=volume,source=" + fullVolumeName + ",target=/vol,volume-driver=vsphere busybox tail -f /dev/null" out, err := dockercli.CreateService(s.master, s.serviceName, opts) c.Assert(err, IsNil, Commentf(out)) diff --git a/tests/utils/verification/volumeproperties.go b/tests/utils/verification/volumeproperties.go index b185f6749..f0a16a773 100644 --- a/tests/utils/verification/volumeproperties.go +++ b/tests/utils/verification/volumeproperties.go @@ -181,6 +181,22 @@ func CheckVolumeAvailability(hostName string, volumeName string) bool { return strings.Contains(volumes, volumeName) } +// GetFullVolumeName returns full volume name from the specified VM; return +// original short name if any error happens +func GetFullVolumeName(hostName string, volumeName string) string { + log.Printf("Fetching full name for volume [%s] from VM [%s]\n", volumeName, hostName) + + cmd := dockercli.ListVolumes + "--filter name='" + volumeName + "' --format '{{.Name}}'" + fullName, err := ssh.InvokeCommand(hostName, cmd) + if err != nil { + log.Println(err) + return volumeName + } + + log.Printf("Full volume name: [%s]\n", fullName) + return fullName +} + // VerifyAttachedStatus - verify volume is attached and name of the VM attached // is consistent on both docker host and ESX func VerifyAttachedStatus(name, hostName, esxName string) bool { @@ -215,6 +231,7 @@ func getVolumeStatusHost(name, hostName string) string { // VerifyDetachedStatus - check if the status gets detached within the timeout func VerifyDetachedStatus(name, hostName, esxName string) bool { log.Printf("Confirming detached status for volume [%s]\n", name) + for attempt := 0; attempt < maxAttempt; attempt++ { misc.SleepForSec(2) status := getVolumeStatusHost(name, hostName) diff --git a/vmdk_plugin/Makefile b/vmdk_plugin/Makefile index 67d754576..0a321f6c5 100644 --- a/vmdk_plugin/Makefile +++ b/vmdk_plugin/Makefile @@ -287,7 +287,7 @@ CLEANESX_SH := $(DEPLOY_TOOLS) cleanesx deploy-esx: clean-esx $(DEPLOY_ESX_SH) "$(ESX)" "$(VIB_BIN)" -VMS= $(VM1) $(VM2) +VMS= $(VM1) $(VM2) $(WORKER2) deploy-vm: clean-vm $(DEPLOY_VM_SH) "$(VMS)" $(PLUGIN_NAME):$(PLUGIN_TAG) From e7c8e21372fa89ad990aa5739ba6023b07cae27c Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Wed, 31 May 2017 12:01:12 -0700 Subject: [PATCH 3/7] Improve some logs for better debugging --- tests/e2e/swarm_test.go | 2 +- tests/utils/dockercli/swarm.go | 8 ++++---- vmdk_plugin/Makefile | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go index 0c61d574e..b754038d0 100644 --- a/tests/e2e/swarm_test.go +++ b/tests/e2e/swarm_test.go @@ -112,7 +112,7 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { c.Assert(status, Equals, true, Commentf("Container %s is not running", s.serviceName)) containerName, err = verification.GetContainerName(s.master, s.serviceName+".1") - c.Assert(err, IsNil, Commentf(out)) + c.Assert(err, IsNil, Commentf("Failed to retrieve container name: %s", containerName)) out, err = dockercli.StopService(s.master, containerName) c.Assert(err, IsNil, Commentf(out)) diff --git a/tests/utils/dockercli/swarm.go b/tests/utils/dockercli/swarm.go index fd187d572..bfa2f387d 100644 --- a/tests/utils/dockercli/swarm.go +++ b/tests/utils/dockercli/swarm.go @@ -39,7 +39,7 @@ func ListNodes(ip string) (string, error) { // CreateService creates a docker service func CreateService(ip, name, opts string) (string, error) { - log.Printf("Creating a docker service %s on VM [%s]\n", name, ip) + log.Printf("Creating a docker service [%s] on VM [%s]\n", name, ip) return ssh.InvokeCommand(ip, dockercli.CreateService+"--name "+name+" "+opts) } @@ -51,18 +51,18 @@ func ListService(ip, name string) (string, error) { // ScaleService scales one or multiple replicated services func ScaleService(ip, name string, replicas int) (string, error) { - log.Printf("Scaling %d replicated services for %s on VM [%s]\n", replicas, name, ip) + log.Printf("Scaling %d replicated services for [%s] on VM [%s]\n", replicas, name, ip) return ssh.InvokeCommand(ip, dockercli.ScaleService+name+"="+strconv.Itoa(replicas)) } // StopService stops a docker service func StopService(ip, name string) (string, error) { - log.Printf("Stopping docker service %s on VM [%s]\n", name, ip) + log.Printf("Stopping docker service [%s] on VM [%s]\n", name, ip) return ssh.InvokeCommand(ip, dockercli.StopContainer+name) } // RemoveService remove a docker service func RemoveService(ip, name string) (string, error) { - log.Printf("Removing docker service %s on VM [%s]\n", name, ip) + log.Printf("Removing docker service [%s] on VM [%s]\n", name, ip) return ssh.InvokeCommand(ip, dockercli.RemoveService+name) } diff --git a/vmdk_plugin/Makefile b/vmdk_plugin/Makefile index 0a321f6c5..67d754576 100644 --- a/vmdk_plugin/Makefile +++ b/vmdk_plugin/Makefile @@ -287,7 +287,7 @@ CLEANESX_SH := $(DEPLOY_TOOLS) cleanesx deploy-esx: clean-esx $(DEPLOY_ESX_SH) "$(ESX)" "$(VIB_BIN)" -VMS= $(VM1) $(VM2) $(WORKER2) +VMS= $(VM1) $(VM2) deploy-vm: clean-vm $(DEPLOY_VM_SH) "$(VMS)" $(PLUGIN_NAME):$(PLUGIN_TAG) From 57ef829b94661a4777ffa19fccdd7a567257ecb7 Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Wed, 31 May 2017 15:34:57 -0700 Subject: [PATCH 4/7] Improved test logic to handle the case where the containers might be spawned on different nodes in Docker Swarm cluster --- tests/e2e/swarm_test.go | 12 +++++------ tests/utils/verification/volumeproperties.go | 21 ++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go index b754038d0..7ed405034 100644 --- a/tests/e2e/swarm_test.go +++ b/tests/e2e/swarm_test.go @@ -96,7 +96,7 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { status := verification.VerifyDockerService(s.master, s.serviceName, 1) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 1) + status, _ = verification.VerifyDockerContainer(s.dockerHosts, 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) @@ -108,18 +108,18 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { status = verification.VerifyDockerService(s.master, s.serviceName, 2) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) - c.Assert(status, Equals, true, Commentf("Container %s is not running", s.serviceName)) + status, host := verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) + c.Assert(status, Equals, true, Commentf("Container %s is not running on any hosts", s.serviceName)) - containerName, err = verification.GetContainerName(s.master, s.serviceName+".1") + containerName, err = verification.GetContainerName(host, s.serviceName+".1") c.Assert(err, IsNil, Commentf("Failed to retrieve container name: %s", containerName)) - out, err = dockercli.StopService(s.master, containerName) + out, err = dockercli.StopService(host, containerName) c.Assert(err, IsNil, Commentf(out)) status = verification.VerifyDockerService(s.master, s.serviceName, 2) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) + status, _ = verification.VerifyDockerContainer(s.dockerHosts, 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) diff --git a/tests/utils/verification/volumeproperties.go b/tests/utils/verification/volumeproperties.go index f0a16a773..f220be164 100644 --- a/tests/utils/verification/volumeproperties.go +++ b/tests/utils/verification/volumeproperties.go @@ -130,23 +130,24 @@ func VerifyDockerService(hostName, serviceName string, replicas int) bool { return true } -// VerifyDockerContainer returns true if the containers are running on one of -// the given docker hosts with specified replicas; false otherwise. -func VerifyDockerContainer(dockerHosts []string, serviceName string, replicas int) bool { +// VerifyDockerContainer returns true and the host IP if the containers are running on one of +// the given docker hosts with specified replicas; otherwise returns false and empty string. +func VerifyDockerContainer(dockerHosts []string, serviceName string, replicas int) (bool, string) { log.Printf("Checking running containers for docker service [%s] on docker hosts: %v\n", serviceName, dockerHosts) //TODO: Need to implement generic polling logic for better reuse for attempt := 0; attempt < maxAttempt; attempt++ { - if allContainersRunning(dockerHosts, serviceName, replicas) { - return true + status, host := allContainersRunning(dockerHosts, serviceName, replicas) + if status { + return status, host } misc.SleepForSec(5) } - return false + return false, "" } // allContainersRunning returns true if all replicated containers are up and running; false otherwise. -func allContainersRunning(dockerHosts []string, serviceName string, replicas int) bool { +func allContainersRunning(dockerHosts []string, serviceName string, replicas int) (bool, string) { //TODO: It looks like all containers will always be spawned on one node. If this assumption //turns out to be false, then the logic below needs to be changed for _, host := range dockerHosts { @@ -159,13 +160,13 @@ func allContainersRunning(dockerHosts []string, serviceName string, replicas int log.Printf("Containers running on docker host [%s]: %s\n", host, out) for i := 1; i <= replicas; i++ { if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { - return false + return false, "" } } - return true + return true, host } } - return false + return false, "" } // CheckVolumeAvailability returns true if the given volume is available From e1017c755f02fdab1ae85611072ec6797244c151 Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Wed, 31 May 2017 19:00:53 -0700 Subject: [PATCH 5/7] Increase e2e timeout to 30 minutes --- vmdk_plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmdk_plugin/Makefile b/vmdk_plugin/Makefile index 67d754576..eea055bea 100644 --- a/vmdk_plugin/Makefile +++ b/vmdk_plugin/Makefile @@ -355,7 +355,7 @@ e2e-test: .PHONY: e2e-dkrVolDriver-test e2e-dkrVolDriver-test: $(log_target) - $(GO) test $(E2E_Tests) -v + $(GO) test $(E2E_Tests) -v -timeout 30m MANAGED_PLUGIN_NAME="vsphere:latest" From d59c264006eb4fc335c61e248414cb4c7ca57742 Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Thu, 1 Jun 2017 12:05:10 -0700 Subject: [PATCH 6/7] Addressed review comments --- tests/constants/dockercli/cmd.go | 16 ++-- tests/e2e/swarm_test.go | 19 ++-- tests/utils/dockercli/swarm.go | 3 +- tests/utils/verification/dockercontainer.go | 95 ++++++++++++++++++++ tests/utils/verification/volumeproperties.go | 80 +---------------- 5 files changed, 116 insertions(+), 97 deletions(-) create mode 100644 tests/utils/verification/dockercontainer.go diff --git a/tests/constants/dockercli/cmd.go b/tests/constants/dockercli/cmd.go index 30c13290b..86e905ed5 100644 --- a/tests/constants/dockercli/cmd.go +++ b/tests/constants/dockercli/cmd.go @@ -40,17 +40,17 @@ const ( // StartDocker - manually start docker StartDocker = "systemctl start docker" - // vDVSPluginName name of vDVS plugin - vDVSPluginName = "vsphere " + // VDVSPluginName name of vDVS plugin + VDVSPluginName = "vsphere " - // vDVS service name - vDVSName = "docker-volume-vsphere" + // VDVSName name of the vDVS service + VDVSName = "docker-volume-vsphere" // GetVDVSPlugin gets vDVS plugin info - GetVDVSPlugin = docker + "plugin list --no-trunc | grep " + vDVSPluginName + GetVDVSPlugin = docker + "plugin list --no-trunc | grep " + VDVSPluginName - // GetVDVSPID Get the process id of vDVS plugin - GetVDVSPID = "pidof " + vDVSName + // GetVDVSPID get the process id of vDVS plugin + GetVDVSPID = "pidof " + VDVSName // GetDockerPID get docker pid GetDockerPID = "pidof dockerd" @@ -59,7 +59,7 @@ const ( KillVDVSPlugin = "docker-runc kill " // StartVDVSPlugin starts the vDVS plugin - StartVDVSPlugin = docker + " plugin enable " + vDVSPluginName + StartVDVSPlugin = docker + " plugin enable " + VDVSPluginName // RunContainer create and run a container RunContainer = docker + "run " diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go index 7ed405034..1e6e7dacf 100644 --- a/tests/e2e/swarm_test.go +++ b/tests/e2e/swarm_test.go @@ -22,6 +22,7 @@ import ( . "gopkg.in/check.v1" + constant "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli" "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli" "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams" "github.com/vmware/docker-volume-vsphere/tests/utils/verification" @@ -37,7 +38,7 @@ type SwarmTestSuite struct { serviceName string } -func (s *SwarmTestSuite) SetUpTest(c *C) { +func (s *SwarmTestSuite) SetUpSuite(c *C) { s.esxName = inputparams.GetEsxIP() s.master = inputparams.GetSwarmManager1() s.worker1 = inputparams.GetSwarmWorker1() @@ -59,7 +60,7 @@ func (s *SwarmTestSuite) SetUpTest(c *C) { c.Assert(status, Equals, true, Commentf("Volume %s is not detached", s.volumeName)) } -func (s *SwarmTestSuite) TearDownTest(c *C) { +func (s *SwarmTestSuite) TearDownSuite(c *C) { // Clean up the volume out, err := dockercli.DeleteVolume(s.master, s.volumeName) c.Assert(err, IsNil, Commentf(out)) @@ -89,14 +90,14 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { log.Printf("START: swarm_test.TestDockerSwarm") fullVolumeName := verification.GetFullVolumeName(s.master, s.volumeName) - opts := "--replicas 1 --mount type=volume,source=" + fullVolumeName + ",target=/vol,volume-driver=vsphere busybox tail -f /dev/null" + opts := "--replicas 1 --mount type=volume,source=" + fullVolumeName + ",target=/vol,volume-driver=" + constant.VDVSPluginName + constant.TestContainer out, err := dockercli.CreateService(s.master, s.serviceName, opts) c.Assert(err, IsNil, Commentf(out)) - status := verification.VerifyDockerService(s.master, s.serviceName, 1) + status := verification.IsDockerServiceRunning(s.master, s.serviceName, 1) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status, _ = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 1) + status, _ = verification.IsDockerContainerRunning(s.dockerHosts, 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) @@ -105,10 +106,10 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { out, err = dockercli.ScaleService(s.master, s.serviceName, 2) c.Assert(err, IsNil, Commentf(out)) - status = verification.VerifyDockerService(s.master, s.serviceName, 2) + status = verification.IsDockerServiceRunning(s.master, s.serviceName, 2) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status, host := verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) + status, host := verification.IsDockerContainerRunning(s.dockerHosts, 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") @@ -116,10 +117,10 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) { out, err = dockercli.StopService(host, containerName) c.Assert(err, IsNil, Commentf(out)) - status = verification.VerifyDockerService(s.master, s.serviceName, 2) + status = verification.IsDockerServiceRunning(s.master, s.serviceName, 2) c.Assert(status, Equals, true, Commentf("Service %s is not running", s.serviceName)) - status, _ = verification.VerifyDockerContainer(s.dockerHosts, s.serviceName, 2) + status, _ = verification.IsDockerContainerRunning(s.dockerHosts, 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) diff --git a/tests/utils/dockercli/swarm.go b/tests/utils/dockercli/swarm.go index bfa2f387d..e19c84391 100644 --- a/tests/utils/dockercli/swarm.go +++ b/tests/utils/dockercli/swarm.go @@ -18,7 +18,6 @@ package dockercli import ( "log" - "strconv" "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli" @@ -45,7 +44,7 @@ func CreateService(ip, name, opts string) (string, error) { // ListService lists the tasks of a docker service func ListService(ip, name string) (string, error) { - log.Printf("Listing docker services running on VM [%s]\n", ip) + log.Printf("Listing docker service [%s] running on VM [%s]\n", name, ip) return ssh.InvokeCommand(ip, dockercli.ListService+name) } diff --git a/tests/utils/verification/dockercontainer.go b/tests/utils/verification/dockercontainer.go new file mode 100644 index 000000000..eeff51010 --- /dev/null +++ b/tests/utils/verification/dockercontainer.go @@ -0,0 +1,95 @@ +// Copyright 2017 VMware, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This util provides various helper methods that can be used by different tests to +// fetch information related to docker service and containers. + +package verification + +import ( + "log" + "strings" + + "strconv" + + "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/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) + if err != nil { + log.Println(err) + return false + } + + for i := 1; i <= replicas; i++ { + if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { + return false + } + } + return true +} + +// IsDockerContainerRunning returns true and the host IP if the containers are running on one of +// the given docker hosts with specified replicas; otherwise returns false and empty string. +func IsDockerContainerRunning(dockerHosts []string, serviceName string, replicas int) (bool, string) { + log.Printf("Checking running containers for docker service [%s] on docker hosts: %v\n", serviceName, dockerHosts) + + //TODO: Need to implement generic polling logic for better reuse + for attempt := 0; attempt < 30; attempt++ { + status, host := isContainerRunning(dockerHosts, serviceName, replicas) + if status { + return status, host + } + misc.SleepForSec(5) + } + return false, "" +} + +// 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) + if err != nil || out == "" { + continue + } + + log.Printf("Containers running on docker host [%s]: %s\n", host, out) + for i := 1; i <= replicas; i++ { + if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { + return false, "" + } + } + return true, host + } + return false, "" +} diff --git a/tests/utils/verification/volumeproperties.go b/tests/utils/verification/volumeproperties.go index f220be164..adcfe930f 100644 --- a/tests/utils/verification/volumeproperties.go +++ b/tests/utils/verification/volumeproperties.go @@ -22,20 +22,13 @@ import ( "log" "strings" - "strconv" - "github.com/vmware/docker-volume-vsphere/tests/constants/admincli" "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli" "github.com/vmware/docker-volume-vsphere/tests/constants/properties" - util "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" ) -const ( - maxAttempt = 30 -) - // GetVMAttachedToVolUsingDockerCli returns attached to vm field of volume using docker cli // TODO: make this private member after finishing refactoring of volmprop_test.go and remove this TODO func GetVMAttachedToVolUsingDockerCli(volName string, hostname string) string { @@ -100,75 +93,6 @@ func GetVolumePropertiesDockerCli(volName string, hostname string) string { return op } -// 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) -} - -// VerifyDockerService returns true if the given service is running on -// the specified VM with specified replicas; false otherwise. -func VerifyDockerService(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) - if err != nil { - log.Println(err) - return false - } - - for i := 1; i <= replicas; i++ { - if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { - return false - } - } - return true -} - -// VerifyDockerContainer returns true and the host IP if the containers are running on one of -// the given docker hosts with specified replicas; otherwise returns false and empty string. -func VerifyDockerContainer(dockerHosts []string, serviceName string, replicas int) (bool, string) { - log.Printf("Checking running containers for docker service [%s] on docker hosts: %v\n", serviceName, dockerHosts) - - //TODO: Need to implement generic polling logic for better reuse - for attempt := 0; attempt < maxAttempt; attempt++ { - status, host := allContainersRunning(dockerHosts, serviceName, replicas) - if status { - return status, host - } - misc.SleepForSec(5) - } - return false, "" -} - -// allContainersRunning returns true if all replicated containers are up and running; false otherwise. -func allContainersRunning(dockerHosts []string, serviceName string, replicas int) (bool, string) { - //TODO: It looks like all containers will always be spawned on one node. If this assumption - //turns out to be false, then the logic below needs to be changed - for _, host := range dockerHosts { - out, err := GetAllContainers(host, serviceName) - if err != nil { - log.Println(err) - continue - } - if out != "" { - log.Printf("Containers running on docker host [%s]: %s\n", host, out) - for i := 1; i <= replicas; i++ { - if !strings.Contains(out, serviceName+"."+strconv.Itoa(i)) { - return false, "" - } - } - return true, host - } - } - return false, "" -} - // CheckVolumeAvailability returns true if the given volume is available // from the specified VM; false otherwise. func CheckVolumeAvailability(hostName string, volumeName string) bool { @@ -190,7 +114,6 @@ func GetFullVolumeName(hostName string, volumeName string) string { cmd := dockercli.ListVolumes + "--filter name='" + volumeName + "' --format '{{.Name}}'" fullName, err := ssh.InvokeCommand(hostName, cmd) if err != nil { - log.Println(err) return volumeName } @@ -233,7 +156,8 @@ func getVolumeStatusHost(name, hostName string) string { func VerifyDetachedStatus(name, hostName, esxName string) bool { log.Printf("Confirming detached status for volume [%s]\n", name) - for attempt := 0; attempt < maxAttempt; attempt++ { + //TODO: Need to implement generic polling logic for better reuse + for attempt := 0; attempt < 30; attempt++ { misc.SleepForSec(2) status := getVolumeStatusHost(name, hostName) if status != properties.DetachedStatus { From 50d4bbb6060ede899b1c00f53978e61cad9bb005 Mon Sep 17 00:00:00 2001 From: Shaomin Chen Date: Thu, 1 Jun 2017 15:13:57 -0700 Subject: [PATCH 7/7] Addressed all review comments. --- tests/e2e/swarm_test.go | 12 +++++------ tests/utils/dockercli/swarm.go | 12 +++++++++++ tests/utils/inputparams/testparams.go | 5 +++++ tests/utils/verification/dockercontainer.go | 23 ++++----------------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/e2e/swarm_test.go b/tests/e2e/swarm_test.go index 1e6e7dacf..74fff0853 100644 --- a/tests/e2e/swarm_test.go +++ b/tests/e2e/swarm_test.go @@ -33,7 +33,7 @@ type SwarmTestSuite struct { master string worker1 string worker2 string - dockerHosts []string + swarmNodes []string volumeName string serviceName string } @@ -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") @@ -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) @@ -109,10 +109,10 @@ 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)) @@ -120,7 +120,7 @@ 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, _ = 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) diff --git a/tests/utils/dockercli/swarm.go b/tests/utils/dockercli/swarm.go index e19c84391..c38b13390 100644 --- a/tests/utils/dockercli/swarm.go +++ b/tests/utils/dockercli/swarm.go @@ -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) +} diff --git a/tests/utils/inputparams/testparams.go b/tests/utils/inputparams/testparams.go index 6a1fdbc69..ad90a6470 100644 --- a/tests/utils/inputparams/testparams.go +++ b/tests/utils/inputparams/testparams.go @@ -83,6 +83,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) diff --git a/tests/utils/verification/dockercontainer.go b/tests/utils/verification/dockercontainer.go index eeff51010..f121f4e15 100644 --- a/tests/utils/verification/dockercontainer.go +++ b/tests/utils/verification/dockercontainer.go @@ -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 @@ -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 }