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

Commit

Permalink
Optimizing volumepropverification_test
Browse files Browse the repository at this point in the history
Rebased changes with Govindan checkin - PR # 1286
  • Loading branch information
ashahi1 committed Jun 6, 2017
1 parent 392c77e commit 42d6fdb
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 174 deletions.
8 changes: 7 additions & 1 deletion tests/constants/dockercli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
// CreateVolume create a volume with vsphere driver
CreateVolume = dockerVol + " create --driver=vsphere "

// RemoveVolume constant refers delete volume command
// RemoveVolume delete volume command
RemoveVolume = dockerVol + "rm "

// KillDocker kill docker
Expand Down Expand Up @@ -99,4 +99,10 @@ const (

// RemoveService remove docker services
RemoveService = dockerService + "rm "

// StopAllContainers stopping all the containers
StopAllContainers = docker + "kill $(docker ps -aq)"

// RemoveAllContainers removing all the containers forcefully
RemoveAllContainers = docker + "rm $(docker ps -aq) -f"
)
2 changes: 1 addition & 1 deletion tests/e2e/swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *SwarmTestSuite) TestDockerSwarm(c *C) {
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 = dockercli.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))
Expand Down
176 changes: 176 additions & 0 deletions tests/e2e/volumeproperty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// 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 is an end-to-end test. Test creates volumes of different format-types
// and verifies their properties from ESX as well as docker host.
// Properties being verified - capacity, disk-format and vm-attached field.

// Test assumes that SSH cert has been setup to enable password-less login to VM and ESX.

package e2e

import (
"log"
"reflect"
"strings"

dockerconst "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/ssh"
"github.com/vmware/docker-volume-vsphere/tests/utils/verification"
. "gopkg.in/check.v1"
)

const (
testName = "volumeproperty"
diskStatusDetached = "detached"
size = "100MB"
diskFormatOption = " -o diskformat="
)

type VolumePropertyTestSuite struct {
volumeNames []string
containerName string
formatTypes []string
dockerVolumeRemoveCmd string
volumeAttached bool
config *inputparams.TestConfig
}

func (s *VolumePropertyTestSuite) SetUpTest(c *C) {
s.config = inputparams.GetTestConfig()
if s.config == nil {
c.Skip("Unable to retrieve test config, skipping volumeproperty_test.TestVolumeProperties.")
}
s.containerName = inputparams.GetContainerNameWithTimeStamp(testName)
s.formatTypes = []string{"thin", "zeroedthick", "eagerzeroedthick"}
s.dockerVolumeRemoveCmd = dockerconst.RemoveVolume
log.Println(" SETUP Finished: volumeproperty_test.TestVolumeProperties")
}

// TearDownTest - Removes all the containers and deletes the volumes
func (s *VolumePropertyTestSuite) TearDownTest(c *C) {
out, err := dockercli.RemoveAllContainers(s.config.DockerHosts[1])
c.Assert(err, IsNil, Commentf(out))
s.dockerVolumeRemoveCmd = s.dockerVolumeRemoveCmd + strings.Join(s.volumeNames, " ")
out, err = ssh.InvokeCommand(s.config.DockerHosts[1], s.dockerVolumeRemoveCmd)
c.Assert(err, IsNil, Commentf(out))
log.Println(" CLEAN-UP Finished: volumeproperty_test.TestVolumeProperties")
}

var _ = Suite(&VolumePropertyTestSuite{})
var dockerCliMap = make(map[string][]string)
var adminCliMap = make(map[string][]string)
var expectedValues = make(map[string][]string)

/*
Test steps:
1. SSH to a vm and create volumes of size 100 mb and specified disk format ["thin", "zeroedthick", "eagerzeroedthick"]
2. Do docker inspect on the volume get size, disk format and attached-to-vm field.
Expected value: {"100MB", "thin/zeroedthick/eagerzeroedthick", no-value} respectively.
3. SSH to the esx and get capacity, disk format and attached-to-vm field for the volume using Admin cli
Expected value: {"100MB", "thin/zeroedthick/eagerzeroedthick", "detached"} respectively.
4. Verifies values obtained from admin cli and docker cli.
5. SSH to the vm and run a container and mount the volume created.
6. SSH to the vm and esx and verify the attached-to-vm field for volume - both docker cli and admin cli values should be same.
7. Again verify capacity and disk format using docker cli and admin cli to make sure things are fine after running the container.
NOTE: Do steps 5 ,6 and 7 only for volume of 'thin' disk format
*/

func (s *VolumePropertyTestSuite) TestVolumeProperties(c *C) {
log.Printf("START: volumeproperty_test.TestVolumeProperties")

// create volumes of all three disk formats
s.createVolumes(c)

// get properties for all three volumes from ESX and docker host
s.getVolumeProperties(c)

// Verify if docker and ESX properties of all three volumes are same and as expected.
s.verifyProperties(c)

// attach only thin volume
out, err := dockercli.AttachVolume(s.config.DockerHosts[1], s.volumeNames[0], s.containerName)
c.Assert(err, IsNil, Commentf("Failed to attach the volume [%s]", out))
s.volumeAttached = true

// Get volumes properties for the thin volume from docker and ESX.
s.getVolumePropertiesAdminCli(c, s.volumeNames[0])
s.getVolumePropertiesDockerCli(c, s.volumeNames[0])

// Verify if docker and ESX properties of volumes are same and as expected.
s.verifyProperties(c)

log.Printf("END: volumeproperty_test.TestVolumeProperties")
}

// createVolumes - creates volumes of each format type
func (s *VolumePropertyTestSuite) createVolumes(c *C) {
for _, formatType := range s.formatTypes {
vname := inputparams.GetVolumeNameWithTimeStamp(formatType)
out, err := dockercli.CreateVolumeWithOptions(s.config.DockerHosts[1], vname, diskFormatOption+formatType)
s.volumeNames = append(s.volumeNames, vname)
c.Assert(err, IsNil, Commentf(out))
}
}

// getVolumeProperties - get properties of three volumes from ESX and docker host
func (s *VolumePropertyTestSuite) getVolumeProperties(c *C) {
// get properties for all three volumes from ESX
for _, volumeName := range s.volumeNames {
s.getVolumePropertiesAdminCli(c, volumeName)
}
// get properties for all three volumes from docker host
for _, volumeName := range s.volumeNames {
s.getVolumePropertiesDockerCli(c, volumeName)
}
}

// getVolumePropertiesAdminCli - get properties of a volume from ESX
func (s *VolumePropertyTestSuite) getVolumePropertiesAdminCli(c *C, volumeName string) {
admincliValues := verification.GetVolumePropertiesAdminCli(volumeName, s.config.EsxHost)
c.Assert(admincliValues, HasLen, 3)
adminCliMap[volumeName] = []string{admincliValues[0], admincliValues[1], admincliValues[2]}
}

// getVolumePropertiesDockerCli - gets properties of a volume from the docker host
func (s *VolumePropertyTestSuite) getVolumePropertiesDockerCli(c *C, volumeName string) {
out, _ := verification.GetVolumePropertiesDockerCli(volumeName, s.config.DockerHosts[1])
dockerCliValues := strings.Fields(out)
dockerCliMap[volumeName] = []string{dockerCliValues[0], dockerCliValues[1], dockerCliValues[2]}
}

// verifyProperties - Verify docker and ESX properties of all three volumes are same and as expected.
func (s *VolumePropertyTestSuite) verifyProperties(c *C) {
log.Println("Verify docker and ESX properties of all three volumes are same")
status := reflect.DeepEqual(dockerCliMap, adminCliMap)
c.Assert(status, Equals, true, Commentf("Admin cli: %s . Docker Cli: %s . ESX and docker properties of volumes are not same.", adminCliMap, dockerCliMap))

// Only for volume with 'thin' format type, after s.volumeAttached=true, modify attached-to-vm field with vm name.
if !s.volumeAttached {
for i, volumeName := range s.volumeNames {
expectedValues[volumeName] = []string{size, s.formatTypes[i], diskStatusDetached}
}
} else {
tmp := expectedValues[s.volumeNames[0]]
tmp[2] = s.config.DockerHostNames[1]
expectedValues[s.volumeNames[0]] = tmp
}

// Verify ESX properties of all three volumes are as expected.
status = reflect.DeepEqual(expectedValues, adminCliMap)
c.Assert(status, Equals, true, Commentf("Admin cli: %s . Expected values: %s . ESX properties and expected property values of volumes are not same", adminCliMap, expectedValues))
}
141 changes: 0 additions & 141 deletions tests/e2e/volumepropverification_test.go

This file was deleted.

12 changes: 12 additions & 0 deletions tests/utils/dockercli/volumelifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,15 @@ func IsContainerExist(ip, containerName string) bool {
}
return false
}

// StopAllContainers - stops all the containers on a particular vm
func StopAllContainers(ip string) (string, error) {
log.Printf("Stopping all containers on VM [%s]\n", ip)
return ssh.InvokeCommand(ip, dockercli.StopAllContainers)
}

// RemoveAllContainers - removes all the containers on a particular vm
func RemoveAllContainers(ip string) (string, error) {
log.Printf("Removing all containers on VM [%s]\n", ip)
return ssh.InvokeCommand(ip, dockercli.RemoveAllContainers)
}
Loading

0 comments on commit 42d6fdb

Please sign in to comment.