This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimizing volumepropverification_test
Rebased changes with Govindan checkin - PR # 1286
- Loading branch information
Showing
6 changed files
with
222 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.