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

Commit

Permalink
Test to delete vm grom vm vmgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahi1 committed Jun 28, 2017
1 parent 45b44f4 commit 03791aa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
9 changes: 9 additions & 0 deletions tests/constants/esx/govc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ const (

// PowerOnVM refers to govc cli (power on vm)
PowerOnVM = govcCmd + "vm.power -on=true "

// VMCreate refers to govc create vm
VMCreate = govcCmd + "vm.create -ds="

// VMDestroy refers to govc destroy vm
VMDestroy = govcCmd + "vm.destroy "

// ListVMs refers to govc vm ls
ListVMs = govcCmd + "ls "
)
43 changes: 42 additions & 1 deletion tests/e2e/vmgroupmisc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

// This test suite contains miscellaneous tests to verify behavior of non-default vmgroup

// +build unstable
// +build runonce

package e2e

import (
admincliconst "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/esx"
"github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
"github.com/vmware/docker-volume-vsphere/tests/utils/misc"
"github.com/vmware/docker-volume-vsphere/tests/utils/verification"
Expand Down Expand Up @@ -224,3 +225,43 @@ func (s *vgBasicSuite) TestDSAccessPrivilegeForUserVG(c *C) {

misc.LogTestEnd(c.TestName())
}

// Test steps:
// 1. Create a vm VM1 using govc
// 2. Create a vmgroup and associate VM1 to it.
// 2. Execute vmgroup ls command.
// 3. Delete the vm that was added to the vmgroup.
// 4. Again execute vmgroup ls command to verify command works fine.
func (s *vgBasicSuite) TestDeleteVMFromVmgroup(c *C) {
misc.LogTestStart(c.TestName())
vmName := "VM_" + inputparams.GetRandomNumber()
vgName := "VG_" + inputparams.GetRandomNumber()
networkAdapterType := "vmxnet3"

// Create a vm - we need this to add to vmgroup and later on delete this vm
esx.CreateVM(vmName, s.config.Datastores[0], networkAdapterType)
c.Assert(esx.IsVMExist(vmName), Equals, true, Commentf("Failed to create VM - %s .", vmName, vgName))

out, err := admincli.CreateVMgroup(s.config.EsxHost, vgName, vmName, admincliconst.VMHomeDatastore)
c.Assert(err, IsNil, Commentf(out))

// Verify if vmgroup exists
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vgName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup %s does not exists.", vgName))

// Verify vm belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, vmName, vgName)
c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", vmName, vgName))

// Destroy the vm
esx.DestroyVM(vmName)
c.Assert(esx.IsVMExist(vmName), Equals, false, Commentf("Failed to delete VM - %s .", vmName, vgName))

// Check vmgroup ls
isVmgroupAvailable = admincli.IsVmgroupPresent(s.config.EsxHost, vgName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup %s does not exists.", vgName))

// TO DO: Due to product behavior vmgroup deletion is not possible - Issue # 1484
// Please add step to delete vmgroup after issue 1484 is fixed.
misc.LogTestEnd(c.TestName())
}
31 changes: 31 additions & 0 deletions tests/utils/esx/govc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ If some test is misbehaving, then the developer can enable that log and test.
package esx

import (
"log"
"strings"

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

Expand Down Expand Up @@ -72,3 +74,32 @@ func GetDatastoreByType(typeName string) string {
cmd := esx.DatastoreInfo + esxcliJSON + " '.Datastores[].Summary | select(.Type==\"" + typeName + "\") | .Name'"
return ssh.InvokeCommandLocally(cmd)
}

// CreateVM creates a vm on the specified ds and esx
func CreateVM(vmName, datastore, networkAdapterType string) string {
log.Printf("Creating a vm [%s] \n", vmName)
cmd := esx.VMCreate + datastore + " -on=false -link=false -net.adapter=" + networkAdapterType + " " + vmName
return ssh.InvokeCommandLocally(cmd)
}

// DestroyVM deletes a vm
func DestroyVM(vmName string) string {
log.Printf("Deleting a vm - %s \n", vmName)
cmd := esx.VMDestroy + vmName
return ssh.InvokeCommandLocally(cmd)
}

// IsVMExist returns true/false based on vm existence
func IsVMExist(vmName string) bool {
log.Printf("Verifying if vm - %s exists \n", vmName)
maxAttempt := 15
waitTime := 2
for attempt := 0; attempt < maxAttempt; attempt++ {
vmList := ssh.InvokeCommandLocally(esx.ListVMs + " /ha-datacenter/vm")
if strings.Contains(vmList, vmName) {
return true
}
misc.SleepForSec(waitTime)
}
return false
}
12 changes: 6 additions & 6 deletions tests/utils/inputparams/testparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ func GetVolumeName() string {

// GetUniqueContainerName prepares unique container name with a random generated number
func GetUniqueContainerName(containerName string) string {
return containerName + "_container_" + getRandomNumber()
return containerName + "_container_" + GetRandomNumber()
}

// GetUniqueServiceName prepares unique service name with a random generated number
func GetUniqueServiceName(serviceName string) string {
return serviceName + "_service_" + getRandomNumber()
return serviceName + "_service_" + GetRandomNumber()
}

// GetUniqueVmgroupName prepares unique vmgroup name with a random generated number.
func GetUniqueVmgroupName(vmgroupName string) string {
return vmgroupName + "_vmgroup_" + getRandomNumber()
return vmgroupName + "_vmgroup_" + GetRandomNumber()
}

// GetUniqueVolumeName prepares unique volume name with a random generated number
func GetUniqueVolumeName(volName string) string {
return volName + "_volume_" + getRandomNumber()
return volName + "_volume_" + GetRandomNumber()
}

// GetVolumeNameOfSize returns a random volume name of required length
Expand Down Expand Up @@ -145,8 +145,8 @@ func GetTestConfig() *TestConfig {
return config
}

// getRandomNumber returns random number
func getRandomNumber() string {
// GetRandomNumber returns random number
func GetRandomNumber() string {
min := 99999
max := 999999
rand.Seed(time.Now().UTC().UnixNano())
Expand Down

0 comments on commit 03791aa

Please sign in to comment.